
--BEFORE CODE 21.01.2015
-- Очистка настроечных таблиц --
DELETE FROM dbo.S_ACCOUNTS_NEW_CONV WHERE BUF_NAME <> '157N_CHANGE_89N_2014'
GO


GO
--Таблица DOC_NASTR_S_ACCOUNTS
IF not exists(select * from sysobjects where id = object_id('[dbo].[DOC_NASTR_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] (
	[LINK] int NOT NULL IDENTITY(1,1) ,
	[LINK_UP] int NOT NULL ,
	[ACCOUNT] int NOT NULL ,
	[DB_KR] tinyint NOT NULL )
GO

	GRANT SELECT, UPDATE, DELETE ON dbo.[DOC_NASTR_S_ACCOUNTS] TO PUBLIC
	
GO

--Расширенные свойства--
--Индексы

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_DOC_NASTR_S_ACCOUNTS')
CREATE INDEX [IX_DOC_NASTR_S_ACCOUNTS] ON [dbo].[DOC_NASTR_S_ACCOUNTS] ([LINK_UP]) ON [INDEX]
GO
--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[PK_DOC_NASTR_S_ACCOUNTS]'))
ALTER TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] 
ADD CONSTRAINT [PK_DOC_NASTR_S_ACCOUNTS] PRIMARY KEY CLUSTERED ([LINK])
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_DOC_NASTR_S_ACCOUNTS_S_ACCOUNTS]'))
ALTER TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] 
ADD CONSTRAINT [FK_DOC_NASTR_S_ACCOUNTS_S_ACCOUNTS] FOREIGN KEY ([ACCOUNT]) REFERENCES [dbo].[S_ACCOUNTS] ([LINK])
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_DOC_NASTR_S_ACCOUNTS_DOC_NASTR_S_ACCOUNTS]'))
ALTER TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] WITH NOCHECK 
ADD CONSTRAINT [FK_DOC_NASTR_S_ACCOUNTS_DOC_NASTR_S_ACCOUNTS] FOREIGN KEY ([LINK_UP]) REFERENCES [dbo].[DOC_NASTR] ([LINK])
ALTER TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] NOCHECK CONSTRAINT [FK_DOC_NASTR_S_ACCOUNTS_DOC_NASTR_S_ACCOUNTS]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[DF_DOC_NASTR_S_ACCOUNTS_DB_KR]'))
ALTER TABLE [dbo].[DOC_NASTR_S_ACCOUNTS] 
ADD CONSTRAINT [DF_DOC_NASTR_S_ACCOUNTS_DB_KR] DEFAULT ((0)) FOR [DB_KR]
GO
--Триггеры


GO
-- Загрузка изменений ПС --
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='204' AND ANALITH_NEW = '32' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '204', '32', '204', '32', 'Участие в уставном фонде государственных (муниципальных) предприятий', 0, '157N_CHANGE_89N_2014', 1, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='205' AND ANALITH_NEW = '82' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '205', '82', '205', '82', 'Расчеты по невыясненным поступлениям', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='209' AND ANALITH_NEW = '00' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '209', '  ', '209', '00', 'Расчеты по ущербу и иным доходам', 0, '157N_CHANGE_89N_2014', 1, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='209' AND ANALITH_NEW = '83' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '209', '83', '209', '83', 'Расчеты по иным доходам', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='210' AND ANALITH_NEW = '01' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '210', '01', '210', '01', 'Расчеты по НДС по приобретенным материальным ценностям, работам, услугам', 0, '157N_CHANGE_89N_2014', 4, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='210' AND ANALITH_NEW = '11' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '210', '11', '210', '11', 'Расчеты по НДС по авансам полученным', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='210' AND ANALITH_NEW = '12' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '210', '12', '210', '12', 'Расчеты по НДС по приобретенным материальным ценностям, работам, услугам', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='27' AND ANALITH_NEW = '' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '27 ', '  ', '27', '', 'Материальные ценности, выданные в личное пользование работникам (сотрудникам)', 0, '157N_CHANGE_89N_2014', 3, 1, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='30' AND ANALITH_NEW = '' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '30 ', '  ', '30', '', 'Расчеты по исполнению денежных обязательств через третьих лиц', 0, '157N_CHANGE_89N_2014', 3, 1, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='401' AND ANALITH_NEW = '60' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '401', '60', '401', '60', 'Резервы предстоящих расходов', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='502' AND ANALITH_NEW = '07' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '502', '07', '502', '07', 'Принимаемые обязательства', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='502' AND ANALITH_NEW = '09' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '502', '09', '502', '09', 'Отложенные обязательства', 0, '157N_CHANGE_89N_2014', 3, 0, USER_SID ()
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NEW_CONV WHERE SINTH_NEW ='504' AND ANALITH_NEW = '00' AND BUF_NAME = '157N_CHANGE_89N_2014')
	INSERT INTO dbo.S_ACCOUNTS_NEW_CONV (LINK, LINK_SA, SINTH_OLD, ANALITH_OLD, SINTH_NEW, ANALITH_NEW, NAME_NEW, ORDERS, BUF_NAME, TYPE_ACCT, ZABALANCE, [SID])
	SELECT 0, 0, '504', '  ', '504', '00', 'Сметные (плановые, прогнозные) назначения', 0, '157N_CHANGE_89N_2014', 1, 0, USER_SID ()


GO



GO
-- Обновление настроечной таблицы счетов (S_ACCOUNTS_NASTR) --
DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

-- 1. Наименование --
UPDATE T2
SET NAME = T1.NAME_NEW
FROM dbo.S_ACCOUNTS_NEW_CONV T1
INNER JOIN dbo.S_ACCOUNTS_NASTR T2 ON (T2.SINTH = T1.SINTH_NEW
	AND T2.ANALITH = T1.ANALITH_NEW)
WHERE T1.BUF_NAME = @BUF_NAME
	AND T1.TYPE_ACCT = 1
--
-- 2. Добавление новых счетов --
INSERT INTO dbo.S_ACCOUNTS_NASTR (
	[NAME],
	[SINTH],
	[ANALITH],
	[BUH_TYPE],
	[DOUBLE_REC],
	[KBK_TYPE],
	[S_ACTIVE],
	[KSU],
	[KBK],
	[P_KASSA],
	[EKR0],
	[AP_EKR],
	[AP_NOMEN],
	[AP_INV],
	[AP_EMP],
	[AP_DEP],
	[AP_DOP],
	[AP_DEP_ACC],
	[AP_DOC],
	[AP_SUB],
	[P_NOCONTROL],
	[AP_TMC],
	[AP_INDATE],
	[AP_KAU],
	[JONUM],
	[P_DATE],
	[NOMEN_TYPE],
	[ZABALANCE]
	)
SELECT
	[NAME]	=	T1.NAME_NEW,
	[SINTH]	=	T1.SINTH_NEW,
	[ANALITH]	=	T1.ANALITH_NEW,
	[BUH_TYPE]	=	7,
	[DOUBLE_REC]	=	0,
	[KBK_TYPE]	=	0,
	[S_ACTIVE]	=	CASE
						WHEN T1.ZABALANCE = 1 OR T1.ZABALANCE = 0 AND LEFT (T1.SINTH_NEW, 1) = '2' THEN 1
						ELSE 0
					END,
	[KSU]	=	CASE
						WHEN T1.ZABALANCE = 1 AND T1.SINTH_NEW = '27' THEN 1
						ELSE 0
					END,
	[KBK]	=	CASE
					WHEN T1.SINTH_NEW = '210' THEN 'КРБ, КДБ'
					WHEN T1.SINTH_NEW = '205' THEN 'КДБ'
					WHEN T1.SINTH_NEW = '209' THEN 'КИФ'
					WHEN T1.SINTH_NEW = '401' THEN 'КРБ'
					WHEN T1.SINTH_NEW = '502' THEN 'КРБ, КИФ'
					ELSE ''
				END,
	[P_KASSA]	=	CASE
						WHEN T1.SINTH_NEW = '401' OR T1.SINTH_NEW = '502' THEN 1
						ELSE 0
					END,
	[EKR0]	=	CASE
					WHEN T1.SINTH_NEW = '205' THEN '180'
					ELSE ''
				END,
	[AP_EKR]	=	CASE
						WHEN T1.SINTH_NEW = '401' OR T1.SINTH_NEW = '502' OR T1.SINTH_NEW = '205' THEN 1
						ELSE 0
					END,
	[AP_NOMEN]	=	0,
	[AP_INV]	=	0,
	[AP_EMP]	=	0,
	[AP_DEP]	=	CASE
						WHEN T1.SINTH_NEW = '205' THEN 1
						ELSE 0
					END,
	[AP_DOP]	=	0,
	[AP_DEP_ACC]	=	0,
	[AP_DOC]	=	0,
	[AP_SUB]	=	0,
	[P_NOCONTROL]	=	0,
	[AP_TMC]	=	CASE
						WHEN T1.SINTH_NEW = '27' THEN 1
						ELSE 0
					END,
	[AP_INDATE]	=	0,
	[AP_KAU]	=	0,
	[JONUM]	=	CASE
					WHEN T1.ZABALANCE = 1 THEN 'ЗБ'
					WHEN T1.SINTH_NEW = '205' THEN '05'
					WHEN T1.SINTH_NEW = '401' THEN ''
					ELSE '08'
				END,
	[P_DATE]	=	0,
	[NOMEN_TYPE]	=	0,
	[ZABALANCE]	=	T1.ZABALANCE
FROM dbo.S_ACCOUNTS_NEW_CONV T1
--INNER JOIN dbo.S_ACCOUNTS_NASTR T2 ON (T2.SINTH = T1.SINTH_NEW
--	AND T2.ANALITH = T1.ANALITH_NEW)
WHERE T1.BUF_NAME = @BUF_NAME
	AND T1.TYPE_ACCT = 3
	AND NOT EXISTS (
					SELECT * FROM dbo.S_ACCOUNTS_NASTR T2 
					WHERE T2.SINTH = T1.SINTH_NEW
						AND T2.ANALITH = T1.ANALITH_NEW
					)

-- 3. Удаление --
DELETE T2
FROM dbo.S_ACCOUNTS_NEW_CONV T1
INNER JOIN dbo.S_ACCOUNTS_NASTR T2 ON (T2.SINTH = T1.SINTH_NEW
	AND T2.ANALITH = T1.ANALITH_NEW)
WHERE T1.BUF_NAME = @BUF_NAME
	AND T1.TYPE_ACCT = 4
--
GO


GO
--Добавление колонки DB_KR таблицы S_ACCOUNTS_NASTR_KOSGU
IF COLUMNPROPERTY(object_id('[dbo].[S_ACCOUNTS_NASTR_KOSGU]'), 'DB_KR', 'AllowsNull') is NULL
   ALTER TABLE [dbo].[S_ACCOUNTS_NASTR_KOSGU] ADD [DB_KR] tinyint NOT NULL CONSTRAINT [DF_S_ACCOUNTS_NASTR_KOSGU_DB_KR] DEFAULT ((0))
GO

-- Обновление настроечной таблицы счетов на СГУ (S_ACCOUNTS_NASTR_KOSGU) -- 
IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '205' AND ANALITH = '82' AND SGU = '560')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('205', '82', '560', 'Увеличение дебиторской задолженности по невыясненным поступлениям ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '205' AND ANALITH = '82' AND SGU = '660')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('205', '82', '660', 'Уменьшение дебиторской задолженности по невыясненным поступлениям ', 1)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '209' AND ANALITH = '83' AND SGU = '560')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('209', '83', '560', 'Увеличение дебиторской задолженности по иным доходам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '209' AND ANALITH = '83' AND SGU = '660')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('209', '83', '660', 'Уменьшение дебиторской задолженности по иным доходам', 1)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '210' AND ANALITH = '11' AND SGU = '560')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('210', '11', '560', 'Увеличение дебиторской задолженности по НДС по авансам полученным', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '210' AND ANALITH = '11' AND SGU = '660')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('210', '11', '660', 'Уменьшение дебиторской задолженности по НДС по авансам полученным', 1)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '210' AND ANALITH = '12' AND SGU = '560')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('210', '12', '560', 'Увеличение дебиторской задолженности по НДС по приобретенным материальным ценностям, работам, услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '210' AND ANALITH = '12' AND SGU = '660')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('210', '12', '660', 'Уменьшение дебиторской задолженности по НДС по приобретенным материальным ценностям, работам, услугам', 1)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '200')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '200', 'Резервы предстоящих расходов хозяйствующего субъекта', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '210')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '210', 'Резервы предстоящих расходов по оплате труда и начислениям на выплаты по оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '211')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '211', 'Резервы предстоящих расходов по заработной плате', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '212')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '212', 'Резервы предстоящих расходов по прочим выплатам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '213')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '213', 'Резервы предстоящих расходов на начисления на выплаты по оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '220')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '220', 'Резервы предстоящих расходов на оплату работ, услуг', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '221')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '221', 'Резервы предстоящих расходов на услуги связи', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '222')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '222', 'Резервы предстоящих расходов на транспортные услуги', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '223')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '223', 'Резервы предстоящих расходов на коммунальные услуги', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '224')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '224', 'Резервы предстоящих расходов на арендную плату за пользование имуществом', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '225')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '225', 'Резервы предстоящих расходов на работы, услуги по содержанию имущества', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '226')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '226', 'Резервы предстоящих расходов на прочие работы, услуги', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '230')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '230', 'Резервы предстоящих расходов на обслуживание государственного (муниципального)  долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '231')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '231', 'Резервы предстоящих расходов на обслуживание внутреннего долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '232')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '232', 'Резервы предстоящих расходов на обслуживание внешнего государственного долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '240')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '240', 'Резервы предстоящих расходов на безвозмездные перечисления организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '241')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '241', 'Резервы предстоящих расходов на безвозмездные перечисления государственным и муниципальным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '242')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '242', 'Резервы предстоящих расходов на безвозмездные перечисления организациям, за исключением государственных и муниципальных организаций', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '250')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '250', 'Резервы предстоящих расходов на безвозмездные перечисления бюджетам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '251')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '251', 'Резервы предстоящих расходов на перечисления другим бюджетам бюджетной системы Российской Федерации', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '252')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '252', 'Резервы предстоящих расходов на перечисления наднациональным организациям и правительствам иностранных государств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '253')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '253', 'Резервы предстоящих расходов на перечисления международным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '260')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '260', 'Резервы предстоящих расходов на социальное обеспечение', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '261')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '261', 'Резервы предстоящих расходов на пенсии, пособия и выплаты по пенсионному, социальному и медицинскому страхованию населения', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '262')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '262', 'Резервы предстоящих расходов на пособия по социальной помощи населению', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '263')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '263', 'Резервы предстоящих расходов на пенсии, пособия, выплачиваемые организациями сектора государственного управления', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '270')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '270', 'Резервы предстоящих расходов по операциям с активами', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '271')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '271', 'Резервы предстоящих расходов на амортизацию основных средств и нематериальных активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '272')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '272', 'Расходование материальных запасов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '273')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '273', 'Чрезвычайные Резервы предстоящих расходов по операциям с активами', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '401' AND ANALITH = '60' AND SGU = '290')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('401', '60', '290', 'Прочие Резервы предстоящих расходов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '200')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '200', 'Принимаемые обязательства по расходам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '210')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '210', 'Принимаемые обязательства по оплате труда и начислениям на выплаты по оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '211')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '211', 'Принимаемые обязательства по заработной плате', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '212')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '212', 'Принимаемые обязательства по заработной плате', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '213')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '213', 'Принимаемые обязательства по начислениям на выплаты по  оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '220')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '220', 'Принимаемые обязательства по оплате работ, услуг', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '221')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '221', 'Принимаемые обязательства по услугам связи', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '222')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '222', 'Принимаемые обязательства по транспортным услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '223')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '223', 'Принимаемые обязательства по коммунальным услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '224')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '224', 'Принимаемые обязательства по арендной плате за пользование имуществом', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '225')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '225', 'Принимаемые обязательства по работам, услугам по содержанию имущества', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '226')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '226', 'Принимаемые обязательства по прочим  работам, услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '230')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '230', 'Принимаемые обязательства по обслуживанию государственного (муниципального) долга ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '231')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '231', 'Принимаемые обязательства по обслуживанию внутреннего долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '232')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '232', 'Принимаемые обязательства по обслуживанию внешнего государственного долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '240')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '240', 'Принимаемые обязательства по безвозмездным перечисления организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '241')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '241', 'Принимаемые обязательства по безвозмездным перечисления государственным и муниципальным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '242')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '242', 'Принимаемые обязательства по безвозмездным перечисления организациям, за исключением государственных и муниципальных организаций', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '250')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '250', 'Принимаемые обязательства по безвозмездным перечисления бюджетам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '251')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '251', 'Принимаемые обязательства по перечислениям другим бюджетам бюджетной системы Российской Федерации', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '252')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '252', 'Принимаемые обязательства по перечислениям наднациональным организациям и правительствам иностранных государств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '253')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '253', 'Принимаемые обязательства по перечислениям международным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '260')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '260', 'Принятые бюджетные обязательства по социальному обеспечению', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '261')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '261', 'Принимаемые обязательства по пенсиям, пособиям и выплатам по пенсионному, социальному и медицинскому страхованию населения ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '262')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '262', 'Принимаемые обязательства по пособиям по социальной помощи населению', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '263')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '263', 'Принимаемые обязательства по пенсиям, пособиям, выплачиваемым организациями сектора государственного управления ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '290')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '290', 'Принимаемые обязательства по прочим расходам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '300')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '300', 'Принимаемые обязательства по приобретению нефинансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '310')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '310', 'Принимаемые обязательства по приобретению основных средств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '320')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '320', 'Принимаемые обязательства по приобретению нематериальных активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '330')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '330', 'Принимаемые обязательства по приобретению непроизведенных активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '340')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '340', 'Принимаемые обязательства по приобретению материальных запасов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '500')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '500', 'Принимаемые обязательства по приобретению финансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '510')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '510', 'Принимаемые обязательства по изменению (увеличению) остатка денежных средств учреждения', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '520')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '520', 'Принимаемые обязательства по приобретению ценных бумаг, кроме акций и иных форм участия в капитале', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '530')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '530', 'Принимаемые обязательства по приобретению акций и иных форм участия в капитале', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '540')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '540', 'Принимаемые обязательства по предоставлению бюджетных кредитов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '550')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '550', 'Принимаемые обязательства по приобретению иных финансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '800')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '800', 'Принимаемые обязательства по погашению долговых обязательств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '810')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '810', 'Принимаемые обязательства по погашению задолженности по внутреннему долгу', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '07' AND SGU = '820')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '07', '820', 'Принимаемые обязательства по погашению задолженности по внешнему государственному  долгу', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '200')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '200', 'Отложенные обязательства по расходам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '210')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '210', 'Отложенные обязательства по оплате труда и начислениям на выплаты по оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '211')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '211', 'Отложенные обязательства по заработной плате', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '212')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '212', 'Отложенные обязательства по заработной плате', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '213')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '213', 'Отложенные обязательства по начислениям на выплаты по  оплате труда', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '220')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '220', 'Отложенные обязательства по оплате работ, услуг', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '221')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '221', 'Отложенные обязательства по услугам связи', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '222')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '222', 'Отложенные обязательства по транспортным услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '223')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '223', 'Отложенные обязательства по коммунальным услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '224')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '224', 'Отложенные обязательства по арендной плате за пользование имуществом', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '225')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '225', 'Отложенные обязательства по работам, услугам по содержанию имущества', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '226')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '226', 'Отложенные обязательства по прочим  работам, услугам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '230')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '230', 'Отложенные обязательства по обслуживанию государственного (муниципального) долга ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '231')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '231', 'Отложенные обязательства по обслуживанию внутреннего долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '232')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '232', 'Отложенные обязательства по обслуживанию внешнего государственного долга', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '240')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '240', 'Отложенные обязательства по безвозмездным перечисления организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '241')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '241', 'Отложенные обязательства по безвозмездным перечисления государственным и муниципальным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '242')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '242', 'Отложенные обязательства по безвозмездным перечисления организациям, за исключением государственных и муниципальных организаций', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '250')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '250', 'Отложенные обязательства по безвозмездным перечисления бюджетам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '251')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '251', 'Отложенные обязательства по перечислениям другим бюджетам бюджетной системы Российской Федерации', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '252')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '252', 'Отложенные обязательства по перечислениям наднациональным организациям и правительствам иностранных государств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '253')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '253', 'Отложенные обязательства по перечислениям международным организациям', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '260')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '260', 'Принятые бюджетные обязательства по социальному обеспечению', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '261')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '261', 'Отложенные обязательства по пенсиям, пособиям и выплатам по пенсионному, социальному и медицинскому страхованию населения ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '262')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '262', 'Отложенные обязательства по пособиям по социальной помощи населению', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '263')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '263', 'Отложенные обязательства по пенсиям, пособиям, выплачиваемым организациями сектора государственного управления ', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '290')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '290', 'Отложенные обязательства по прочим расходам', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '300')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '300', 'Отложенные обязательства по приобретению нефинансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '310')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '310', 'Отложенные обязательства по приобретению основных средств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '320')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '320', 'Отложенные обязательства по приобретению нематериальных активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '330')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '330', 'Отложенные обязательства по приобретению непроизведенных активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '340')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '340', 'Отложенные обязательства по приобретению материальных запасов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '500')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '500', 'Отложенные обязательства по приобретению финансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '510')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '510', 'Отложенные обязательства по изменению (увеличению) остатка денежных средств учреждения', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '520')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '520', 'Отложенные обязательства по приобретению ценных бумаг, кроме акций и иных форм участия в капитале', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '530')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '530', 'Отложенные обязательства по приобретению акций и иных форм участия в капитале', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '540')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '540', 'Отложенные обязательства по предоставлению бюджетных кредитов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '550')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '550', 'Отложенные обязательства по приобретению иных финансовых активов', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '800')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '800', 'Отложенные обязательства по погашению долговых обязательств', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '810')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '810', 'Отложенные обязательства по погашению задолженности по внутреннему долгу', 0)

IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS_NASTR_KOSGU WHERE SINTH = '502' AND ANALITH = '09' AND SGU = '820')
	INSERT INTO dbo.S_ACCOUNTS_NASTR_KOSGU (SINTH, ANALITH, SGU, [NAME], DB_KR)
	VALUES ('502', '09', '820', 'Отложенные обязательства по погашению задолженности по внешнему государственному  долгу', 0)
GO






GO
--Добавление колонки SUM_REST таблицы OUT_TABLE_MZ_CHARGE
IF COLUMNPROPERTY(object_id('[dbo].[OUT_TABLE_MZ_CHARGE]'), 'SUM_REST', 'AllowsNull') is NULL
   ALTER TABLE [dbo].[OUT_TABLE_MZ_CHARGE] ADD [SUM_REST] numeric(28, 4) NOT NULL CONSTRAINT [DF_OUT_TABLE_MZ_CHARGE_SUM_REST] DEFAULT ((0))
GO


GO
--Таблица BS_WORKMODE
IF not exists(select * from sysobjects where id = object_id('[dbo].[BS_WORKMODE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[BS_WORKMODE] (
	[WORK_MODE] varchar(30) NOT NULL ,
	[WORK_STATUS] tinyint NOT NULL )
GO

	GRANT SELECT, UPDATE, DELETE ON dbo.[BS_WORKMODE] TO PUBLIC
	
GO

--Расширенные свойства--
--Индексы
--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[PK_BS_WORKMODE]'))
ALTER TABLE [dbo].[BS_WORKMODE] 
ADD CONSTRAINT [PK_BS_WORKMODE] PRIMARY KEY CLUSTERED ([WORK_MODE])
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[DF_BS_WORKMODE_WORK_STATUS]'))
ALTER TABLE [dbo].[BS_WORKMODE] 
ADD CONSTRAINT [DF_BS_WORKMODE_WORK_STATUS] DEFAULT ((0)) FOR [WORK_STATUS]
GO
--Триггеры


GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FINANS_ASSIGN_LIM_DATE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FINANS_ASSIGN_LIM_DATE', 'Формировать лимиты датой ассигнований', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_ASSIGN_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FINANS_ASSIGN_LIM_DATE', NAME = 'Формировать лимиты датой ассигнований', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_ASSIGN_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FINANS_ASSIGN_LIM_DATE'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'TITLE', 'Формировать лимиты датой ассигнований'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'CONTROLSOURCE', 'm.cAlias + ".LIM_DATE"'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'STORAGE', 'S_OPTIONS'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'TYPE_FIELD_DICT', 'bit'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'SHORT_CODE_OBJ', 'LIM_DATE'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".LIM_DATE"'
GO
EXEC X_SET_PROP 'FINANS_ASSIGN_LIM_DATE', 'CONTROL_NAME_EDIT', 'Check3'
GO
EXECUTE X_FORM_VIEW_OPTIONS 'FINANS_ASSIGN_OPTIONS'
GO

GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FINANS_LIMIT_OPTIONS_BO_EKR')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FINANS_LIMIT_OPTIONS_BO_EKR', 'ЭКР для формирования БО', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_LIMIT_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FINANS_LIMIT_OPTIONS_BO_EKR', NAME = 'ЭКР для формирования БО', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_LIMIT_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FINANS_LIMIT_OPTIONS_BO_EKR'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'TITLE', 'ЭКР для формирования БО'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'CONTROLSOURCE', 'm.cAlias + ".BO_EKR"'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'STORAGE', 'S_OPTIONS'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'TYPE_FIELD_DICT', 'VARCHAR(250)'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'SHORT_CODE_OBJ', 'BO_EKR'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".BO_EKR"'
GO
EXEC X_SET_PROP 'FINANS_LIMIT_OPTIONS_BO_EKR', 'CONTROL_NAME_EDIT', 'aTxt5'
GO
EXECUTE X_FORM_VIEW_OPTIONS 'FINANS_LIMIT_OPTIONS'
GO

GO
--Таблица OKPD
IF not exists(select * from sysobjects where id = object_id('[dbo].[OKPD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[OKPD] (
	[LINK] int NOT NULL IDENTITY(1,1) ,
	[LINK_SELF] int NULL ,
	[CODE] char(12) NOT NULL ,
	[NAME] varchar(254) NOT NULL ,
	[UM] int NULL ,
	[USED] bit NOT NULL )
GO

	GRANT SELECT, UPDATE, DELETE ON dbo.[OKPD] TO PUBLIC
	
GO

--Расширенные свойства--
--Индексы

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_OKPD')
CREATE UNIQUE INDEX [IX_OKPD] ON [dbo].[OKPD] ([CODE]) ON [INDEX]
GO
--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[PK_OKPD]'))
ALTER TABLE [dbo].[OKPD] 
ADD CONSTRAINT [PK_OKPD] PRIMARY KEY CLUSTERED ([LINK])
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_OKPD_OKPD]'))
ALTER TABLE [dbo].[OKPD] WITH NOCHECK 
ADD CONSTRAINT [FK_OKPD_OKPD] FOREIGN KEY ([LINK_SELF]) REFERENCES [dbo].[OKPD] ([LINK])
ALTER TABLE [dbo].[OKPD] NOCHECK CONSTRAINT [FK_OKPD_OKPD]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_OKPD_DICTION]'))
ALTER TABLE [dbo].[OKPD] WITH NOCHECK 
ADD CONSTRAINT [FK_OKPD_DICTION] FOREIGN KEY ([UM]) REFERENCES [dbo].[DICTION] ([LINK])
ALTER TABLE [dbo].[OKPD] NOCHECK CONSTRAINT [FK_OKPD_DICTION]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[DF_OKPD_USED]'))
ALTER TABLE [dbo].[OKPD] 
ADD CONSTRAINT [DF_OKPD_USED] DEFAULT (1) FOR [USED]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[DF_OKPD_CODE]'))
ALTER TABLE [dbo].[OKPD] 
ADD CONSTRAINT [DF_OKPD_CODE] DEFAULT ('') FOR [CODE]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[DF_OKPD_NAME]'))
ALTER TABLE [dbo].[OKPD] 
ADD CONSTRAINT [DF_OKPD_NAME] DEFAULT ('') FOR [NAME]
GO



---------------------------------------------------------------------------------
-- добавление поля  [OKPD] в таблицу [NOMENCLATURE] 
IF COLUMNPROPERTY(object_id('[dbo].[NOMENCLATURE]'), 'LINK_OKPD', 'AllowsNull') IS null
	ALTER TABLE [dbo].[NOMENCLATURE] ADD [LINK_OKPD] int NULL
GO

-- добавление поля  [COEFF_OKPD] в таблицу [NOMENCLATURE] 
IF COLUMNPROPERTY(object_id('[dbo].[NOMENCLATURE]'), 'COEFF_OKPD', 'AllowsNull') IS null
	ALTER TABLE [dbo].[NOMENCLATURE] ADD [COEFF_OKPD] numeric(18, 9) NOT NULL DEFAULT (1)
GO


--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_NOMENCLATURE_OKPD]'))
ALTER TABLE [dbo].[NOMENCLATURE] WITH NOCHECK 
ADD CONSTRAINT [FK_NOMENCLATURE_OKPD] FOREIGN KEY ([LINK_OKPD]) REFERENCES [dbo].[OKPD] ([LINK])
ALTER TABLE [dbo].[NOMENCLATURE] NOCHECK CONSTRAINT [FK_NOMENCLATURE_OKPD]
GO

--Триггеры

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[NOMENCLATURE_XINSERT]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[NOMENCLATURE_XINSERT]

GO
CREATE TRIGGER dbo.NOMENCLATURE_XINSERT ON NOMENCLATURE
FOR INSERT, UPDATE
AS
Declare   @varKSCountRel 	int
  IF @@ROWCOUNT>0 AND TRIGGER_NESTLEVEL()<2
        BEGIN
	Select @varKSCountRel=Count(*) 
		FROM INSERTED INS
		WHERE INS.[LINK_OKDP] is not NULL AND INS.[LINK_OKDP] not in (SELECT [LINK] FROM dbo.OKDP WITH (NOLOCK))
				or (INS.[LINK_OKPD] is not NULL AND INS.[LINK_OKPD] not in (SELECT [LINK] FROM dbo.OKPD WITH (NOLOCK)))
	    IF @varKSCountRel>0
		BEGIN
			raiserror('Ошибки при вставке или обновлении данных в таблице NOMENCLATURE',11,1)
			ROLLBACK
			RETURN
		END
        END

GO

----------------------------------------------------------

-- добавление поля  [OKPD] в таблицу [GZ_DOC_TABLE] 
IF COLUMNPROPERTY(object_id('[dbo].[GZ_DOC_TABLE]'), 'OKPD', 'AllowsNull') IS null
	ALTER TABLE [dbo].[GZ_DOC_TABLE] ADD [OKPD] int NULL
GO


--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_GZ_NOT_CONTRACT_OKPD]'))
ALTER TABLE [dbo].[GZ_DOC_TABLE] WITH NOCHECK 
ADD CONSTRAINT  [FK_GZ_NOT_CONTRACT_OKPD] FOREIGN KEY ([OKPD]) REFERENCES [dbo].[OKPD] ([LINK])
ALTER TABLE [dbo].[GZ_DOC_TABLE] NOCHECK CONSTRAINT [FK_GZ_NOT_CONTRACT_OKPD]
GO


--Триггеры

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[GZ_DOC_TABLE_XINSERT]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[GZ_DOC_TABLE_XINSERT]

GO
CREATE TRIGGER dbo.GZ_DOC_TABLE_XINSERT ON GZ_DOC_TABLE
FOR INSERT, UPDATE
AS
Declare   @varKSCountRel 	int
  IF @@ROWCOUNT>0 AND TRIGGER_NESTLEVEL()<2
        BEGIN
	Select @varKSCountRel=Count(*) 
		FROM INSERTED INS
		WHERE (INS.[DOP_CL] is not NULL AND INS.[DOP_CL] not in (SELECT [LINK] FROM dbo.DOP_CLASSIF WITH (NOLOCK)))
		   OR	( INS.[OKDP] is not NULL AND INS.[OKDP] not in (SELECT [LINK] FROM dbo.OKDP WITH (NOLOCK)))
		   OR 	( INS.[OKPD] is not NULL AND INS.[OKPD] not in (SELECT [LINK] FROM dbo.OKPD WITH (NOLOCK)))
	    IF @varKSCountRel>0
		BEGIN
			raiserror('Ошибки при вставке или обновлении данных в таблице GZ_DOC_TABLE',11,1)
			ROLLBACK
			RETURN
		END
        END

GO

-----------------------------------------------------------------

-- добавление поля  [OKPD] в таблицу [FINANSE_CONTRACT] 
IF COLUMNPROPERTY(object_id('[dbo].[FINANSE_CONTRACT]'), 'OKPD', 'AllowsNull') IS null
	ALTER TABLE [dbo].[FINANSE_CONTRACT] ADD [OKPD] int NULL
GO

--Констрэйнты
IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_FINANSE_CONTRACT_OKPD]'))
ALTER TABLE [dbo].[FINANSE_CONTRACT] WITH NOCHECK 
ADD CONSTRAINT [FK_FINANSE_CONTRACT_OKPD] FOREIGN KEY ([OKPD]) REFERENCES [dbo].[OKPD] ([LINK])
ALTER TABLE [dbo].[FINANSE_CONTRACT] NOCHECK CONSTRAINT [FK_FINANSE_CONTRACT_OKPD]
GO



--Триггеры

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[FINANSE_CONTRACT_XINSERT]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[FINANSE_CONTRACT_XINSERT]

GO
CREATE TRIGGER dbo.FINANSE_CONTRACT_XINSERT ON FINANSE_CONTRACT
FOR INSERT, UPDATE
AS
Declare   @varKSCountRel 	int
  IF @@ROWCOUNT>0 AND TRIGGER_NESTLEVEL()<2
        BEGIN
	Select @varKSCountRel=Count(*) 
		FROM INSERTED INS
		WHERE (INS.[OKDP] is not NULL AND INS.[OKDP] not in (SELECT [LINK] FROM dbo.OKDP WITH (NOLOCK)))
			  or (INS.[OKPD] is not NULL AND INS.[OKPD] not in (SELECT [LINK] FROM dbo.OKPD WITH (NOLOCK)))
	    IF @varKSCountRel>0
		BEGIN
			raiserror('Ошибки при вставке или обновлении данных в таблице FINANSE_CONTRACT',11,1)
			ROLLBACK
			RETURN
		END
        END

GO



--Триггеры ТАБЛИЦЫ OKPD

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[B_DELETE_TRIGGER]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[B_DELETE_TRIGGER]

GO
CREATE TRIGGER [dbo].[B_DELETE_TRIGGER] ON [dbo].[OKPD] 
FOR DELETE 
AS
IF @@ROWCOUNT>0 --AND TRIGGER_NESTLEVEL()<2
	update O 
	set O.LINK_SELF = DEL.LINK_SELF
	from dbo.OKPD O
	inner join  DELETED DEL on DEL.LINK = O.LINK_SELF

GO


IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[OKPD_XDELETE]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[OKPD_XDELETE]

GO
CREATE TRIGGER dbo.OKPD_XDELETE ON OKPD
FOR DELETE 
AS
  IF @@ROWCOUNT>0
	BEGIN
		UPDATE dbo.FINANSE_CONTRACT SET [OKPD]=null WHERE [OKPD] IN (SELECT [LINK] FROM DELETED) 
		UPDATE dbo.GZ_DOC_TABLE SET [OKPD]=null WHERE [OKPD] IN (SELECT [LINK] FROM DELETED) 
		UPDATE dbo.NOMENCLATURE SET [LINK_OKPD]=null WHERE [LINK_OKPD] IN (SELECT [LINK] FROM DELETED) 
		DELETE FROM dbo.OKPD WHERE [LINK_SELF] IN (SELECT [LINK] FROM DELETED)
	END

GO


IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[OKPD_XINSERT]') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
DROP TRIGGER dbo.[OKPD_XINSERT]

GO
CREATE TRIGGER dbo.OKPD_XINSERT ON OKPD
FOR INSERT, UPDATE
AS
Declare   @varKSCountRel 	int
  IF @@ROWCOUNT>0 AND TRIGGER_NESTLEVEL()<2
        BEGIN
	Select @varKSCountRel=Count(*) 
		FROM INSERTED INS
		WHERE INS.[LINK_SELF] is not NULL AND INS.[LINK_SELF] not in (SELECT [LINK] FROM dbo.OKPD WITH (NOLOCK))
		   OR	 INS.[UM] is not NULL AND INS.[UM] not in (SELECT [LINK] FROM dbo.DICTION WITH (NOLOCK))
	    IF @varKSCountRel>0
		BEGIN
			raiserror('Ошибки при вставке или обновлении данных в таблице OKPD',11,1)
			ROLLBACK
			RETURN
		END
        END

GO


---------------------------------------------------------------------------------
-- добавление поля  [OKPD] в таблицу [GZ_PLAN_TABLE] 
IF COLUMNPROPERTY(object_id('[dbo].[GZ_PLAN_TABLE]'), 'OKPD', 'AllowsNull') IS null
	ALTER TABLE [dbo].[GZ_PLAN_TABLE] ADD [OKPD] INT NULL 
GO

--Констрэйнты
IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_GZ_PLAN_TABLE_OKPD]'))
ALTER TABLE [dbo].[GZ_PLAN_TABLE] 
ADD CONSTRAINT [FK_GZ_PLAN_TABLE_OKPD] FOREIGN KEY ([OKPD]) REFERENCES [dbo].[OKPD] ([LINK])

GO

----- изменение поля OKDP в таблице [GZ_PLAN_TABLE]
IF COLUMNPROPERTY(object_id('[dbo].[GZ_PLAN_TABLE]'), 'OKDP', 'AllowsNull') IS not null
	ALTER TABLE [dbo].[GZ_PLAN_TABLE] ALTER COLUMN [OKDP] INT NULL 
GO



GO
--- ОТЧЕТ: ГЛАВНАЯ КНИГА (LEDGER) --- 
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'
GO
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_SQL'), 'Главная книга', NULL, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'JOURNAL_OPERATION_GROUP'), 'LEDGER', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_FILTER'), 'Стандартный фильтр для запроса', 0, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER'), 'LEDGER_FILTER1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_NASTRS'), 'Группа настроек', 6, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER'), 'LEDGER_GR_TURNS', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1_ACCT')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_ACCT'), 'Отбор субсчетов', 1, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'), 'LEDGER_FILTER1_ACCT', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1_KBK')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KBK'), 'Отбор КБК', 2, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'), 'LEDGER_FILTER1_KBK', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1_KOSGU')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KOSGU'), 'Отбор КОСГУ', 3, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'), 'LEDGER_FILTER1_KOSGU', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1_FIN_SOURCE')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_DICTION_SFIN'), 'Отбор видов финансового обеспечения', 4, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'), 'LEDGER_FILTER1_FIN_SOURCE', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1_KAU')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KAU'), 'Отбор КАУ', 5, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_FILTER1'), 'LEDGER_FILTER1_KAU', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_ACCT_GR')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Итоги по синтетической части счета', 11, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_ACCT_GR', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_JO_IN_STR')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Не разделять обороты по журналам операций', 10, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_JO_IN_STR', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_NAS1_KBK')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Код счета с КБК', 12, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_NAS1_KBK', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_NAS1_SGU')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Код счета с КОСГУ', 13, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_NAS1_SGU', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_NAS1_ZB')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Сводный отчет (ЦБ)', 14, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_NAS1_ZB', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS_ZABALANS')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_OPTIONGROUP'), 'Главная книга по', 9, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_GR_TURNS_ZABALANS', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_OPTION_DATE_BE')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PE'), 'Конец расчетного периода', 8, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_OPTION_DATE_BE', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_OPTION_DATE_BP')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PB'), 'Начало расчетного периода', 7, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_OPTION_DATE_BP', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_TOTAL_BY_KOSGU')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Подитоги по группам КОСГУ', 16, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_TOTAL_BY_KOSGU', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_TOTAL_OPTIONS')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Разделить подитоги по забалансовым счетам', 15, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'LEDGER_GR_TURNS'), 'LEDGER_TOTAL_OPTIONS', NULL, NULL, 1
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'INIT_OBJECT_METHOD', 'm_print_query(nLink_Var)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'CHECK_VALUE_IN_TABLE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'AFTER_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'BEFORE_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_CENTER_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_FOOTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_LEFT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'NASTR_XL_RIGHT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_ADDFROM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_ADDINTO', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_ADDSELECT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_ADDWHERE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_AFTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_BEFORE', '	EXEC	dbo.BK_REPORT_BOOK_MAIN
		@dDateB1,
		@dDateE1,
		@nCheck1	/* Не разделять обороты по журналам операций */,
		@nOption2	/* Главная книга по */,
		@nCheck2	/* Итоги по синтетической части счета */,
		@cVal1, @nOtborLink1	/* Отбор субсчетов */,
		@nCheck3	/* Код счета с КБК */,
		@nCheck4	/* Код счета с КОСГУ */,
		@nCheck5	/* Сводный отчет (ЦБ) */,
		@nCheck7	/* Подитоги по группам КОСГУ */,
		@cVal2, @nOtborLink2	/* Отбор КБК */,
		@cVal3, @nOtborLink3	/* Отбор КОСГУ */,
		@cVal4, @nOtborLink4	/* Отбор видов финансового обеспечения */,
		@cVal5,	@nOtborLink5	/* Отбор КАУ */
		


	
', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_DISTINCT', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_FOOTER', '="Исполнитель                               " & User_FIO
                                 подпись', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_HEADER', '=User_Name', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_PROCEDURE', '#LEDGER', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_REPMAKER', 'KirRepMaker.xls', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_REPORT', 'IIF(.T.,"BOOK_MAIN.XLT","")', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_REPORT_PATH', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_SQL', 'CREATE PROCEDURE #LEDGER
	@dDateB1 datetime	/* Начало расчетного периода */,
	@dDateE1 datetime	/* Конец расчетного периода */,
	@nOption2 int	/* Главная книга по */,
	@nCheck1 int	/* Не разделять обороты по журналам операций */,
	@nCheck2 int	/* Итоги по синтетической части счета */,
	@nCheck3 int	/* Код счета с КБК */,
	@nCheck4 int	/* Код счета с КОСГУ */,
	@nCheck5 int	/* Сводный отчет (ЦБ) */,
	@nCheck6 int	/* Разделить подитоги по забалансовым счетам */,
	@nCheck7 int	/* Подитоги по группам КОСГУ */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор субсчетов */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_ACCT''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор КБК */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KBK''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal3 char(1), @nOtborLink3 int	/* Отбор КОСГУ */
	SELECT @nOtborLink3 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KOSGU''))
	SELECT @cVal3 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink3 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal4 char(1), @nOtborLink4 int	/* Отбор видов финансового обеспечения */
	SELECT @nOtborLink4 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_DICTION_SFIN''))
	SELECT @cVal4 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink4 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal5 char(1), @nOtborLink5 int	/* Отбор КАУ */
	SELECT @nOtborLink5 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KAU''))
	SELECT @cVal5 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink5 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

	EXEC	dbo.BK_REPORT_BOOK_MAIN
		@dDateB1,
		@dDateE1,
		@nCheck1	/* Не разделять обороты по журналам операций */,
		@nOption2	/* Главная книга по */,
		@nCheck2	/* Итоги по синтетической части счета */,
		@cVal1, @nOtborLink1	/* Отбор субсчетов */,
		@nCheck3	/* Код счета с КБК */,
		@nCheck4	/* Код счета с КОСГУ */,
		@nCheck5	/* Сводный отчет (ЦБ) */,
		@nCheck7	/* Подитоги по группам КОСГУ */,
		@cVal2, @nOtborLink2	/* Отбор КБК */,
		@cVal3, @nOtborLink3	/* Отбор КОСГУ */,
		@cVal4, @nOtborLink4	/* Отбор видов финансового обеспечения */,
		@cVal5,	@nOtborLink5	/* Отбор КАУ */
		


	


END', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_SYSTEM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_TOP', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_TOTAL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_TOTALCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_TOTALROW', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_AP_LIST', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'EOD_PROTOCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'AFTER_REPORT_PROG', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_ADD_MODULE', 'KirRepCommon.bas', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'QUERY_DATE_TYPE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'SQUERY_NO_SHOW', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER', 'REPORT_EXTERNAL_GENERATOR', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1', 'QUERY_NASTR_NOTE', 'Стандартный фильтр для отчета', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1', 'QUERY_VARIANT_ID', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICT_SUBACCOUNTS', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_OTBOR_FIELD', '(GP2.DEBIT=RECORD) OR (GP2.CREDIT=RECORD)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_ACCT', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_OTBOR_DICTIONARY_CODE', 'BI_DICTION_KBK', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KBK', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICTIONARY_KOSGU', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KOSGU', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICTIONARY_FIN_SOURCE_RPT', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_FIN_SOURCE', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICTIONARY_ANALYTICAL_CODES', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_FILTER1_KAU', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_CAPTION', 'Итоги по синтетической части счета', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_NUMPARAM', '2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_SQLPARAM', '@nCheck2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ACCT_GR', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'SQUERY_NASTR_NON_VISIBLE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_CAPTION', 'Не разделять обороты по журналам операций', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_SQLPARAM', '@nCheck1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_JO_IN_STR', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_CAPTION', 'Код счета с КБК', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_NUMPARAM', '3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_SQLPARAM', '@nCheck3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_VALUE', 'Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_KBK', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_CAPTION', 'Код счета с КОСГУ', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_NUMPARAM', '4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_SQLPARAM', '@nCheck4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_VALUE', 'Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_SGU', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_CAPTION', 'Сводный отчет (ЦБ)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_NUMPARAM', '5', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_SQLPARAM', '@nCheck5', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_NAS1_ZB', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_CAPTION', 'Главная книга по', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_CONTROL', 'OPTIONGROUP', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_NUMPARAM', '2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_SOURCE', 'По всем счетам, По балансовым счетам, По забалансовым счетам', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_SQLPARAM', '@nOption2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_VALUE', 'По балансовым счетам', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_GR_TURNS_ZABALANS', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_CAPTION', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_SQLPARAM', '@dDateE1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_VALUE', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BE', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_CAPTION', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_SQLPARAM', '@dDateB1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_VALUE', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_OPTION_DATE_BP', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_CAPTION', 'Подитоги по группам КОСГУ', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_NUMPARAM', '7', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_SQLPARAM', '@nCheck7', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_VALUE', 'Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_BY_KOSGU', 'SQUERY_NASTR_OPTIONAL', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_CAPTION', 'Разделить подитоги по забалансовым счетам', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_NUMPARAM', '6', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_SQLPARAM', '@nCheck6', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'LEDGER_TOTAL_OPTIONS', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO


GO

IF  EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS')
DROP INDEX [IX_SDOC_ADIS] ON [dbo].[SDOC_ADIS]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS')
CREATE CLUSTERED INDEX [IX_SDOC_ADIS] ON [dbo].[SDOC_ADIS] ([LINK_UP], [LINK_EMPL], [REF_DOC], [LINK_PAY])
GO

IF  EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE1')
DROP INDEX [IX_SDOC_ADIS_TABLE1] ON [dbo].[SDOC_ADIS_TABLE1]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE1')
CREATE CLUSTERED INDEX [IX_SDOC_ADIS_TABLE1] ON [dbo].[SDOC_ADIS_TABLE1] ([LINK_UP], [ORDERS]) ON [INDEX]
GO

IF  EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE2')
DROP INDEX [IX_SDOC_ADIS_TABLE2] ON [dbo].[SDOC_ADIS_TABLE2]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE2')
CREATE CLUSTERED INDEX [IX_SDOC_ADIS_TABLE2] ON [dbo].[SDOC_ADIS_TABLE2] ([LINK_UP], [ORDERS], [PERIOD]) ON [INDEX]
GO

IF  EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE3')
DROP INDEX [IX_SDOC_ADIS_TABLE3] ON [dbo].[SDOC_ADIS_TABLE3]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_SDOC_ADIS_TABLE3')
CREATE CLUSTERED INDEX [IX_SDOC_ADIS_TABLE3] ON [dbo].[SDOC_ADIS_TABLE3] ([LINK_UP], [LINK_PAY], [ORDERS]) ON [INDEX]
GO


GO
-- Списание мягкого и хозяйственного инвентаря --
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOCUMENTS_MP_CHARGE', 'Списание мягкого и хозяйственного инвентаря', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DOC_MAT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOCUMENTS_MP_CHARGE', NAME = 'Списание мягкого и хозяйственного инвентаря', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DOC_MAT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BA_DOCUMENTS_MP_CHARGE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_DEP_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_DEP_LINK', 'Ссылка на организацию', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_DEP_LINK', NAME = 'Ссылка на организацию', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_DEP_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_DEP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_DEP_CODE', 'Код организации', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_DEP_CODE', NAME = 'Код организации', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_DEP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_SUBDIV_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'Ссылка на структурное подразделение', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_SUBDIV_LINK', NAME = 'Ссылка на структурное подразделение', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_SUBDIV_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_SUBDIV_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'Код структурного подразделения', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_SUBDIV_CODE', NAME = 'Код структурного подразделения', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_SUBDIV_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_GE_SUBDIV_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_GE_SUBDIV_NAME', 'Наименование структурного подразделения', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_GE_SUBDIV_NAME', NAME = 'Наименование структурного подразделения', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_GE_SUBDIV_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL_LINK', 'МОЛ', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL_LINK', NAME = 'МОЛ', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL_CODE', 'Код МОЛ', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL_CODE', NAME = 'Код МОЛ', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL_NAME', 'Наименование МОЛ', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL_NAME', NAME = 'Наименование МОЛ', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_DEP_NAME', 'Наименование организации', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_DEP_NAME', NAME = 'Наименование организации', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL0_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL0_LINK', 'Председатель комиссии', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL0_LINK', NAME = 'Председатель комиссии', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL0_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL0_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL0_NAME', 'Наименование Председателя комиссии', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL0_NAME', NAME = 'Наименование Председателя комиссии', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL0_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL0_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL0_CODE', 'Код Председателя комиссии', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL0_CODE', NAME = 'Код Председателя комиссии', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL0_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL1_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL1_LINK', 'Член комиссии 1', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL1_LINK', NAME = 'Член комиссии 1', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL1_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL1_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL1_CODE', 'Код Члена комиссии 1', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL1_CODE', NAME = 'Код Члена комиссии 1', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL1_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL1_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL1_NAME', 'Наименование Члена комиссии 1', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL1_NAME', NAME = 'Наименование Члена комиссии 1', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL1_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL2_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL2_CODE', 'Код Члена комиссии 2', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL2_CODE', NAME = 'Код Члена комиссии 2', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL2_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='MP_CHARGE_MOL2_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'MP_CHARGE_MOL2_LINK', 'Член комиссии 2', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'MP_CHARGE_MOL2_LINK', NAME = 'Член комиссии 2', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='MP_CHARGE_MOL2_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL2_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL2_NAME', 'Наименование Члена комиссии 2', 18, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL2_NAME', NAME = 'Наименование Члена комиссии 2', ORDERS = '18', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL2_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL3_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL3_LINK', 'Член комиссии 3', 19, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL3_LINK', NAME = 'Член комиссии 3', ORDERS = '19', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL3_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL3_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL3_CODE', 'Код Члена комиссии 3', 20, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL3_CODE', NAME = 'Код Члена комиссии 3', ORDERS = '20', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL3_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_MOL3_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_MOL3_NAME', 'Наименование Члена комиссии 3', 21, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_MOL3_NAME', NAME = 'Наименование Члена комиссии 3', ORDERS = '21', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_MOL3_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_DOCNUM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_DOCNUM', '№ документа о комиссии списании', 22, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_DOCNUM', NAME = '№ документа о комиссии списании', ORDERS = '22', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_DOCNUM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_DOCDATE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_DOCDATE', 'Дата документа о комиссии списании', 23, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_DOCDATE', NAME = 'Дата документа о комиссии списании', ORDERS = '23', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_DOCDATE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_NOTICE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_NOTICE', 'Примечание', 24, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_NOTICE', NAME = 'Примечание', ORDERS = '24', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_NOTICE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_TABLE', 'Таблица инвентаря', 25, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_TABLE', NAME = 'Таблица инвентаря', ORDERS = '25', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BA_DOC_MP_CHARGE_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_DOC_MP_CHARGE_OPTIONS', 'Настройки', 26, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_DOC_MP_CHARGE_OPTIONS', NAME = 'Настройки', ORDERS = '26', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOCUMENTS_MP_CHARGE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_DOC_MP_CHARGE_OPTIONS'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_OPTIONS_TYP_LINK1')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', 'Ссылка на операцию', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', NAME = 'Ссылка на операцию', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_OPTIONS_TYP_LINK1'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_OPTIONS_TYP_NAME1')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'Наим тип. опер.', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', NAME = 'Наим тип. опер.', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_OPTIONS_TYP_NAME1'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_OPTIONS_TYP_LINK2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', 'Ссылка на операцию', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', NAME = 'Ссылка на операцию', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_OPTIONS_TYP_LINK2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_OPTIONS_TYP_NAME2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'Наим тип. опер.', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', NAME = 'Наим тип. опер.', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_OPTIONS'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_OPTIONS_TYP_NAME2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_MAKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_MAKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_MAKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_MAKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_TYPE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_TYPE', 'Тип инвентаря', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_TYPE', NAME = 'Тип инвентаря', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_TYPE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_LINK', 'Ссылка на инвентарь', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_LINK', NAME = 'Ссылка на инвентарь', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_CODE', 'Код', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_CODE', NAME = 'Код', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_NAME', 'Наименование', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_NAME', NAME = 'Наименование', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_UM_NAME', 'Наименование EИ', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_UM_NAME', NAME = 'Наименование EИ', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_ACCT_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_ACCT_CODE', 'Субсчет', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_ACCT_CODE', NAME = 'Субсчет', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_ACCT_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_QTY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_QTY', 'Количество', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_QTY', NAME = 'Количество', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_QTY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_REST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_REST', 'Количество (имеется)', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_REST', NAME = 'Количество (имеется)', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_REST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_PRICE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_PRICE', 'Средняя цена', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_PRICE', NAME = 'Средняя цена', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_PRICE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BA_MP_CHARGE_TABLE_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BA_MP_CHARGE_TABLE_SUMMA', 'Сумма', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BA_MP_CHARGE_TABLE_SUMMA', NAME = 'Сумма', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BA_DOC_MP_CHARGE_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BA_MP_CHARGE_TABLE_SUMMA'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'TITLE', 'Акт списания мягкого и хозяйственного инвентаря'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'REMOVE_OBJECT_METHOD', 'I_DELETE_RECORDS(m.oForm.Alias, ''BA_DOCUMENTS_MP_CHARGE'', ''BV_DELETE_DOCUMENTS'', 4, .F., .F.)'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'SAVE_OBJECT_METHOD', 'BK_SAVE_DOC_WITH_COMISSION (''X_SAVE_BA_DOCUMENTS_MP_CHARGE'', m.cAlias,"NUMBER, SQLNULL(DATE), SQLNULL(DATE_PROV), SUMMA, COMMENT, SQLNULL (DEP_LINK), SQLNULL (ACC_LINK), GET_STORE, SQLNULL(LINK_SUB), SQLNULL(LINK_MOL), NOTICE", "SQLNULL(BC_LINK), SQLNULL(LINK_PRED), SQLNULL(DOC_DATE), SQLNULL(DOC_NUM)", "BA_DOCUMENTS_MP_CHARGE")'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'PRINT_OBJECT_METHOD', 'BK_Print_F0504143()'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'EDIT_OBJECT_METHOD', 'bdoc_brow(''DOCUMENT_CHARGE_MP_NEW'')'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_LIST_ZB(''BA_DOCUMENTS_MP_CHARGE'',,.T.)'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DOCUMENT_LIST(''BA_DOCUMENTS_MP_CHARGE'',,.T.)'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'SNAME', 'Акт списания инвентаря'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'QUERY_REPMAKER', 'KirRepMakerMultiSheet.xls'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'QUERY_REPORT', 'F-0504143.XLT'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'OPTIONS_OBJECT_CODE', 'BA_DOC_MP_CHARGE_OPTIONS'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'HELP_TOPIC', '29'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'QUERY_ADD_MODULE', 'F0504143.bas'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'OPERATION_MASK', '24'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'CREATE_PROV_SQL', 'BA_SAVE_G_PROV1_CHARGE_MP'
GO
EXEC X_SET_PROP 'BA_DOCUMENTS_MP_CHARGE', 'REPORT_EXTERNAL_GENERATOR', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'REFERENCE_TO_DICT', 'DICTIONARY_DEPARTMENT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'SHORT_CODE_OBJ', 'DEP_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("DICTIONARY_DEPARTMENT", oForm.ALIAS, "LINK,CODE,NAME", "DEP_LINK, DEP_CODE, DEP_NAME", "", "", "", .T., 1, oForm, oObj,"",.T.,"DEPARTMENT_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'CONTROLSOURCE', 'm.cAlias+".DEP_CODE"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_DEP_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'SHORT_CODE_OBJ', 'DEP_CODE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DEP_CODE"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'TITLE', 'Структурное подразделение'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'STORAGE', 'SUBDIV'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'REFERENCE_TO_DICT', 'DICTIONARY_SUBDIVISION'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'SHORT_CODE_OBJ', 'LINK_SUB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'TITLE', 'Структурное подразделение'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("DICTIONARY_SUBDIVISION", oForm.ALIAS, "subdiv_link,CODE,NAME", "LINK_SUB,CODE_SUB,NAME_SUB", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'CONTROLSOURCE', 'm.cAlias + ".CODE_SUB"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'STORAGE', 'SUBDIV'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_SUBDIV_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(5)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'SHORT_CODE_OBJ', 'CODE_SUB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CODE_SUB"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'CONTROL_NAME_EDIT', 'selSub'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_SUBDIV_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'TITLE', 'Структурное подразделение'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'CONTROLSOURCE', 'm.cAlias + ".NAME_SUB"'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'STORAGE', 'SUBDIV'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_SUBDIV_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(50)'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'SHORT_CODE_OBJ', 'NAME_SUB'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NAME_SUB"'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'CONTROL_NAME_EDIT', 'txtSub'
GO
EXEC X_SET_PROP 'BA_DOC_GE_SUBDIV_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'TITLE', 'МОЛ'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'REFERENCE_TO_DICT', 'KU_EMPL_PLACING'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'SHORT_CODE_OBJ', 'LINK_MOL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'TITLE', 'МОЛ'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("KU_EMPL_PLACING", oForm.ALIAS,"LINK, TAB, NAME_EMPL", "LINK_MOL,CODE_MOL,NAME_MOL", "", "", "", .T., 1, oForm, oObj,"",.T.,"EMPL_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'CONTROLSOURCE', 'm.cAlias + ".CODE_MOL"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'SHORT_CODE_OBJ', 'CODE_MOL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CODE_MOL"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'CONTROL_NAME_EDIT', 'selMol'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_CODE', 'REFERENCE_TO_FIELD', 'TAB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'TITLE', 'МОЛ'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'CONTROLSOURCE', 'm.cAlias + ".NAME_MOL"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(30)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'SHORT_CODE_OBJ', 'NAME_MOL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NAME_MOL"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'CONTROL_NAME_EDIT', 'txtMol'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL_NAME', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'CONTROLSOURCE', 'm.cAlias+".DEP_NAME"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'CONTROL_TYPE', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_DEP_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'TYPE_FIELD_DICT', 'varchar(50)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DEP_NAME"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DEP_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'REFERENCE_TO_DICT', 'KU_EMPL_PLACING'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'SHORT_CODE_OBJ', 'LINK_MOL0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'TITLE', 'Председатель комиссии'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'CONTROLSOURCE', 'm.cAlias + ''.NAME_MOL0'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL0_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(30)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'SHORT_CODE_OBJ', 'NAME_MOL0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ''.NAME_MOL0'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'CONTROL_NAME_EDIT', 'Parent.Page3.ATxtN6'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_NAME', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'TITLE', 'Председатель комиссии'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("KU_EMPL_PLACING", oForm.ALIAS,"LINK, TAB, NAME_EMPL", "LINK_MOL0,CODE_MOL0,NAME_MOL0", "", "", "", .T., 1, oForm, oObj,"",.T.,"EMPL_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_MOL0'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL0_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'SHORT_CODE_OBJ', 'CODE_MOL0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.CODE_MOL0'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'CONTROL_NAME_EDIT', 'Parent.Page3.ASel_Spr6'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL0_CODE', 'REFERENCE_TO_FIELD', 'TAB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'REFERENCE_TO_DICT', 'KU_EMPL_PLACING'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'SHORT_CODE_OBJ', 'LINK_MOL1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'TITLE', 'Член комиссии 1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("KU_EMPL_PLACING", oForm.ALIAS,"LINK, TAB, NAME_EMPL", "LINK_MOL1,CODE_MOL1,NAME_MOL1", "", "", "", .T., 1, oForm, oObj,"",.T.,"EMPL_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_MOL1'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL1_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'SHORT_CODE_OBJ', 'CODE_MOL1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.CODE_MOL1'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'CONTROL_NAME_EDIT', 'Parent.Page3.ASel_Spr7'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_CODE', 'REFERENCE_TO_FIELD', 'TAB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'TITLE', 'Член комиссии 1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'CONTROLSOURCE', 'm.cAlias + ''.NAME_MOL1'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL1_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(30)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'SHORT_CODE_OBJ', 'NAME_MOL1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ''.NAME_MOL1'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'CONTROL_NAME_EDIT', 'Parent.Page3.ATxtN7'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL1_NAME', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'TITLE', 'Член комиссии 2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("KU_EMPL_PLACING", oForm.ALIAS,"LINK, TAB, NAME_EMPL", "LINK_MOL2,CODE_MOL2,NAME_MOL2", "", "", "", .T., 1, oForm, oObj,"",.T.,"EMPL_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_MOL2'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL2_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'SHORT_CODE_OBJ', 'CODE_MOL2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.CODE_MOL2'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'CONTROL_NAME_EDIT', 'Parent.Page3.ASel_Spr8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_CODE', 'REFERENCE_TO_FIELD', 'TAB'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'REFERENCE_TO_DICT', 'KU_EMPL_PLACING'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'SHORT_CODE_OBJ', 'LINK_MOL2'
GO
EXEC X_SET_PROP 'MP_CHARGE_MOL2_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'TITLE', 'Член комиссии 2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'CONTROLSOURCE', 'm.cAlias + ''.NAME_MOL2'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL2_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(30)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'SHORT_CODE_OBJ', 'NAME_MOL2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ''.NAME_MOL2'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'CONTROL_NAME_EDIT', 'Parent.Page3.ATxtN8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL2_NAME', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'REFERENCE_TO_DICT', 'KU_EMPL_PLACING'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'SHORT_CODE_OBJ', 'LINK_MOL3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'TITLE', 'Член комиссии 3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("KU_EMPL_PLACING", oForm.ALIAS,"LINK, TAB, NAME_EMPL", "LINK_MOL3,CODE_MOL3,NAME_MOL3", "", "", "", .T., 1, oForm, oObj,"",.T.,"EMPL_GROUPS")'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_MOL3'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL3_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'SHORT_CODE_OBJ', 'CODE_MOL3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.CODE_MOL3'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'CONTROL_NAME_EDIT', 'Parent.Page3.ASel_Spr5'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_CODE', 'REFERENCE_TO_FIELD', 'TAB'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'TITLE', 'Член комиссии 3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'CONTROLSOURCE', 'm.cAlias + ''.NAME_MOL3'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'STORAGE', 'EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'REFERENCE_TO_DICT', 'BA_DOC_MP_CHARGE_MOL3_LINK'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(30)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'SHORT_CODE_OBJ', 'NAME_MOL3'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ''.NAME_MOL3'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'CONTROL_NAME_EDIT', 'Parent.Page3.ATxtN5'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_MOL3_NAME', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'TITLE', 'Номер документа о коммиссии'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'CONTROLSOURCE', 'm.cAlias + ".DOCNUM"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'TYPE_FIELD_DICT', 'VARCHAR(6)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'SHORT_CODE_OBJ', 'DOCNUM'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOCNUM"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCNUM', 'CONTROL_NAME_EDIT', 'Parent.Page3.ATxt9'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'TITLE', 'Дата документа о комиссии'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'CONTROLSOURCE', 'm.cAlias + ".DOCDATE"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'SHORT_CODE_OBJ', 'DOCDATE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOCDATE"'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_DOCDATE', 'CONTROL_NAME_EDIT', 'Parent.Page3.Aseldate10'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'TITLE', 'Примечание'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'CONTROLSOURCE', 'm.cAlias + ''.NOTICE'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'SHORT_CODE_OBJ', 'NOTICE'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ''.NOTICE'''
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_NOTICE', 'CONTROL_NAME_EDIT', 'txtNotice'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_TABLE', 'TITLE', 'Таблица материальных ценностей'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_TABLE', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BA_SAVE_MP_CHARGE_TABLE'',m.cAlias,''SQLNULL(LINK_UP),INV_TYPE,INV_LINK,QTY,ORDERS,ACCOUNT,REST,SUMMA,PRICE, 0, SUM_REST'', ''BA_DOC_MP_CHARGE_TABLE'')'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_TABLE', 'SELECT_RECORDS_METHOD', 'XA_SELECT(''BA_SELECT_MP_CHARGE_TABLE'',m.cAlias,''BA_DOCUMENTS_MP_CHARGE'',.F.,''m.nDocLink'')'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_TABLE', 'SERVER_TABLE_NAME', 'OUT_TABLE_ROW'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_OPTIONS', 'TITLE', 'Настройки'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_OPTIONS', 'SAVE_OBJECT_METHOD', 'X_SAVE_DOCUMENT_OPTIONS()'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_OPTIONS', 'EDIT_OBJECT_METHOD', 'bdoc_brow(''BA_DOC_MZ_NEEDS_OPTIONS'')'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_OPTIONS', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_OPTIONS(m.OBJ_CODE, m.cAlias)'
GO
EXEC X_SET_PROP 'BA_DOC_MP_CHARGE_OPTIONS', 'OPTIONS_OBJECT_CODE', 'BA_DOC_MP_NEEDS_OPT'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', 'TITLE', 'Ссылка на операцию'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', 'STORAGE', 'G_PROV1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', 'SHORT_CODE_OBJ', 'TYP_LINK_1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK1', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'TITLE', 'Типовая операция (Номенклатура)'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'EDIT_OBJECT_METHOD', 'X_VIBOR_OPER(m.oForm, m.oObj, "TYP_LINK_1", "TYP_NAME_1", "BA_DOCUMENTS_MZ_NEEDS")'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'STORAGE', 'G_PROV1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'REFERENCE_TO_DICT', 'BA_MP_CHARGE_OPTIONS_TYP_LINK1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'TYPE_FIELD_DICT', 'VARCHAR(60)'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'SHORT_CODE_OBJ', 'TYP_NAME_1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYP_NAME_1"'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'CONTROL_NAME_EDIT', 'Asel_spr1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME1', 'REFERENCE_TO_FIELD', 'NAME_OPER'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', 'TITLE', 'Ссылка на операцию'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', 'STORAGE', 'G_PROV1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', 'SHORT_CODE_OBJ', 'TYP_LINK_2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_LINK2', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'TITLE', 'Типовая операция (Инвентарь)'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'EDIT_OBJECT_METHOD', 'X_VIBOR_OPER(m.oForm, m.oObj, "TYP_LINK_2", "TYP_NAME_2", "BA_DOCUMENTS_MZ_NEEDS")'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'STORAGE', 'G_PROV1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'REFERENCE_TO_DICT', 'BA_MP_CHARGE_OPTIONS_TYP_LINK2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'TYPE_FIELD_DICT', 'VARCHAR(60)'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'SHORT_CODE_OBJ', 'TYP_NAME_2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYP_NAME_2"'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'CONTROL_NAME_EDIT', 'Asel_spr2'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_OPTIONS_TYP_NAME2', 'REFERENCE_TO_FIELD', 'NAME_OPER'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_MAKER', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_MAKER', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_MAKER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_TYPE', 'TITLE', 'Тип инв.'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_TYPE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_TYPE', 'CONTROLSOURCE', 'm.cAlias+''.INV_TYPE'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_TYPE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_LINK', 'CONTROLSOURCE', 'm.cAlias+''.INV_LINK'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'TITLE', 'Код'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'EDIT_OBJECT_METHOD', 'BA_VIBOR_MP_CHARGE()'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'CONTROLSOURCE', 'm.cAlias+''.INV_CODE'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.INV_CODE'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_NAME', 'CONTROLSOURCE', 'm.cAlias+''.INV_NAME'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_UM_NAME', 'TITLE', 'ЕИ'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_UM_NAME', 'CONTROLSOURCE', 'm.cAlias+''.UM_NAME'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_ACCT_CODE', 'TITLE', 'Субсчет'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_ACCT_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_ACCT_CODE', 'CONTROLSOURCE', 'm.cAlias+''.ACCT_CODE'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_QTY', 'TITLE', 'Количество'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_QTY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_QTY', 'CONTROLSOURCE', 'm.cAlias+''.QTY'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_QTY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_REST', 'TITLE', 'Имеется'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_REST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_REST', 'CONTROLSOURCE', 'm.cAlias+''.REST'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_PRICE', 'TITLE', 'Средняя цена'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_PRICE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_PRICE', 'CONTROLSOURCE', 'm.cAlias+''.PRICE'''
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BA_MP_CHARGE_TABLE_SUMMA', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA'''
GO




GO
--- Инвентаризация расчетов с покупателями и поставщиками (DOCUMENTS_INVENTORY_DBKT) ---
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOCUMENTS_INVENTORY_DBKT', 'Инвентаризация расчетов с покупателями и поставщиками', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_WITH_COMMISSION_70N'), (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOCUMENTS_INVENTORY_DBKT', NAME = 'Инвентаризация расчетов с покупателями и поставщиками', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_WITH_COMMISSION_70N'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='DOCUMENTS_INVENTORY_DBKT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_DEP_NAME', 'Наименование организации', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_DEP_NAME', NAME = 'Наименование организации', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_METHOD_DB')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_METHOD_DB', 'Метод выбора ДБ', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_METHOD_DB', NAME = 'Метод выбора ДБ', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_METHOD_DB'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_METHOD_KT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_METHOD_KT', 'Метод выбора КТ', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_METHOD_KT', NAME = 'Метод выбора КТ', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_METHOD_KT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_PRINT_RES')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_PRINT_RES', 'Печатать результаты инвентаризации', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_PRINT_RES', NAME = 'Печатать результаты инвентаризации', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_PRINT_RES'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_PLACE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_PLACE', 'Место проведения инвентаризации', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_PLACE', NAME = 'Место проведения инвентаризации', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_PLACE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_TYPE_CALC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_TYPE_CALC', 'Наименование вида расчетов', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_TYPE_CALC', NAME = 'Наименование вида расчетов', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_TYPE_CALC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_NUMBER_PRIKAZ')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'Номер приказа', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_NUMBER_PRIKAZ', NAME = 'Номер приказа', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_NUMBER_PRIKAZ'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_DATE_PRIKAZ')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_DATE_PRIKAZ', 'Дата приказа', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_DATE_PRIKAZ', NAME = 'Дата приказа', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_DATE_PRIKAZ'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_DATE_BEGIN')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_DATE_BEGIN', 'Дата начала', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_DATE_BEGIN', NAME = 'Дата начала', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_DATE_BEGIN'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_DATE_END')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_DATE_END', 'Дата окончания', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_DATE_END', NAME = 'Дата окончания', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_DATE_END'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_ZAKLUCH')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_ZAKLUCH', 'Заключение комиссии', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_ZAKLUCH', NAME = 'Заключение комиссии', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_ZAKLUCH'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DBKT_COMMENT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DBKT_COMMENT', 'Комментарий', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DBKT_COMMENT', NAME = 'Комментарий', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DBKT_COMMENT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_DB_TABLE', 'Таблица "Дебиторская задолженность"', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_DB_TABLE', NAME = 'Таблица "Дебиторская задолженность"', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_DB_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INVENTORY_KT_TABLE', 'Таблица "Кредиторская задолженность"', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INVENTORY_KT_TABLE', NAME = 'Таблица "Кредиторская задолженность"', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INVENTORY_KT_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT', 'Настройки Инвентаризация расчетов (Покуп\Постав)', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT', NAME = 'Настройки Инвентаризация расчетов (Покуп\Постав)', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOCUMENTS_INVENTORY_DBKT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_MARKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_MARKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_LINK', 'Ссылка на счет', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_LINK', NAME = 'Ссылка на счет', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_CODE', 'Код счета', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_CODE', NAME = 'Код счета', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_SINTH')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_SINTH', 'Код счета (синт. часть)', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_SINTH', NAME = 'Код счета (синт. часть)', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_SINTH'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_ANALIT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_ANALIT', 'Код счета (ан.часть)', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_ANALIT', NAME = 'Код счета (ан.часть)', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_ANALIT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_NAME', 'Наименование счета', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_NAME', NAME = 'Наименование счета', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_DEP_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_DEP_LINK', 'Ссылка на организацию', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_DEP_LINK', NAME = 'Ссылка на организацию', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_DEP_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_DEP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_DEP_CODE', 'Код организации', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_DEP_CODE', NAME = 'Код организации', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_DEP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_DEP_NAME', 'Наименование организации', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_DEP_NAME', NAME = 'Наименование организации', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_SUMMA_ALL')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_SUMMA_ALL', 'Сумма (всего)', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_SUMMA_ALL', NAME = 'Сумма (всего)', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_SUMMA_ALL'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_SUMMA1')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_SUMMA1', 'Сумма, подтвержденная дебиторами', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_SUMMA1', NAME = 'Сумма, подтвержденная дебиторами', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_SUMMA1'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_SUMMA2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_SUMMA2', 'Сумма, неподтвержденная дебиторами', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_SUMMA2', NAME = 'Сумма, неподтвержденная дебиторами', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_SUMMA2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_SUMMA3')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_SUMMA3', 'Сумма с истекшим сроком давности', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_SUMMA3', NAME = 'Сумма с истекшим сроком давности', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_SUMMA3'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_ACCT_SOURCE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_ACCT_SOURCE', 'Код источника финансирования', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_ACCT_SOURCE', NAME = 'Код источника финансирования', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_ACCT_SOURCE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_DB_TABLE_COMMENT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_DB_TABLE_COMMENT', 'Примечание', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_DB_TABLE_COMMENT', NAME = 'Примечание', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_DB_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_DB_TABLE_COMMENT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_MARKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_MARKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_LINK', 'Ссылка на счет', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_LINK', NAME = 'Ссылка на счет', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_CODE', 'Код счета', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_CODE', NAME = 'Код счета', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_SINTH')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_SINTH', 'Код счета (синт. часть)', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_SINTH', NAME = 'Код счета (синт. часть)', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_SINTH'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_ANALIT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_ANALIT', 'Код счета (ан.часть)', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_ANALIT', NAME = 'Код счета (ан.часть)', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_ANALIT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_NAME', 'Наименование счета', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_NAME', NAME = 'Наименование счета', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_DEP_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_DEP_LINK', 'Ссылка на организацию', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_DEP_LINK', NAME = 'Ссылка на организацию', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_DEP_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_DEP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_DEP_CODE', 'Код организации', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_DEP_CODE', NAME = 'Код организации', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_DEP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_DEP_NAME', 'Наименование организации', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_DEP_NAME', NAME = 'Наименование организации', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_SUMMA_ALL')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_SUMMA_ALL', 'Сумма (всего)', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_SUMMA_ALL', NAME = 'Сумма (всего)', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_SUMMA_ALL'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_SUMMA1')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_SUMMA1', 'Сумма, подтвержденная кредиторами', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_SUMMA1', NAME = 'Сумма, подтвержденная кредиторами', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_SUMMA1'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_SUMMA2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_SUMMA2', 'Сумма, неподтвержденная кредиторами', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_SUMMA2', NAME = 'Сумма, неподтвержденная кредиторами', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_SUMMA2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_SUMMA3')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_SUMMA3', 'Сумма с истекшим сроком давности', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_SUMMA3', NAME = 'Сумма с истекшим сроком давности', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_SUMMA3'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_ACCT_SOURCE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_ACCT_SOURCE', 'Код источника финансирования', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_ACCT_SOURCE', NAME = 'Код источника финансирования', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_ACCT_SOURCE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='INV_KT_TABLE_COMMENT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'INV_KT_TABLE_COMMENT', 'Примечание', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'INV_KT_TABLE_COMMENT', NAME = 'Примечание', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='INVENTORY_KT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='INV_KT_TABLE_COMMENT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_NASTR1')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_NASTR1', 'Настройка', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_NASTR1', NAME = 'Настройка', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_NASTR1'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_DB', 'Настройка счетов для дебиторской задолженности', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_DB', NAME = 'Настройка счетов для дебиторской задолженности', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_DB'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_KT', 'Настройка счетов для кредиторской задолженности', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_KT', NAME = 'Настройка счетов для кредиторской задолженности', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_KT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_DB_MARKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_DB_MARKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_DB_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_DB_CODE', 'Код счета', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_DB_CODE', NAME = 'Код счета', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_DB_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_DB_NAME', 'Наименование счета', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_DB_NAME', NAME = 'Наименование счета', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_DB'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_DB_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_KT_MARKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_KT_MARKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_KT_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_KT_CODE', 'Код счета', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_KT_CODE', NAME = 'Код счета', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_KT_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DOC_INVENT_DBKT_OPT_KT_NAME', 'Наименование счета', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DOC_INVENT_DBKT_OPT_KT_NAME', NAME = 'Наименование счета', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DOC_INVENT_DBKT_OPT_KT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DOC_INVENT_DBKT_OPT_KT_NAME'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'TITLE', 'Инвентаризация расчетов с покупателями и поставщиками'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'REMOVE_OBJECT_METHOD', 'I_DELETE_RECORDS (m.cAlias,"DOCUMENTS_INVENTORY_DBKT", "BV_DELETE_DOCUMENTS", 4, .F., .F.)'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'SAVE_OBJECT_METHOD', 'BK_SAVE_DOC_WITH_COMISSION (''X_SAVE_DOCUMENTS_INVENTORY_DBKT'', m.cAlias,"NUMBER, SQLNULL(DATE), SQLNULL(DATE_PROV), SUMMA, COMMENT, SQLNULL (DEP_LINK), SQLNULL (ACC_LINK), METHOD_DB, METHOD_KT, PRINT_RES, PLACE, TYPE_CALC, NUM_PR, SQLNULL(DATE_PR), SQLNULL(DATE_BEGIN), SQLNULL(DATE_END)"+", ZAKLUCH", "SQLNULL(BC_LINK), SQLNULL(LINK_PRED), SQLNULL(DOC_DATE), SQLNULL(DOC_NUM)", "DOCUMENTS_INVENTORY_DBKT")'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'PRINT_OBJECT_METHOD', 'BK_PRINT_AKT_INVENTORY_DBKT()'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'EDIT_OBJECT_METHOD', 'BDOC_BROW(''BK_DOC_INVENTORY_DBKT'')'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_LIST_ZB(''DOCUMENTS_INVENTORY_DBKT'')'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DOCUMENT_LIST(''DOCUMENTS_INVENTORY_DBKT'')'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'SNAME', 'Инв. Дб\Кт'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'QUERY_REPMAKER', 'KirRepMakerMultiSheet.xls'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'QUERY_REPORT', 'AKT_INVENTORY_DBKT_F0504089.XLT'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'OPTIONS_OBJECT_CODE', 'DOC_INVENT_DBKT_OPT'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'QUERY_ADD_MODULE', 'AKT_INVENTORY_DBKT.BAS'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'OPERATION_MASK', '24'
GO
EXEC X_SET_PROP 'DOCUMENTS_INVENTORY_DBKT', 'REPORT_EXTERNAL_GENERATOR', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'CONTROLSOURCE', 'm.cALIAS + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DEP_NAME', 'CONTROLSOURCE_EDIT', 'm.cALIAS + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'TITLE', 'Метод выбора'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'CONTROLSOURCE', 'm.cAlias + ".METHOD_DB"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'SHORT_CODE_OBJ', 'METHOD_DB'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".METHOD_DB"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_DB', 'CONTROL_NAME_EDIT', 'Parent.Page4.Aoptgrp2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'TITLE', 'Метод выбора'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'CONTROLSOURCE', 'm.cAlias + ".METHOD_KT"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'SHORT_CODE_OBJ', 'METHOD_KT'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".METHOD_KT"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_METHOD_KT', 'CONTROL_NAME_EDIT', 'Parent.Page5.Aoptgrp51'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'TITLE', 'Печатать результаты инвентаризации'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'CONTROLSOURCE', 'm.cAlias + ".PRINT_RES"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'SHORT_CODE_OBJ', 'PRINT_RES'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".PRINT_RES"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PRINT_RES', 'CONTROL_NAME_EDIT', 'Parent.Parent.AChkPrnRes'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'TITLE', 'Место проведения инвентаризации'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'CONTROLSOURCE', 'm.cAlias + ".PLACE"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'TYPE_FIELD_DICT', 'VARCHAR (254)'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'SHORT_CODE_OBJ', 'PLACE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".PLACE"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_PLACE', 'CONTROL_NAME_EDIT', 'ATXT1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'TITLE', 'Вид расчетов'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'CONTROLSOURCE', 'm.cAlias + ".TYPE_CALC"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'TYPE_FIELD_DICT', 'VARCHAR (254)'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'SHORT_CODE_OBJ', 'TYPE_CALC'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYPE_CALC"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_TYPE_CALC', 'CONTROL_NAME_EDIT', 'ATXT3'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'TITLE', 'Приказ (распоряжение) о проведении инвентаризации: номер'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'CONTROLSOURCE', 'm.cAlias + ".NUM_PR"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'TYPE_FIELD_DICT', 'VARCHAR (8)'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'SHORT_CODE_OBJ', 'NUM_PR'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NUM_PR"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_NUMBER_PRIKAZ', 'CONTROL_NAME_EDIT', 'ATXT4'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'TITLE', 'Дата приказа'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'CONTROLSOURCE', 'm.cAlias + ".DATE_PR"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'SHORT_CODE_OBJ', 'DATE_PR'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DATE_PR"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_PRIKAZ', 'CONTROL_NAME_EDIT', 'ASelDate5'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'TITLE', 'Дата начала'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'CONTROLSOURCE', 'm.cAlias + ".DATE_BEGIN"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'SHORT_CODE_OBJ', 'DATE_BEGIN'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DATE_BEGIN"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_BEGIN', 'CONTROL_NAME_EDIT', 'ASelDate6'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'TITLE', 'Дата окончания'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'CONTROLSOURCE', 'm.cAlias + ".DATE_END"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'SHORT_CODE_OBJ', 'DATE_END'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DATE_END"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_DATE_END', 'CONTROL_NAME_EDIT', 'ASelDate7'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'TITLE', 'Заключение комиссии'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'CONTROLSOURCE', 'm.cAlias + ".ZAKLUCH"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'TYPE_FIELD_DICT', 'VARCHAR (254)'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'SHORT_CODE_OBJ', 'ZAKLUCH'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".ZAKLUCH"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'CONTROL_NAME', 'AEdit8'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_ZAKLUCH', 'CONTROL_NAME_EDIT', 'AEdit8'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'TITLE', 'Комментарий'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'CONTROLSOURCE', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'TYPE_FIELD_DICT', 'VARCHAR (254)'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'SHORT_CODE_OBJ', 'COMMENT'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'CONTROL_NAME', 'AEdit9'
GO
EXEC X_SET_PROP 'INVENTORY_DBKT_COMMENT', 'CONTROL_NAME_EDIT', 'AEdit9'
GO
EXEC X_SET_PROP 'INVENTORY_DB_TABLE', 'SAVE_OBJECT_METHOD', 'X_SAVE(''X_SAVE_INVENTORY_DB_TABLE'', m.cAlias,''SQLNULL(LINK_UP), ORDERS, ACC_LINK, SQLNULL(DEP_LINK), SUMMA_ALL, SUMMA1, SUMMA2, SUMMA3, PRIM'',"INVENTORY_DB_TABLE")'
GO
EXEC X_SET_PROP 'INVENTORY_DB_TABLE', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOC_TABLE_LIST ("INVENTORY_DB_TABLE")'
GO
EXEC X_SET_PROP 'INVENTORY_DB_TABLE', 'SERVER_TABLE_NAME', 'OUT_TABLE_ROW'
GO
EXEC X_SET_PROP 'INVENTORY_KT_TABLE', 'SAVE_OBJECT_METHOD', 'X_SAVE(''X_SAVE_INVENTORY_KT_TABLE'', m.cAlias,''SQLNULL(LINK_UP), ORDERS, ACC_LINK, SQLNULL(DEP_LINK), SUMMA_ALL, SUMMA1, SUMMA2, SUMMA3, PRIM'',"INVENTORY_KT_TABLE")'
GO
EXEC X_SET_PROP 'INVENTORY_KT_TABLE', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOC_TABLE_LIST ("INVENTORY_KT_TABLE")'
GO
EXEC X_SET_PROP 'INVENTORY_KT_TABLE', 'SERVER_TABLE_NAME', 'OUT_TABLE_ROW'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT', 'TITLE', 'Настройки инвентаризации расчетов с покупателями и поставщиками'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT', 'SAVE_OBJECT_METHOD', 'X_SAVE_DOCUMENT_OPTIONS()'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT', 'EDIT_OBJECT_METHOD', 'bdoc_brow(''BK_DOC_INVENT_DBKT_OPT'')'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_OPTIONS(m.OBJ_CODE, m.cAlias)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_MARKER', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_MARKER', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_MARKER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_LINK', 'CONTROLSOURCE', 'm.cAlias+''.ACC_LINK'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_LINK', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_LINK', 'SHORT_CODE_OBJ', 'ACC_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'TITLE', 'Счет'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'CONTROLSOURCE', 'm.cAlias+''.ACC_CODE'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'TYPE_FIELD_DICT', 'CHAR(20)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'SHORT_CODE_OBJ', 'ACC_CODE'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACC_CODE'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'TITLE', 'Код счета'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'CONTROLSOURCE', 'm.cAlias+''.ACC_SINTH'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'TYPE_FIELD_DICT', 'VARCHAR(3)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'SHORT_CODE_OBJ', 'ACC_SINTH'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SINTH', 'REFERENCE_TO_FIELD', 'cSINTH'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'TITLE', 'Код счета'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'CONTROLSOURCE', 'm.cAlias+''.ACC_AN'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'TYPE_FIELD_DICT', 'VARCHAR(2)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'SHORT_CODE_OBJ', 'ACC_AN'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_ANALIT', 'REFERENCE_TO_FIELD', 'cANALIT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'TITLE', 'Наименование счета'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'CONTROLSOURCE', 'm.cAlias+''.ACC_NAME'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(150)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'SHORT_CODE_OBJ', 'ACC_NAME'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_LINK', 'CONTROLSOURCE', 'm.cAlias+''.DEP_LINK'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_LINK', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_LINK', 'SHORT_CODE_OBJ', 'DEP_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'CONTROLSOURCE', 'm.cAlias+''.DEP_CODE'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_DEP_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'SHORT_CODE_OBJ', 'DEP_CODE'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'CONTROLSOURCE', 'm.cAlias+''.DEP_NAME'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_DEP_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'SNAME', 'Организация'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_DEP_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'TITLE', 'Сумма (всего)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA_ALL'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA_ALL', 'SHORT_CODE_OBJ', 'SUMMA_ALL'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'TITLE', 'Сумма, подтвержденная'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA1'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA1', 'SHORT_CODE_OBJ', 'SUMMA1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'TITLE', 'Сумма, неподтвержденная'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA2'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA2', 'SHORT_CODE_OBJ', 'SUMMA2'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'TITLE', 'Сумма с истекшим сроком'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA3'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_SUMMA3', 'SHORT_CODE_OBJ', 'SUMMA3'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'TITLE', 'ИФ'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_SOU'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'REFERENCE_TO_DICT', 'INV_DB_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'TYPE_FIELD_DICT', 'VARCHAR(1)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'SHORT_CODE_OBJ', 'CODE_SOU'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_ACCT_SOURCE', 'REFERENCE_TO_FIELD', 'cSource'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'TITLE', 'Примечание'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'CONTROLSOURCE', 'm.cAlias+''.PRIM'''
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'STORAGE', 'STRING'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'INV_DB_TABLE_COMMENT', 'SHORT_CODE_OBJ', 'PRIM'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_MARKER', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_MARKER', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_MARKER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_LINK', 'CONTROLSOURCE', 'm.cAlias+''.ACC_LINK'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_LINK', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_LINK', 'SHORT_CODE_OBJ', 'ACC_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'TITLE', 'Счет'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'CONTROLSOURCE', 'm.cAlias+''.ACC_CODE'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'TYPE_FIELD_DICT', 'CHAR(20)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'SHORT_CODE_OBJ', 'ACC_CODE'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACC_CODE'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'TITLE', 'Код счета'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'CONTROLSOURCE', 'm.cAlias+''.ACC_SINTH'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'TYPE_FIELD_DICT', 'VARCHAR(3)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'SHORT_CODE_OBJ', 'ACC_SINTH'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SINTH', 'REFERENCE_TO_FIELD', 'cSINTH'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'TITLE', 'Код счета'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'CONTROLSOURCE', 'm.cAlias+''.ACC_AN'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'TYPE_FIELD_DICT', 'VARCHAR(2)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'SHORT_CODE_OBJ', 'ACC_AN'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_ANALIT', 'REFERENCE_TO_FIELD', 'cANALIT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'TITLE', 'Наименование счета'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'CONTROLSOURCE', 'm.cAlias+''.ACC_NAME'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(150)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'SHORT_CODE_OBJ', 'ACC_NAME'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_LINK', 'CONTROLSOURCE', 'm.cAlias+''.DEP_LINK'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_LINK', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_LINK', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_LINK', 'SHORT_CODE_OBJ', 'DEP_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'CONTROLSOURCE', 'm.cAlias+''.DEP_CODE'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_DEP_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'SHORT_CODE_OBJ', 'DEP_CODE'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'CONTROLSOURCE', 'm.cAlias+''.DEP_NAME'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_DEP_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'SNAME', 'Организация'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_DEP_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'TITLE', 'Сумма (всего)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA_ALL'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA_ALL', 'SHORT_CODE_OBJ', 'SUMMA_ALL'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'TITLE', 'Сумма, подтвержденная'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA1'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA1', 'SHORT_CODE_OBJ', 'SUMMA1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'TITLE', 'Сумма, неподтвержденная'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA2'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA2', 'SHORT_CODE_OBJ', 'SUMMA2'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'TITLE', 'Сумма с истекшим сроком'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'CONTROLSOURCE', 'm.cAlias+''.SUMMA3'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'STORAGE', 'SUMMA'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'TYPE_FIELD_DICT', 'NUMERIC(28, 4)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_SUMMA3', 'SHORT_CODE_OBJ', 'SUMMA3'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'TITLE', 'ИФ'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'CONTROLSOURCE', 'm.cAlias+''.CODE_SOU'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'REFERENCE_TO_DICT', 'INV_KT_TABLE_ACCT_LINK'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'TYPE_FIELD_DICT', 'VARCHAR(1)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'SHORT_CODE_OBJ', 'CODE_SOU'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_ACCT_SOURCE', 'REFERENCE_TO_FIELD', 'cSource'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'TITLE', 'Примечание'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'CONTROLSOURCE', 'm.cAlias+''.PRIM'''
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'STORAGE', 'STRING'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'INV_KT_TABLE_COMMENT', 'SHORT_CODE_OBJ', 'PRIM'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_NASTR1', 'STORAGE', 'S_OPTIONS'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_NASTR1', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_NASTR1', 'SHORT_CODE_OBJ', 'OPT1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB', 'TITLE', 'Счета для дебиторской задолженности'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BK_UPDATE_DOC_NASTR_SA'', m.cAlias,''SQLNULL(LINK_UP),  ACCOUNT,0'',"DOC_INVENT_DBKT_OPT_DB")'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB', 'SELECT_RECORDS_METHOD', 'SQL.EXEC ("SELECT 0 AS CHECKED, 0 AS DEL, 0 AS UPD, * FROM dbo.FT_DOC_NASTR_SA (" + ALLTRIM (STR (m.nNASTR_LINK)) + ", 0)", m.cAlias)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB', 'SERVER_TABLE_NAME', 'DOC_NASTR_S_ACCOUNTS'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT', 'TITLE', 'Счета для кредиторской задолженности'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BK_UPDATE_DOC_NASTR_SA'', m.cAlias,''SQLNULL(LINK_UP),  ACCOUNT,1'',"DOC_INVENT_DBKT_OPT_DB")'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT', 'SELECT_RECORDS_METHOD', 'SQL.EXEC ("SELECT 0 AS CHECKED, 0 AS DEL, 0 AS UPD, * FROM dbo.FT_DOC_NASTR_SA (" + ALLTRIM (STR (m.nNASTR_LINK)) + ", 1)", m.cAlias)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT', 'SERVER_TABLE_NAME', 'DOC_NASTR_S_ACCOUNTS'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_MARKER', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_MARKER', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_MARKER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'TITLE', 'Счет'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'EDIT_OBJECT_METHOD', 'a_vibor_01("PLAN_ACCOUNTS_LIST", oObj.parent.Parent.RECORDSOURCE, "LINK, ACCCODE, NAME", "ACCOUNT, ACCT_CODE, ACCT_NAME", "", "","",  .T., 1, oForm, oObj,''lg_prov_notsbs()'')'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'CONTROLSOURCE', 'm.cAlias+''.ACCT_CODE'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'TYPE_FIELD_DICT', 'CHAR(20)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'SHORT_CODE_OBJ', 'ACCT_CODE'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACCT_CODE'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'TITLE', 'Наименование счета'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'CONTROLSOURCE', 'm.cAlias+''.ACCT_NAME'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'TYPE_FIELD_DICT', 'CHAR(254)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'SHORT_CODE_OBJ', 'ACCT_NAME'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_DB_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACCT_NAME'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_MARKER', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_MARKER', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_MARKER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'TITLE', 'Счет'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'EDIT_OBJECT_METHOD', 'a_vibor_01("PLAN_ACCOUNTS_LIST", oObj.parent.Parent.RECORDSOURCE, "LINK, ACCCODE, NAME", "ACCOUNT, ACCT_CODE, ACCT_NAME", "", "","",  .T., 1, oForm, oObj,''lg_prov_notsbs()'')'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'CONTROLSOURCE', 'm.cAlias+''.ACCT_CODE'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'TYPE_FIELD_DICT', 'CHAR(20)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'SHORT_CODE_OBJ', 'ACCT_CODE'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACCT_CODE'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'TITLE', 'Наименование счета'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'CONTROLSOURCE', 'm.cAlias+''.ACCT_NAME'''
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'STORAGE', 'ACCOUNT'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'TYPE_FIELD_DICT', 'CHAR(254)'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'SHORT_CODE_OBJ', 'ACCT_NAME'
GO
EXEC X_SET_PROP 'DOC_INVENT_DBKT_OPT_KT_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias+''.ACCT_NAME'''
GO

EXECUTE X_FORM_VIEW_OPTIONS 'DOC_INVENT_DBKT_OPT'
GO


GO
--Таблица VAC_PERIOD_CHANGE
IF not exists(select * from sysobjects where id = object_id('[dbo].[VAC_PERIOD_CHANGE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[VAC_PERIOD_CHANGE] (
	[LINK] int NOT NULL IDENTITY(1,1) ,
	[LINK_EMPL] int NOT NULL ,
	[DATE1] datetime NOT NULL ,
	[DATE2] datetime NOT NULL ,
	[YEAR1] int NOT NULL ,
	[YEAR2] int NOT NULL ,
	[COMMENT] varchar(254) NULL )
GO

	GRANT SELECT, UPDATE, DELETE ON dbo.[VAC_PERIOD_CHANGE] TO PUBLIC
	
GO

--Расширенные свойства--
--Индексы

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_VAC_PERIOD_CHANGE')
CREATE UNIQUE CLUSTERED INDEX [IX_VAC_PERIOD_CHANGE] ON [dbo].[VAC_PERIOD_CHANGE] ([LINK_EMPL], [DATE1], [DATE2])
GO
--Констрэйнты

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[PK_VAC_PERIOD_CHANGE]'))
ALTER TABLE [dbo].[VAC_PERIOD_CHANGE] 
ADD CONSTRAINT [PK_VAC_PERIOD_CHANGE] PRIMARY KEY NONCLUSTERED ([LINK]) ON [INDEX]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysconstraints WHERE constid =  object_id('dbo.[FK_VAC_PERIOD_CHANGE_EMPL]'))
ALTER TABLE [dbo].[VAC_PERIOD_CHANGE] 
ADD CONSTRAINT [FK_VAC_PERIOD_CHANGE_EMPL] FOREIGN KEY ([LINK_EMPL]) REFERENCES [dbo].[EMPL] ([LINK])
GO

GO

--ОБЪЕКТЫ БД 21.01.2015
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[FT_DOC_NASTR_SA]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[FT_DOC_NASTR_SA]

GO
CREATE FUNCTION dbo.FT_DOC_NASTR_SA
	(
	@iLINK_UP	INT	=	NULL,
	@DB_KR		TINYINT	=	255
	)
RETURNS TABLE
AS
RETURN
	SELECT 
		DN_SA.LINK,
		DN_SA.LINK_UP,
		DN_SA.ACCOUNT,
		DN_SA.DB_KR,
		ACCT_CODE = SA.CODE,
		ACCT_NAME = SA.NAME
	FROM dbo.DOC_NASTR_S_ACCOUNTS DN_SA
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = DN_SA.ACCOUNT)
	WHERE
		(@iLINK_UP IS NULL
			OR DN_SA.LINK_UP = @iLINK_UP
		)	
		AND (ISNULL (@DB_KR, 255) = 255
			OR DN_SA.DB_KR = @DB_KR
			)

GO


GRANT SELECT ON dbo.[FT_DOC_NASTR_SA] TO PUBLIC

GO


--Расширенные свойства--


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_GZ_PLAN]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[BB_GZ_PLAN]
GO


CREATE           VIEW dbo.BB_GZ_PLAN 
AS
SELECT	G.LINK,
	G.[DATE],
	G.DATE_PROV,
	G.NUMBER,
	[FLAG_JC] = CASE WHEN G.DATE_PROV IS NULL THEN 0 ELSE 1 END,
	SUMMA 		= isnull(S.SUMMA, G.SUMMA),
	SUMMA_FIN 	= isnull(S.SUMMA_FB, 0) + isnull(S.SUMMA_FV, 0),
	SUMMA_FB 	= isnull(S.SUMMA_FB, 0),
	SUMMA_FV 	= isnull(S.SUMMA_FV, 0),
	G.COMMENT,
	[DEP_LINK]	= G.DEP,
	[DEP_CODE]	= D.CODE,
	[DEP_NAME]	= D.[NAME],
	type = 0

from 	G_PROV as G 
left join dbo.DEPARTMENTS D  on G.DEP = D.LINK
left join (select LINK_UP, sum(SUMMA) as SUMMA, sum(SUMMA_FB) as SUMMA_FB, sum(SUMMA_FV) as SUMMA_FV
	   from dbo.GZ_PLAN_TABLE 
	   group by LINK_UP) S on LINK_UP = G.LINK
where  G.OBJECT in (select LINK from dbo.S_OBJECTS where CODE='BB_GZ_PLAN')













GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[GET_CODE_STR_BY_CIFSGU]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[GET_CODE_STR_BY_CIFSGU]

GO

/*******************************************************************************

	© Профессионал+, 2013

*******************************************************************************/
-- Возвращает код строки по коду дохода и КОСГУ источника финансирования.
CREATE FUNCTION dbo.[GET_CODE_STR_BY_CIFSGU](
@gp char(10), -- Код источника
@sgu char(3) -- КОСГУ.
)
RETURNS CHAR(3) AS
BEGIN
DECLARE @cReturn CHAR(3)
declare @dd datetime
		select @dd = getdate()
		select top 1 @cReturn = Code_str
		from dbo.report_kbk where code_form in ('ИСТОЧНИКИ_2011')
		and RIGHT(code, 2) <> '00'
		--and (end_date >= @dd or end_date is null)
		--and (begin_date <= @dd or begin_date is null)
		and substring(code, 7,10) = @gp
		and RIGHT(code, 3) = @sgu
		and LEN(rtrim(ltrim(code))) = 23
				group by  code_str, substring(code, 7,10), RIGHT(code, 3)
	   RETURN @cReturn
END





GO


GRANT EXECUTE ON dbo.[GET_CODE_STR_BY_CIFSGU] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_TABELS_W]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[SA_TABELS_W]

GO
CREATE view [dbo].SA_TABELS_W
AS
select 
	T.link,
	D.LINK_DOC as LINK_UP,
	T.link_up as link_up1,
	link_sovm = COALESCE(t.link_sovm,0),
	t.link_day,
	s.SYMB,
	s.NAME,
	s.FORE_COLOR,
	S.WORK_D, 
	S.TYP_YAVKA,
	t.d1,
	t.d2,
	t.d3,
	t.d4,
	t.d5,
	t.d6,
	t.d7,
	t.d8,
	t.d9,
	t.d10,
	t.d11,
	t.d12,
	t.d13,
	t.d14,
	t.d15,
	t.d16,
	t.d17,
	t.d18,
	t.d19,
	t.d20,
	t.d21,
	t.d22,
	t.d23,
	t.d24,
	t.d25,
	t.d26,
	t.d27,
	t.d28,
	t.d29,
	t.d30,
	t.d31
from 
	dbo.tabels D
	inner join dbo.tabels_w T on D.LINK = T.link_up
	inner join dbo.TYP_DAYS S ON S.LINK = t.link_day

GO


GRANT SELECT ON dbo.[SA_TABELS_W] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BV_NOMENCLATURE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BV_NOMENCLATURE]

GO






/*
© Кейсистемс (Keysystems), 2005
*/


CREATE    VIEW dbo.BV_NOMENCLATURE
AS
SELECT	N.LINK,
--	[CODE] = CONVERT(CHAR(10),N.CODE),
	[CODE] = N.CODE,
	[NAME] = CONVERT(VARCHAR(254),N.[NAME]),
	[LINK_GRP] = N.GROUP_INV,


	[CODE_GRP] = CONVERT(CHAR(7), GI.CODE),
	[NAME_GRP] = CONVERT(VARCHAR(50), GI.[NAME]),
	[LINK_ACC] = GI.ACCOUNT,
	[CODE_ACC] = SA.CODE,
	[NAME_ACC] = SA.[NAME],
	[LINK_UM] = N.UM,
	[CODE_UM]=(SELECT CONVERT(VARCHAR(10),B.CODE) FROM dbo.DICTION B WHERE B.LINK = N.UM),
	[NAME_UM]=(SELECT CONVERT(VARCHAR(20),B.NAME) FROM dbo.DICTION B WHERE B.LINK = N.UM),
	[SERIES] = N.SERIES,
	[PRICE_TYPE] = N.PRICE_TYPE,
   	[IS_EXTRA] = N.[IS_EXTRA],
	[LINK_OKDP],
	[CODE_OKDP]= OKDP.CODE,
	[NAME_OKDP]= OKDP.NAME,
	[LINK_OKPD],
	[CODE_OKPD]= OKPD.CODE,
	[NAME_OKPD]= OKPD.NAME,
	GI.[TYPE],
	[COEFF],
	[OKDP_UM] = OKDP.UM,
	[OKDP_CODE_UM]=(SELECT CONVERT(VARCHAR(10),B.CODE) FROM dbo.DICTION B WHERE B.LINK = OKDP.UM),
	[OKDP_NAME_UM]=(SELECT CONVERT(VARCHAR(20),B.NAME) FROM dbo.DICTION B WHERE B.LINK = OKDP.UM),
	[COEFF_OKPD],
	[OKPD_UM] = OKPD.UM,
	[OKPD_CODE_UM]=(SELECT CONVERT(VARCHAR(10),B.CODE) FROM dbo.DICTION B WHERE B.LINK = OKPD.UM),
	[OKPD_NAME_UM]=(SELECT CONVERT(VARCHAR(20),B.NAME) FROM dbo.DICTION B WHERE B.LINK = OKPD.UM),
	N.ISUSED, 
	CASE
		WHEN GI.ISUSED = 1 AND N.ISUSED = 1 THEN CONVERT (VARCHAR (3), 'Да')
		ELSE CONVERT (VARCHAR (3), 'Нет')
	END AS ISUSED_COM
FROM dbo.NOMENCLATURE N
LEFT JOIN dbo.GROUP_INV GI ON GI.LINK = N.GROUP_INV
LEFT JOIN dbo.S_ACCOUNTS SA ON SA.LINK = GI.ACCOUNT
LEFT JOIN dbo.OKDP OKDP ON OKDP.LINK = N.LINK_OKDP
LEFT JOIN dbo.OKPD OKPD ON OKPD.LINK = N.LINK_OKPD
-- WHERE GI.ISUSED = 1


GO


GRANT SELECT ON dbo.[BV_NOMENCLATURE] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BS_GetWorkMode]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BS_GetWorkMode]

GO
CREATE FUNCTION dbo.BS_GetWorkMode (@WORK_MODE	VARCHAR (30))
RETURNS TINYINT
AS
BEGIN
	DECLARE
		@WORK_STATUS	TINYINT
	
	SELECT
		@WORK_STATUS = WORK_STATUS
	FROM dbo.BS_WORKMODE
	WHERE WORK_MODE = @WORK_MODE
	
	RETURN ISNULL (@WORK_STATUS, 0)
END

		

GO


GRANT EXECUTE ON dbo.[BS_GetWorkMode] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_VIEW_EXPORT_FORMAT_NALOG_FN]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BK_VIEW_EXPORT_FORMAT_NALOG_FN]

GO
CREATE FUNCTION dbo.BK_VIEW_EXPORT_FORMAT_NALOG_FN (@YEAR INT = NULL)
RETURNS TABLE

RETURN

	-- Форматы для налога на прибыль --
	SELECT FORM_CODE = 'ND_NP',
		FNAME = 'Формат 5.02 (с 01.01.2009 г.)', PROC_NAME = 'BK_EXPORT_F1151006', 
		PRG_SKRIPT = CONVERT(VARCHAR(100),''),
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR < 2011

	UNION ALL

	SELECT FORM_CODE = 'ND_NP',
		FNAME = 'Формат 5.03 (с 01.01.2011 г.)', PROC_NAME = 'BK_EXPORT_F1151006_503', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR BETWEEN 2011 AND 2013

	UNION ALL

	SELECT FORM_CODE = 'ND_NP',
		FNAME = 'Формат 5.05 (с 01.12.2013 г.)', PROC_NAME = 'BK_EXPORT_F1151006_505', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR >= 2013

	UNION ALL
	-- Форматы для транспортного налога --
	SELECT
		FORM_CODE = 'ND_TN',
		FNAME = 'Формат 4.01 (с 01.01.2007 г.)',
		PROC_NAME = 'BK_EXPORT_F1152004', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = 'BK_TEST_EXP_F1152027'
	WHERE @YEAR < 2012	

	UNION ALL

	SELECT
		FORM_CODE = 'ND_TN',
		FNAME = 'Формат 5.01 (с 01.01.2012 г.)',
		PROC_NAME = 'BK_EXPORT_F1152004_501', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR = 2012

	UNION ALL

	SELECT
		FORM_CODE = 'ND_TN',
		FNAME = 'Формат 5.02 (с 01.01.2013 г.)',
		PROC_NAME = 'BK_EXPORT_F1152004_502', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR = 2013
	
	UNION ALL

	SELECT
		FORM_CODE = 'ND_TN',
		FNAME = 'Формат 5.03 (с 01.01.2015 г.)',
		PROC_NAME = 'BK_EXPORT_F1152004_503', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = ''
	WHERE @YEAR >= 2014

	UNION ALL

	SELECT FORM_CODE = 'AV_TN',
		FNAME = 'Формат 4.01 (с 01.01.2007 г.)', PROC_NAME = 'BK_EXPORT_F1152027', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = 'BK_TEST_EXP_F1152027'

	UNION ALL

	--- Форматы для налога на имущество ---
	SELECT FORM_CODE = 'AV_F1152028',
		FNAME = 'Формат 5.00 (с 01.01.2008 г.)',
		PROC_NAME = 'BK_EXPORT_F1152028', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = 'BK_TEST_EXP_F1152028'
	UNION ALL
	SELECT FORM_CODE = 'AV_ASS',
		FNAME = 'Формат 5.00 (с 01.01.2008 г.)',
		PROC_NAME = 'BK_EXPORT_F1152026', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = 'BK_TEST_EXP_F1152028'
	UNION ALL
	-- Форматы с 01.01.2012 --
	SELECT FORM_CODE = 'ND_IMU',
		FNAME = 'Формат 5.02 (с 01.01.2012 г.)',
		PROC_NAME = 'BK_EXPORT_F1152026_502', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = '' --'BK_TEST_EXP_F1152028'
	WHERE @YEAR < 2013
	UNION ALL
	SELECT FORM_CODE = 'AV_IMU',
		FNAME = 'Формат 5.02 (с 01.01.2012 г.)',
		PROC_NAME = 'BK_EXPORT_F1152028_502', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = '' --'BK_TEST_EXP_F1152028'
	WHERE @YEAR < 2014		
	UNION ALL
	-- Форматы с 01.01.2013 --
	SELECT FORM_CODE = 'ND_IMU',
		FNAME = 'Формат 5.03 (с 01.01.2013 г.)',
		PROC_NAME = 'BK_EXPORT_F1152026_503', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = '' --'BK_TEST_EXP_F1152028'
	UNION ALL
	SELECT FORM_CODE = 'AV_IMU',
		FNAME = 'Формат 5.03 (с 01.01.2014 г.)',
		PROC_NAME = 'BK_EXPORT_F1152028_503', 
		PRG_SKRIPT = '',
		DIR = 'IMNS',
		TEST_PROC = '' --'BK_TEST_EXP_F1152028'
	WHERE @YEAR >= 2014		

	UNION ALL
	-- Форматы для 4ФСС --
	SELECT FORM_CODE = '4FSS',
		FNAME = 'формат, утвержденный приказом Минздравсоцразвития России от 06.11.2009 n 871н', PROC_NAME = 'SA_4FSS_EXPORT', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_4FSS_EXPORT_TEST'
	WHERE
		@YEAR <= 2010	
	UNION ALL	
	SELECT FORM_CODE = '4FSS',
		FNAME = 'Версия формата 0.3 (Приказ №19 от 12.02.2010 в ред. от 21.03.2011 (№53)', PROC_NAME = 'SA_4FSS_EXPORT_v03', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_4FSS_EXPORT_TEST'
	WHERE
		@YEAR = 2011
	UNION ALL
	SELECT FORM_CODE = '4FSS',
		FNAME = 'Версия формата 0.4 (Приказ № от 22.11.2011)', PROC_NAME = 'SA_4FSS_EXPORT_v04', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_4FSS_EXPORT_TEST'
	WHERE
		@YEAR = 2012
	UNION ALL
	SELECT FORM_CODE = '4FSS',
		FNAME = 'Версия формата 0.5 (Приказ №107н от 19.03.2013)', PROC_NAME = 'SA_4FSS_EXPORT_v05', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_4FSS_EXPORT_TEST'
	WHERE
		@YEAR = 2013	
	UNION ALL
	SELECT FORM_CODE = '4FSS',
		FNAME = 'Версия формата 0.6 (Приказ №107н от 19.03.2013 в ред. от 11.02.2014 № 94н)', PROC_NAME = 'SA_4FSS_EXPORT_v05', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_4FSS_EXPORT_TEST'
	WHERE
		@YEAR >= 2014	
	UNION ALL
	
	-- Формат выгрузки РСВ-1 --
	SELECT FORM_CODE = 'РСВ-1',
		FNAME = 'Формат 07.00 (2011)', PROC_NAME = 'SA_RSV1_EXPORT_0700_2011', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_RSV1_EXPORT_TEST'
	WHERE
		@YEAR = 2011	
	UNION ALL	
	
	-- Формат выгрузки РСВ-1 --
	SELECT FORM_CODE = 'РСВ-1',
		FNAME = 'Формат 07.00 (от 15.03.2012 г. №232н)', PROC_NAME = 'SA_RSV1_EXPORT_0700_2012', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_RSV1_EXPORT_TEST'
	WHERE
		@YEAR = 2012			
	UNION ALL	
	
	-- Формат выгрузки РСВ-1 --
	SELECT FORM_CODE = 'РСВ-1',
		FNAME = 'Формат 07.00 (от 15.03.2012 г. №232н)', PROC_NAME = 'SA_RSV1_EXPORT_0700_2013', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_RSV1_EXPORT_TEST'
	WHERE
		@YEAR = 2013
	UNION ALL	
	
	-- Формат выгрузки РСВ-1 --
	SELECT FORM_CODE = 'РСВ-1',
		FNAME = 'Формат 07.00 (от 03.03.2014 г. №25п)', PROC_NAME = 'SA_RSV1_EXPORT_0700_2014', 
		PRG_SKRIPT = '',
		DIR = 'PF',
		TEST_PROC = 'SA_RSV1_EXPORT_TEST'
	WHERE
		@YEAR >= 2014	
	UNION ALL
	-- Формат выгрузки П-2 (краткая) --
	SELECT FORM_CODE = '0617005',
		FNAME = 'Формат выгрузки формы П-2 (краткая) для Росстата', PROC_NAME = 'BK_EXPORT_F0617005', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''

	UNION ALL
	-- Формат выгрузки П-2 (квартальная) --
	SELECT FORM_CODE = '0617004',
		FNAME = 'Формат выгрузки формы П-2 (квартальная) для Росстата', PROC_NAME = 'BK_EXPORT_F0617004', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- П-2 кв. с 01.01.2011 --
	SELECT FORM_CODE = '0617004_11',
		FNAME = 'Формат выгрузки формы П-2 (квартальная) для Росстата', PROC_NAME = 'BK_EXPORT_F0617004_11', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''

	-- Формат выгрузки П-2 ИНВ (годовая) --
	UNION ALL
	SELECT FORM_CODE = 'П2_ИНВ',
		FNAME = 'Формат выгрузки формы П-2(ИНВ) для Росстата', PROC_NAME = 'BK_EXPORT_F0617010', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	WHERE @YEAR < 2012	

	UNION ALL
	SELECT FORM_CODE = 'П2_ИНВ',
		FNAME = 'Формат выгрузки формы П-2(ИНВ) для Росстата', PROC_NAME = 'BK_EXPORT_F0617010_2012', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	WHERE @YEAR >= 2012	

	UNION ALL
	-- Формат выгрузки П-4 --
	SELECT FORM_CODE = '0606010',
		FNAME = 'Формат выгрузки формы П-4 для Росстата', PROC_NAME = 'SK_EXPORT_F0606010', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	WHERE 
		@YEAR <= 2012	
	UNION ALL
	-- Формат выгрузки П-4 c 01.01.2013 --
	SELECT FORM_CODE = '0606010',
		FNAME = 'Формат выгрузки формы П-4 для Росстата', PROC_NAME = 'SK_EXPORT_F0606010_13', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	WHERE 
		@YEAR >= 2013		


	UNION ALL
	-- Формат выгрузки 1-ГС --
	SELECT FORM_CODE = '1GS',
		FNAME = 'Формат выгрузки формы 1-ГС для Росстата', PROC_NAME = 'KJ_EXPORT_1GS', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 2-ГС --
	SELECT FORM_CODE = '2GS_GZ',
		FNAME = 'Формат выгрузки формы 2-ГС для Росстата', PROC_NAME = 'KJ_EXPORT_2GS', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 1-МС --
	SELECT FORM_CODE = '1MS',
		FNAME = 'Формат выгрузки формы 1-МС для Росстата', PROC_NAME = 'KJ_EXPORT_1MS', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 2-МС --
	SELECT FORM_CODE = '2MS',
		FNAME = 'Формат выгрузки формы 2-МС для Росстата', PROC_NAME = 'KJ_EXPORT_2MS', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 1-Т(ГМС) --
	SELECT FORM_CODE = '1T_GMS',
		FNAME = 'Формат выгрузки формы 1-Т(ГМС) для Росстата', PROC_NAME = 'KJ_EXPORT_1T_GMS', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 1-торги (квартальная) --
	SELECT FORM_CODE = '0607006',
		FNAME = 'Формат выгрузки формы 1-торги для Росстата', PROC_NAME = 'BK_EXPORT_F0607006', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 1-торги (квартальная) --
	SELECT FORM_CODE = '1_ТОРГИ',
		FNAME = 'Формат выгрузки формы 1-торги для Росстата', PROC_NAME = 'BK_EXPORT_F0607006_11', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	UNION ALL
	-- Формат выгрузки 11 краткая (годовая) --
	SELECT FORM_CODE = '0602002',
		FNAME = 'Формат выгрузки формы 11-краткая для Росстата', PROC_NAME = 'BK_EXPORT_F0602002', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''

	UNION ALL
	SELECT FORM_CODE = 'КРАТ_11',
		FNAME = 'Формат выгрузки формы 11-краткая для Росстата', PROC_NAME = 'BK_EXPORT_F0602002_2012', 
		PRG_SKRIPT = '',
		DIR = 'RST',
		TEST_PROC = ''
	WHERE 
		@YEAR >= 2012		
	
	-- Выгрузка АХД (МЗ 2013) --		
	UNION ALL
	SELECT
		FORM_CODE = 'AHD_EXPORT_REST',
		FNAME = 'Формат 1.00 (с 01.09.2013 г.)',
		PROC_NAME = 'BK_EXPORT_AHD_REST',
		PRG_SKRIPT = '',
		DIR = 'AHD',
		TEST_PROC = ''

	UNION ALL
	SELECT
		FORM_CODE = 'AHD_EXPORT_PROV',
		FNAME = 'Формат 1.00 (с 01.09.2013 г.)',
		PROC_NAME = 'BK_EXPORT_AHD_PROV',
		PRG_SKRIPT = '',
		DIR = 'AHD',
		TEST_PROC = ''
	

	-- Выгрузка данных об ОС --		
	UNION ALL
	SELECT
		FORM_CODE = 'EOD_EXPORT_INV1',
		FNAME = 'Формат 1.00 (с 01.01.2013 г.)',
		PROC_NAME = 'BK_EXPORT_INV1',
		PRG_SKRIPT = '',
		DIR = 'AHD',
		TEST_PROC = ''




GO


GRANT SELECT ON dbo.[BK_VIEW_EXPORT_FORMAT_NALOG_FN] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[EMPL_STAFF]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[EMPL_STAFF]

GO


CREATE FUNCTION dbo.EMPL_STAFF(@dDATE DATETIME = NULL)
	RETURNS @RET TABLE (
		EMPL_LINK INT,
		STAFF_LINK INT,
		STAFF_HEAD INT,
		SUBDIV_LINK INT,
		SUBDIV_HEAD INT,
		POST_LINK INT,
		NUM_STAKE NUMERIC(3,2),
		MOVE_LINK INT,
		[STATUS] INT,
		NOTWORK TINYINT,
		OKLAD NUMERIC(10,2),
		LINK_KBK INT,
		KAT_LINK int,
		DATE_BEGIN DATETIME
	)
AS BEGIN
	IF @dDATE IS NULL BEGIN
		SET @dDATE = (SELECT WORKDATE FROM dbo.USER_INFO)
	END
	DECLARE @MOVES TABLE(EMPL_LINK INT, STAFF_LINK INT, NUM_STAKE NUMERIC(3,2), MOVE_LINK INT, STATUS INT, OKLAD NUMERIC(10,2), DATE_BEGIN DATETIME)
	DECLARE @MOVES2 TABLE(EMPL_LINK INT, STAFF_LINK INT, STAFF_HEAD INT, NUM_STAKE NUMERIC(3,2), MOVE_LINK INT, [STATUS] INT, OKLAD NUMERIC(10,2), DATE_BEGIN DATETIME)

	declare @oklad table (empl_link int, summa numeric(18,2) )
	insert into @oklad (empl_link, summa)
	SELECT 
		MP.EMPL_LINK,
		SUM(MP.SUMMA)
	FROM 
		dbo.PAYS P
		INNER JOIN dbo.SA_MONEY_PERIOD_FN(DEFAULT,DEFAULT) MP ON MP.PAY_LINK = P.LINK
	WHERE
		P.WAY_CALC = 1
		AND
		@dDate between MP.DATE_BEGIN and ISNULL(MP.DATE_END,'20990101')		
	GROUP BY
		MP.EMPL_LINK	

	INSERT INTO @MOVES 
	SELECT IM1.EMPL_LINK, IM1.STAFF_LINK, IM1.NUM_STAKE, IM1.LINK, IM1.STATUS, isnull(o.summa,0), IM1.DATE_BEGIN
	FROM ITEM_MOVE IM1 
		inner join 
		(
		SELECT IM.EMPL_LINK, MAX(IM.LINK) AS LINK
		FROM
			(SELECT 
				EMPL_LINK, MAX(DATE_BEGIN) AS DATE_BEGIN
			FROM dbo.item_move
			WHERE date_begin<=@dDATE and active=1 --and new_face<>2
			GROUP BY EMPL_LINK
			) M
		INNER JOIN ITEM_MOVE IM ON IM.EMPL_LINK=M.EMPL_LINK AND IM.DATE_BEGIN=M.DATE_BEGIN
			and im.active=1 --and im.new_face<>2
		GROUP BY IM.EMPL_LINK
		) M1 on IM1.LINK = M1.LINK
		left join @oklad o on o.empl_link = im1.EMPL_LINK

	DECLARE @STAFF TABLE (LINK_UP INT, DATE_BEGIN DATETIME, LINK INT)
	INSERT INTO @STAFF
	SELECT S.LINK_UP, S.DATE_BEGIN, ST.LINK
	FROM(	
		SELECT LINK_UP, MAX(DATE_BEGIN) AS DATE_BEGIN
		FROM STAFF
		WHERE 
			(DATE_BEGIN<=@dDATE)
			OR
			(@dDate between DATE_BEGIN and ISNULL(DATE_END,'20990101'))
		GROUP BY LINK_UP
	) S, STAFF ST
	WHERE S.LINK_UP = ST.LINK_UP AND S.DATE_BEGIN = ST.DATE_BEGIN

	--INSERT INTO @STAFF 
	--SELECT DISTINCT ST.LINK_UP, ST.DATE_BEGIN, ST.LINK
	--FROM 
	--	dbo.STAFF ST
	--	INNER JOIN 
	--	(	
	--	SELECT LINK_UP, MAX(DATE_BEGIN) AS DATE_BEGIN
	--	FROM dbo.STAFF
	--	GROUP BY LINK_UP
	--	) ST2 ON ST2.LINK_UP = ST.LINK_UP AND ST2.DATE_BEGIN = ST.DATE_BEGIN
	--WHERE NOT EXISTS (SELECT * FROM @STAFF S WHERE S.LINK_UP = ST.LINK_UP)	

	INSERT INTO @MOVES2
	SELECT M.EMPL_LINK, ST.LINK, ST.LINK_UP, M.NUM_STAKE, M.MOVE_LINK, M.STATUS, M.OKLAD, M.DATE_BEGIN
	FROM @STAFF ST, @MOVES M
	WHERE ST.LINK_UP=M.STAFF_LINK

	INSERT INTO @RET
	SELECT M.EMPL_LINK, M.STAFF_LINK, M.STAFF_HEAD, S.SUBDIV_LINK, S.SUBDIV_LINK, S.post_link, M.NUM_STAKE, M.MOVE_LINK, M.STATUS, 
		(SELECT notwork FROM empl WHERE link=m.empl_link), M.OKLAD, S.LINK_KBK, S.KAT_LINK, M.DATE_BEGIN
	FROM @MOVES2 M
	INNER JOIN dbo.staff s ON M.STAFF_LINK = S.LINK
	
	UPDATE @RET SET SUBDIV_LINK = 
	(
		SELECT TOP 1 S.LINK
		FROM SUBDIV S
		WHERE S.LINK_UP = R.SUBDIV_HEAD
			AND S.DATE_BEGIN <= @dDATE
		ORDER BY S.DATE_BEGIN DESC
	) 
	FROM @RET R
	
	RETURN
END


GO


GRANT SELECT ON dbo.[EMPL_STAFF] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_USED_OKPD]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_USED_OKPD]

GO





/*
© Кейсистемс (Keysystems), 2006
*/

CREATE VIEW dbo.BB_USED_OKPD

AS
SELECT  O.*,
		CODE_UM = UM.CODE, 
		NAME_UM = UM.NAME 
FROM dbo.OKPD O
left join dbo.DICTIONARY_DIGIT UM ON UM.LINK = O.UM
where O.USED = 1





GO


GRANT SELECT ON dbo.[BB_USED_OKPD] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_GZ_PLAN_TABLE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_GZ_PLAN_TABLE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE             VIEW [dbo].BB_GZ_PLAN_TABLE
AS
Select T.LINK, T.LINK_UP, T.OKDP, T.OKPD, T.QUANTITY, 
	[ERROR]	     = convert(bit, 0),
	[UM_LINK] = UM.LINK,
	[UM_CODE] = UM.CODE,
	[UM_NAME] = UM.NAME,
	[OKDP_CODE] = O.CODE,
	[OKDP_NAME] = O.NAME,
	[UM1_LINK] = UM1.LINK,
	[UM1_CODE] = UM1.CODE,
	[UM1_NAME] = UM1.NAME,
	[OKPD_CODE] = OP.CODE,
	[OKPD_NAME] = OP.NAME,
	T.SUMMA,
	[SUMMA_FIN] = T.SUMMA_FB + T.SUMMA_FV,
	T.SUMMA_FB,
	T.SUMMA_FV,
	T.INDNUMBER
	
	
from dbo.GZ_PLAN_TABLE T 
left join dbo.OKDP O on O.LINK = T.OKDP
left join dbo.DICTIONARY_DIGIT UM on UM.LINK = O.UM
left join dbo.OKPD OP on OP.LINK = T.OKPD
left join dbo.DICTIONARY_DIGIT UM1 on UM1.LINK = OP.UM








GO


GRANT SELECT ON dbo.[BB_GZ_PLAN_TABLE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_RestOborotForLedgerByPeriod1]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BB_RestOborotForLedgerByPeriod1]

GO

/* --- Возвращает обороты для главной книги, за выбранный период с датами
Бочкарев Е. --- */
CREATE FUNCTION dbo.BB_RestOborotForLedgerByPeriod1(@DateBegin datetime, @DateEnd datetime, @GROUPKBK int = 1)
RETURNS TABLE
AS
RETURN
	SELECT 
		T1.ACCOUNT,
		T1.KBK,
		T1.KAU,
		T1.SGU,
		T1.LEDGER_JOURNAL,
		D_SUMMA	=	SUM (T1.D_SUMMA),
		K_SUMMA	=	SUM (T1.K_SUMMA),
		T1.DEP_LINK
	FROM (
		SELECT 
			[ACCOUNT] = AP.ACCOUNT,
			[KBK]	=	CASE
							WHEN SA.ap_KBK = 1 AND @GROUPKBK = 1 THEN AP.KBK
							ELSE NULL
						END,
			AP.KAU,
			[SGU]	= 	CASE
							WHEN @GROUPKBK = 1 OR @GROUPKBK = 2 THEN AP.SGU
							ELSE NULL
						END,
			[LEDGER_JOURNAL] = XOJ.JURN_LINK,
			[D_SUMMA] = CASE 
							WHEN AP.DB_KR = 1 THEN 0  
							ELSE G2.SUMMA
						END,
			[K_SUMMA] = CASE
							WHEN AP.DB_KR =0 THEN 0  
							ELSE G2.SUMMA
						END,
			[DEP_LINK] = G.DEP
		FROM dbo.G_PROV G
		INNER JOIN dbo.G_PROV1 G1 ON G1.LINK_UP = G.LINK
		INNER JOIN dbo.G_PROV2 G2 ON G2.LINK_UP = G1.LINK
		INNER JOIN dbo.G_PROV_AP AP ON AP.LINK_UP = G2.LINK
		INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = AP.ACCOUNT
		INNER JOIN dbo.AccountsTableWithNoChild () NO_CH ON (NO_CH.LINK = SA.LINK)
		INNER JOIN dbo.XOZ_OPER XO ON (XO.LINK = G2.ECON_OPER)
		INNER JOIN dbo.XOZ_OPER_JURN XOJ ON (XOJ.XOZ_LINK = XO.LINK
			AND XOJ.GK = 1)
		WHERE G.DATE_PROV BETWEEN @DateBegin AND @DateEnd	
		) AS T1
	GROUP BY
		T1.ACCOUNT,
		T1.KBK,
		T1.KAU,
		T1.SGU,
		T1.LEDGER_JOURNAL,
		T1.DEP_LINK

GO


GRANT SELECT ON dbo.[BB_RestOborotForLedgerByPeriod1] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[FINANS_CONTRACT_TABLE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[FINANS_CONTRACT_TABLE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE             VIEW [dbo].FINANS_CONTRACT_TABLE
AS
Select F.LINK, F.LINK_UP, F.VKR, F.EKR, F.OKDP,F.OKPD, F.QUANTITY, F.COST,
--	[RECORD_NO] = convert(NUMERIC(9), F.RECORD_NO),
--	[REC_CH_NO] = convert(NUMERIC(9), F.RECORD_CH_NO),
	[RECORD_NO] = F.RECORD_NO,
	[REC_CH_NO] = F.RECORD_CH_NO,
	[ERROR]	   = convert(bit, 0),
	F.P1, F.P2, F.P3, F.P4, F.P5, F.P6, F.P7, F.P8, F.P9, F.P10, F.P11, F.P12, 
	[VKR_CODE] = VKR.CODE,
	[VKR_NAME] = VKR.NAME,
	[EKR_CODE] = EKR.CODE,
	[EKR_NAME] = EKR.NAME,

	[D_CL_LINK] = F.DOP_CLASSIF,
	[D_CL_CODE] = DC.CODE,
	[D_CL_NAME] = DC.NAME,
	
	[UM_LINK] = UM.LINK,
	[UM_CODE] = UM.CODE,
	[UM_NAME] = UM.NAME,
	[UM1_LINK] = UM1.LINK,
	[UM1_CODE] = UM1.CODE,
	[UM1_NAME] = UM1.NAME,

	[ITOG]     = F.P1 + F.P2 + F.P3 + F.P4 + F.P5 + F.P6 + F.P7 + F.P8 + F.P9 + F.P10 + F.P11 + F.P12,
	[OKDP_CODE] = O.CODE,
	[OKDP_NAME] = O.NAME,
	[OKPD_CODE] = P.CODE,
	[OKPD_NAME] = P.NAME,
	[SUMMA]    = F.SUMMA
	
from FINANSE_CONTRACT F  
left join dbo.KL_KBK VKR 	  on VKR.LINK = F.VKR
left join dbo.KOSGU EKR 	  on EKR.LINK = F.EKR
left join dbo.BD_DOP_CLASSIF DC   on DC.LINK = F.DOP_CLASSIF
left join dbo.OKDP O	  	  on O.LINK = F.OKDP
left join dbo.OKPD p	  	  on p.LINK = F.OKPD
left join dbo.DICTIONARY_DIGIT UM on UM.LINK = O.UM
left join dbo.DICTIONARY_DIGIT UM1 on UM1.LINK = P.UM







GO


GRANT SELECT ON dbo.[FINANS_CONTRACT_TABLE] TO PUBLIC

GO



GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FB_LimitOborotByPeriod]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[FB_LimitOborotByPeriod]
GO

CREATE       FUNCTION FB_LimitOborotByPeriod(@varKSDateBegin datetime, @varKSDateEnd datetime, @varKSAccount int = null)

RETURNS TABLE
AS
RETURN 
SELECT G.DATE_PROV, AP.ACCOUNT, G.DEP AS DEP_LINK, G.ACC AS ACC_LINK,
[D_SUMMA] = CASE WHEN AP.DB_KR = 0 THEN G2.SUMMA ELSE 0 END,
[K_SUMMA] = CASE WHEN AP.DB_KR = 1 THEN G2.SUMMA ELSE 0 END,
KBK	= CASE WHEN SA.ap_KBK = 1 THEN AP.KBK ELSE NULL END,
EKR	= CASE WHEN SA.ap_EKR = 1 THEN AP.EKR ELSE NULL END,
DEP	= CASE WHEN SA.ap_DEP = 1 THEN AP.DEP ELSE NULL END,
SUB	= CASE WHEN SA.ap_SUB = 1 THEN SUB.LINK_UP ELSE NULL END,
EMP	= CASE WHEN SA.ap_EMP = 1 THEN AP.EMP ELSE NULL END,
NOMEN	= CASE WHEN SA.ap_NOMEN  = 1 THEN AP.NOMEN  ELSE NULL END,
INV	= CASE WHEN SA.ap_INV = 1 THEN AP.INV ELSE NULL END,
KAU	= CASE WHEN SA.ap_KAU = 1 THEN AP.KAU ELSE NULL END,
DEP_ACC = CASE WHEN SA.ap_DEP_ACC = 1 THEN AP.DEP_ACC ELSE NULL END,
TMC	= CASE WHEN SA.ap_TMC = 1 THEN AP.TMC ELSE NULL END,
INDATE	= CASE WHEN SA.ap_INDATE = 1 THEN AP.INDATE ELSE NULL END,
AP1	= CASE WHEN SA.ap_AP1 = 1 THEN AP.AP1 ELSE NULL END,
AP2	= CASE WHEN SA.ap_AP2 = 1 THEN AP.AP2 ELSE NULL END,
AP3	= CASE WHEN SA.ap_AP3 = 1 THEN AP.AP3 ELSE NULL END,
SGU	= AP.SGU,
LINK_UP = G.LINK
FROM dbo.G_PROV G
INNER JOIN dbo.G_PROV1 G1 ON G1.LINK_UP = G.LINK
INNER JOIN dbo.G_PROV2 G2 ON G2.LINK_UP = G1.LINK
INNER JOIN dbo.G_PROV_AP AP ON AP.LINK_UP = G2.LINK 
	AND (((AP.INDATE IS NULL or AP.INDATE < = G.DATE_PROV) AND (G.DATE_PROV BETWEEN @varKSDateBegin AND @varKSDateEnd)) 
	OR (AP.INDATE IS NOT NULL and AP.INDATE > G.DATE_PROV AND (AP.INDATE BETWEEN @varKSDateBegin AND @varKSDateEnd))) 
INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = AP.ACCOUNT
LEFT JOIN dbo.SUBDIV SUB ON SUB.LINK = AP.SUB
LEFT JOIN dbo.KOSGU SGU ON AP.SGU = SGU.LINK
WHERE ((SA.LINK IN (select LINK FROM dbo.AccountsSubtreeByRoot(@varKSAccount)) AND @varKSAccount IS NOT NULL)
OR (SA.LINK IN (select LINK FROM dbo.AccountsTableWithNoChild()) AND @varKSAccount IS NULL)) and G.DATE_PROV is not null

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_GZ_REESTR_TABLE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_GZ_REESTR_TABLE]

GO


CREATE           VIEW dbo.BB_GZ_REESTR_TABLE
AS
SELECT	-- ТАБЛИЦА
	GZT.LINK,
	GZT.LINK_UP,
	GZT.NOMENCLATURE,
	NOMEN_CODE 	= N.CODE,
	NOMEN_NAME 	= N.NAME,
	N.UM,
	N_COST		= GZT.COST,
	N_QUANTITY	= GZT.QUANTITY,
	SUMMA		= GZT.SUMMA,
	N_UM_NAME	= UM.NAME,
	OKDP 		= OKDP.LINK,
	OKDP_CODE 	= OKDP.CODE,
	OKDP_NAME 	= OKDP.NAME,
	OKDP_COST	= (CASE WHEN OKDP.LINK IS NOT null then 
							 cast((case when N.COEFF = 0 then 0 else GZT.COST / N.COEFF end) as numeric(19,4))
						ELSE null
						END ),
	OKDP_QUANTITY	= (CASE WHEN OKDP.LINK IS NOT null then 
					  		cast(GZT.QUANTITY  * N.COEFF as numeric(19,4))						
					   	ELSE null
						END ),
	OKDP_SUMMA	=		(CASE WHEN OKDP.LINK IS NOT null then 
									GZT.SUMMA * N.COEFF					   	
						 ELSE null
						END ),
	OKDP_UM_NAME	= (CASE WHEN OKDP.LINK IS NOT null then  UM1.NAME ELSE '' END) ,
	N.COEFF,
	OKPD 		= OKPD.LINK,
	OKPD_CODE 	= OKPD.CODE,
	OKPD_NAME 	= OKPD.NAME,
	OKPD_COST	= (CASE WHEN OKPD.LINK IS NOT null then  
						cast((case when N.COEFF_OKPD = 0 then 0 else GZT.COST / N.COEFF_OKPD end) as numeric(19,4))
						ELSE NULL END) ,
	OKPD_QUANTITY	= (CASE WHEN OKPD.LINK IS NOT null then
						cast(GZT.QUANTITY  * N.COEFF_OKPD as numeric(19,4))
						ELSE NULL END) ,
	OKPD_SUMMA	= (CASE WHEN OKPD.LINK IS NOT null then 
						GZT.SUMMA * N.COEFF_OKPD
					ELSE NULL END) ,
	OKPD_UM_NAME	= (CASE WHEN OKPD.LINK IS NOT null then 
						UM11.NAME 
						ELSE NULL END) ,
	GZT.TYPE,
	[TYPE_NAME]	= case GZT.TYPE when 1 then 'Оплата' when 2 then 'Поставка' end,  	
	N.COEFF_OKPD


from		dbo.GZ_REESTR_DOP GZT
inner join	dbo.NOMENCLATURE N on N.LINK = GZT.NOMENCLATURE
left join 	dbo.DICTIONARY_DIGIT UM on N.UM = UM.LINK 
left join 	dbo.OKDP on N.LINK_OKDP = OKDP.LINK 
left join 	dbo.DICTIONARY_DIGIT UM1 on OKDP.UM = UM1.LINK 
left join 	dbo.OKPD on N.LINK_OKPD = OKPD.LINK 
left join 	dbo.DICTIONARY_DIGIT UM11 on OKPD.UM = UM11.LINK 















GO


GRANT SELECT ON dbo.[BB_GZ_REESTR_TABLE] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RT_VIEW_DEPDICT_125]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[RT_VIEW_DEPDICT_125]

GO

/*******************************************************************************

	© Кейсистемс (Keysystems), 2007

*******************************************************************************/

CREATE VIEW dbo.[RT_VIEW_DEPDICT_125]
AS
select 
	dp.link as link,
	dp.code,
	sh_name =ISNULL(DH.[NAME], dp.NAME), 
	name = ISNULL(DH.[FULL_NAME], dp.[FULL_NAME]), 
	isnull(kbs.code,'') as ppp,
	isnull( cast(replace(dp.okato,' ','') as varchar(11/*хотя, по идее ОКАТО 11 символов*/)),'') as okato, 
	isnull( cast(replace(dp.oktmo,' ','') as varchar(11/*хотя, по идее ОКАТО 11 символов*/)),'') as oktmo, 
	ISNULL( cast(replace(dp.INN,' ','') as varchar(12)),'') as INN,
	coalesce((
		select coalesce(kbt.code_el,'') 
		from kl_budg_type as kbt 
		where kbt.link = (
			select kab.link_budg 
			from kl_admin_bs as kab 
			where kab.link = dp.ved_link)
		),'') as code_el,
	right('0000000000' + cast(isnull(dp.link,'0') as varchar(10)),8) as UCS,
   isnull(DH.[DATE_BEGIN], '19000101') [DATE_BEGIN],
   isnull(DH.[DATE_END], '30000101') [DATE_END] 
	from dbo.Departments as dp 
	left join dbo.kl_admin_bs as kbs on dp.ved_link = kbs.link
   left JOIN dbo.DICTIONARY_DEPARTMENT_HIST DH ON DH.[LINK_UP] = DP.[LINK]
	where dp.link in (select convert(int, code) from dbo.report_kbk where code_form = 'RT_VIEW_DEPDICT_125' and isnumeric(code) = 1)
union 
select 
	dp.link as link,
	dp.code,
	sh_name = dp.NAME, 
	name = dp.[FULL_NAME], 
	isnull(kbs.code,'') as ppp,
	isnull( cast(replace(dp.okato,' ','') as varchar(11/*хотя, по идее ОКАТО 11 символов*/)),'') as okato, 
	isnull( cast(replace(dp.oktmo,' ','') as varchar(11/*хотя, по идее ОКАТО 11 символов*/)),'') as oktmo, 
	ISNULL(cast(replace(dp.INN,' ','') as varchar(12)),'') as INN,
	coalesce((
		select coalesce(kbt.code_el,'') 
		from kl_budg_type as kbt 
		where kbt.link = (
			select kab.link_budg 
			from kl_admin_bs as kab 
			where kab.link = dp.ved_link)
		),'') as code_el,
	right('0000000000' + cast(isnull(dp.link,'0') as varchar(10)),8) as UCS,
  '19000101',
   isnull(DH.[DATE_BegiN]-1,'30000101') 
	from dbo.Departments as dp 
	left join dbo.kl_admin_bs as kbs on dp.ved_link = kbs.link
   left JOIN (select min(date_begin) date_begin, link_up from dbo.DICTIONARY_DEPARTMENT_HIST GROUP BY link_up) DH ON DH.[LINK_UP] = DP.[LINK]
	where dp.link in (select convert(int, code) from dbo.report_kbk where code_form = 'RT_VIEW_DEPDICT_125' and isnumeric(code) = 1)
union
select -1 as link,'Итого' as code, 'Итого' as sh_name,'Итого' as name, '' as ppp,'99999999999' as okato, '99999999999' as oktmo,'999999999999' as inn, '' , '', '19000101', '30000101'



GO


GRANT SELECT ON dbo.[RT_VIEW_DEPDICT_125] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_OKDP]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_OKDP]

GO

CREATE VIEW dbo.BB_OKDP

AS
/*SELECT  LINK,
	CODE, 
	NAME,
	LINK_SELF
FROM dbo.OKDP*/
select T.*, 
	CODE_UM = UM.CODE, 
	NAME_UM = UM.NAME, 
	0 as UPD,
	0 as CHECKED, 
	0 as DEL, 
	IMAGEINDEX = cast(case CHILDRENS when 0 then 'FOLDER' else 'NAIM' end as varchar(10))
from (
		select 
			[O].LINK, 
	  		[O].USED,
			LINK_SELF = isnull([O].LINK_SELF, 0),
	  		[O].CODE,
	  		CODE_SELF = (select isnull(OKDP1.CODE,'') FROM dbo.OKDP OKDP1 where OKDP1.LINK = [O].LINK_SELF),	  	
			[NAME_TABLE] = [O].[NAME],
	  		[NAME] = convert(varchar(254),RTRIM([O].CODE) + ' ' + RTRIM([O].[NAME])),
	  		[CHILDRENS] =	CASE  	when EXISTS(select * from dbo.OKDP OKDP2 where OKDP2.LINK_SELF = [O].LINK) 
		                   		then CONVERT(bit,0)
		             			else CONVERT(bit,1)
		                	end,
			[UM]
		from 
			dbo.OKDP [O]
	) T
left join dbo.DICTIONARY_DIGIT UM ON UM.LINK = T.UM

GO


GRANT SELECT ON dbo.[BB_OKDP] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_OKPD]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_OKPD]
GO

CREATE VIEW dbo.BB_OKPD

AS
/*SELECT  LINK,
	CODE, 
	NAME,
	LINK_SELF
FROM dbo.OKDP*/
select T.*, 
	CODE_UM = UM.CODE, 
	NAME_UM = UM.NAME, 
	0 as UPD,
	0 as CHECKED, 
	0 as DEL, 
	IMAGEINDEX = cast(case when CHILDRENS = 0 then 'FOLDER' else 'NAIM' end as varchar(10))
from 
	(
		select 
			[O].LINK, 
	  		[O].USED,
			LINK_SELF 	= isnull([O].LINK_SELF, 0),
	  		[O].CODE,
	  		CODE_SELF 	= (select isnull(OKPD1.CODE,'') FROM dbo.OKPD OKPD1 where OKPD1.LINK = [O].LINK_SELF),	  	
			[NAME_TABLE] 	= [O].[NAME],
	  		[NAME]    	= convert(varchar(254),RTRIM([O].CODE) + ' ' + RTRIM([O].[NAME])),
	  		[CHILDRENS] 	=	CASE when EXISTS(select * from dbo.OKPD where LINK_SELF = [O].LINK) 
		                   			then CONVERT(bit,0)
		             				else CONVERT(bit,1)
		                		end,
			[UM]
		from 
			dbo.OKPD [O]
	) T
left join dbo.DICTIONARY_DIGIT UM ON UM.LINK = T.UM

GO

GRANT SELECT ON dbo.[BB_OKPD] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[FT_ALL_SA_NASTR_DOC]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[FT_ALL_SA_NASTR_DOC]

GO
CREATE FUNCTION dbo.FT_ALL_SA_NASTR_DOC
	(
	@LINK_UP	INT,
	@DB_KR	TINYINT	= 255
	)
RETURNS TABLE
AS
RETURN
	SELECT 
		T2.LINK
	FROM dbo.FT_DOC_NASTR_SA (@LINK_UP, @DB_KR)	T1
	CROSS APPLY dbo.AccountsFullSubtreeByRoot (T1.ACCOUNT) T2
	WHERE @DB_KR = 255
		OR T1.DB_KR = @DB_KR 
	GROUP BY
		T2.LINK

GO

GRANT SELECT ON dbo.[FT_ALL_SA_NASTR_DOC] TO PUBLIC

GO

--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BA_SELECT_MP_CHARGE_TABLE]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BA_SELECT_MP_CHARGE_TABLE]

GO

/*******************************************************************************

	© Кейсистемс (Keysystems), 2006

*******************************************************************************/
-- Функция выборки МЦ (табличной части в режиме "Списание мягкого и хоз. инвентаря.").
CREATE FUNCTION dbo.BA_SELECT_MP_CHARGE_TABLE
	(
   @iDOC_LINK INT = NULL -- Ссылка на документ.
	)
RETURNS TABLE
AS
	RETURN	
		SELECT
			LINK	=	OTR.LINK,
			LINK_UP	=	OTR.LINK_UP,
			[OBJECT]	=	OTR.[OBJECT],
			ORDERS	=	OTR.ORDERS,
			INV_TYPE	=	ISNULL (OT_INVT.INV_TYPE, ''),
			INV_LINK	=	CASE
								WHEN OT_INVT.INV_TYPE = 'BV_NOMENCLATURE' THEN OT_INVT.NOMEN
								WHEN OT_INVT.INV_TYPE = 'INVENTORY_CARD' THEN OT_INVT.INV
							END,	
			INV_CODE	=	CASE
								WHEN OT_INVT.INV_TYPE = 'BV_NOMENCLATURE' THEN NOMEN.CODE
								WHEN OT_INVT.INV_TYPE = 'INVENTORY_CARD' THEN INV.CODE
							END,	
			INV_NAME	=	CASE
								WHEN OT_INVT.INV_TYPE = 'BV_NOMENCLATURE' THEN NOMEN.NAME
								WHEN OT_INVT.INV_TYPE = 'INVENTORY_CARD' THEN INV.NAME
							END,	
			UM_NAME	=	UM.[NAME],
			QTY		=	OT_MZC.QTY,
			REST	=	OT_MZC.QTY_REST,
			PRICE	=	OT_MZC.PRICE,
			SUMMA	=	OT_MZC.SUMMA,
			SUM_REST	=	OT_MZC.SUM_REST,
			ACCOUNT	=	OT_MZC.ACCOUNT,
			ACCT_CODE	=	SA.CODE
		FROM dbo.OUT_TABLE_ROW OTR
		LEFT JOIN dbo.OUT_TABLE_INV_TYPE OT_INVT ON (OT_INVT.LINK_UP = OTR.LINK) 
		LEFT JOIN dbo.INVENTORY INV ON (OT_INVT.INV_TYPE = 'INVENTORY_CARD'
			AND INV.LINK = OT_INVT.INV) 
		LEFT JOIN dbo.NOMENCLATURE NOMEN ON (OT_INVT.INV_TYPE = 'BV_NOMENCLATURE' AND NOMEN.LINK = OT_INVT.NOMEN
			OR OT_INVT.INV_TYPE = 'INVENTORY_CARD' AND NOMEN.LINK = INV.NOMENCLATURE)
		LEFT JOIN dbo.DICTION UM ON (UM.LINK = NOMEN.UM)
		LEFT JOIN dbo.OUT_TABLE_MZ_CHARGE OT_MZC ON (OT_MZC.LINK_UP = OTR.LINK)
		LEFT JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = OT_MZC.ACCOUNT)
		WHERE
			OTR.[OBJECT] = dbo.XA_GET_SO_LINK ('BA_DOC_MP_CHARGE_TABLE')
			AND (@iDOC_LINK IS NULL OR OTR.LINK_UP = @iDOC_LINK)
	
			

GO


GRANT SELECT ON dbo.[BA_SELECT_MP_CHARGE_TABLE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_GZ_DOC_TABLE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_GZ_DOC_TABLE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE             VIEW [dbo].BB_GZ_DOC_TABLE
AS
Select F.LINK, F.LINK_UP, F.KBK, F.EKR, F.DOP_CL, F.OKDP, F.OKPD, F.QUANTITY, F.COST,
	RECORD_NO    = convert(NUMERIC(9), F.RECORD_NO),
	[ERROR]	     = convert(bit, 0),
	KBK_CODE     = KBK.CODE,
	KBK_NAME     = KBK.NAME,
	EKR_CODE     = EKR.CODE,
	EKR_NAME     = EKR.NAME,
	DOP_CL_CODE  = DC.CODE,
	DOP_CL_NAME  = DC.NAME,
	[UM_LINK] = UM.LINK,
	[UM_CODE] = UM.CODE,
	[UM_NAME] = UM.NAME,
	[OKDP_CODE] = O.CODE,
	[OKDP_NAME] = O.NAME,
	[UM1_LINK] = UM1.LINK,
	[UM1_CODE] = UM1.CODE,
	[UM1_NAME] = UM1.NAME,
	[OKPD_CODE] = OP.CODE,
	[OKPD_NAME] = OP.NAME,
	[SUMMA]      = cast((case when F.SUMMA <> 0 then F.SUMMA else F.QUANTITY * F.COST end) as NUMERIC(19,2))
	
from dbo.GZ_DOC_TABLE F  
left join dbo.KL_KBK KBK     on KBK.LINK = F.KBK
left join dbo.KOSGU EKR      on EKR.LINK = F.EKR
left join dbo.DOP_CLASSIF DC on DC.LINK = F.DOP_CL
left join dbo.OKDP O 	     on O.LINK = F.OKDP
left join dbo.DICTIONARY_DIGIT UM on UM.LINK = O.UM
left join dbo.OKPD OP 	     on OP.LINK = F.OKPD
left join dbo.DICTIONARY_DIGIT UM1 on UM1.LINK = OP.UM









GO


GRANT SELECT ON dbo.[BB_GZ_DOC_TABLE] TO PUBLIC

GO



GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FB_FINANS_POLUCH_DOC]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[FB_FINANS_POLUCH_DOC]
GO

CREATE FUNCTION dbo.FB_FINANS_POLUCH_DOC(@varKSintFyear int, 
					@varKSdDateB datetime, 
					@varKSdDateE datetime, 
					@varKSintPer_num int, 
					@varKSintSumType numeric (5, 3), 
					@varKSFinObjCode char(100), 
					@varKSintTypePer int = 1)
-- за год @varKSintTypePer = 1 - за год,
--			   = 2 - по кварталам,
--			   = 3 - по месяцам
-- за период = + 10		  
RETURNS @varKSResTable TABLE
	(link_doc	int,
	 dep	[int] NULL,
	 vkr	[int] NULL,
	 ekr	[int] NULL, 
	 dop_cl	[int] NULL, 
	 P1	[numeric](28, 2) NULL,
	 P2	[numeric](28, 2) NULL,
	 P3	[numeric](28, 2) NULL,
	 P4	[numeric](28, 2) NULL,
	 P5	[numeric](28, 2) NULL,
	 P6	[numeric](28, 2) NULL,
	 P7	[numeric](28, 2) NULL,
	 P8	[numeric](28, 2) NULL,
	 P9	[numeric](28, 2) NULL,
	 P10	[numeric](28, 2) NULL,
	 P11	[numeric](28, 2) NULL,
	 P12	[numeric](28, 2) NULL)

AS
BEGIN
DECLARE @varKSAccount int,
	@varKSFinObj int,
	@varKSdEndDate1 datetime,
	@varKSdEndDate2 datetime,
	@varKSdEndDate3 datetime,
	@varKSdEndDate4 datetime,
	@varKSdEndDate5 datetime,
	@varKSdEndDate6 datetime,
	@varKSdEndDate7 datetime,
	@varKSdEndDate8 datetime,
	@varKSdEndDate9 datetime,
	@varKSdEndDate10 datetime,
	@varKSdEndDate11 datetime,
	@varKSdEndDate12 datetime,
	@varKSdBegDate1 datetime,
	@varKSdBegDate2 datetime,
	@varKSdBegDate3 datetime,
	@varKSdBegDate4 datetime,
	@varKSdBegDate5 datetime,
	@varKSdBegDate6 datetime,
	@varKSdBegDate7 datetime,
	@varKSdBegDate8 datetime,
	@varKSdBegDate9 datetime,
	@varKSdBegDate10 datetime,
	@varKSdBegDate11 datetime,
	@varKSdBegDate12 datetime,
	@varKSdDateEndP	 datetime,
	@varKSdDateBegP	 datetime,
	@varKSiOwnDep	 int

DECLARE @varKSTempTable TABLE 
	(link_doc [int] NULL,
	 dep	[int] NULL,
	 vkr	[int] NULL,
	 ekr	[int] NULL, 
	 dop_cl	[int] NULL, 
	 P1	[numeric](28, 2) NULL,
	 P2	[numeric](28, 2) NULL,
	 P3	[numeric](28, 2) NULL,
	 P4	[numeric](28, 2) NULL,
	 P5	[numeric](28, 2) NULL,
	 P6	[numeric](28, 2) NULL,
	 P7	[numeric](28, 2) NULL,
	 P8	[numeric](28, 2) NULL,
	 P9	[numeric](28, 2) NULL,
	 P10	[numeric](28, 2) NULL,
	 P11	[numeric](28, 2) NULL,
	 P12	[numeric](28, 2) NULL)

DECLARE @tOborot TABLE 
	(LINK_DOC	int,
	 DATE_PROV	datetime null,
	 DEP	 	[int] NULL,
	 INDATE 	datetime null,
	 VKR	[int] NULL,
	 EKR	[int] NULL, 
	 DOP_CL	[int] NULL, 
	 SUMMA	[numeric](19, 2) NULL)


set @varKSiOwnDep = isnull (dbo.BK_GetDepZB (), dbo.GetOwnDepLink())
set @varKSdBegDate1 = convert(datetime,convert(char(4),@varKSintFyear) + '0101')
SET @varKSdBegDate2 =  convert(datetime,convert(char(4),@varKSintFyear) + '0201')
SET @varKSdBegDate3 =  convert(datetime,convert(char(4),@varKSintFyear) + '0301')
SET @varKSdBegDate4 =  convert(datetime,convert(char(4),@varKSintFyear) + '0401')
SET @varKSdBegDate5 =  convert(datetime,convert(char(4),@varKSintFyear) + '0501')
SET @varKSdBegDate6 =  convert(datetime,convert(char(4),@varKSintFyear) + '0601')
SET @varKSdBegDate7 =  convert(datetime,convert(char(4),@varKSintFyear) + '0701')
SET @varKSdBegDate8 =  convert(datetime,convert(char(4),@varKSintFyear) + '0801')
SET @varKSdBegDate9 =  convert(datetime,convert(char(4),@varKSintFyear) + '0901')
SET @varKSdBegDate10 =  convert(datetime,convert(char(4),@varKSintFyear) + '1001')
SET @varKSdBegDate11 =  convert(datetime,convert(char(4),@varKSintFyear) + '1101')
SET @varKSdBegDate12 =  convert(datetime,convert(char(4),@varKSintFyear) + '1201')
SET @varKSdEndDate1 = @varKSdBegDate2 - 1
SET @varKSdEndDate2 = @varKSdBegDate3 - 1
SET @varKSdEndDate3 = @varKSdBegDate4 - 1
SET @varKSdEndDate4 = @varKSdBegDate5 - 1
SET @varKSdEndDate5 = @varKSdBegDate6 - 1
SET @varKSdEndDate6 = @varKSdBegDate7 - 1
SET @varKSdEndDate7 = @varKSdBegDate8 - 1
SET @varKSdEndDate8 = @varKSdBegDate9 - 1
SET @varKSdEndDate9 = @varKSdBegDate10 - 1
SET @varKSdEndDate10 = @varKSdBegDate11 - 1
SET @varKSdEndDate11 = @varKSdBegDate12 - 1
SET @varKSdEndDate12 = convert(datetime,convert(char(4),@varKSintFyear + 1)+'0101') - 1

if @varKSdDateB is null 
	set @varKSdDateB = @varKSdBegDate1

select @varKSintPer_num  = (case @varKSintTypePer
				when 13 then @varKSintPer_num				
				when 12 then (case when @varKSintPer_num < 4 then 1
						when @varKSintPer_num < 7 then 4
						when @varKSintPer_num < 10 then 7
						else 10 end)
				when 11 then 1
				else 0 end)
					

IF @varKSintTypePer < 12 or @varKSintPer_num = 0
begin
	set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
	set @varKSdDateBegP= convert(datetime,convert(char(4),@varKSintFyear) + '0101')
end
else 
begin
	if @varKSintTypePer = 12
	BEGIN
		if @varKSintPer_num = 10
		begin
			set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '1001'))		
		end
		else
		begin
			if @varKSintPer_num = 7
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + convert(char(2),@varKSintPer_num + 3) + '01') - 1
			else 
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0' + convert(char(1),@varKSintPer_num + 3) + '01') - 1
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '0' + convert(char(1),@varKSintPer_num) + '01'))
		end
	END 
	else 
	BEGIN
		if @varKSintPer_num = 12
			set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
		else 		
			if @varKSintPer_num > 8
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + convert(char(2),@varKSintPer_num + 1) + '01') - 1
			else 
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0' + convert(char(1),@varKSintPer_num + 1) + '01') - 1
		if @varKSintPer_num < 10
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '0' + convert(char(1),@varKSintPer_num) + '01'))
		else 		
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + convert(char(2),@varKSintPer_num) + '01'))

	END
end   

-- дата расчета не должна выходить за пределы периода
if @varKSdDateE is null or @varKSdDateE > @varKSdDateEndP
	set @varKSdDateE = @varKSdDateEndP

SELECT @varKSAccount = link 
FROM s_accounts 
WHERE (cSinth = '501' and @varKSFinObjCode like '%_LIMIT%' or cSinth = '503' and @varKSFinObjCode like '%_ASSIGN%') and cAnalit = '14' and cSource = '1'  
	

INSERT INTO @tOborot (LINK_DOC, DATE_PROV, DEP, INDATE, VKR, EKR,DOP_CL, SUMMA)
SELECT LINK_UP, DATE_PROV,DEP, INDATE, KBK AS VKR, EKR, AP2 AS DOP_CL, isnull(k_summa,0)
from FB_LimitOborotByPeriod(@varKSdDateBegP,@varKSdDateEndP, @varKSAccount)
where DEP_LINK = @varKSiOwnDep and 
	not DATE_PROV  < @varKSdDateB and
	not DATE_PROV  > @varKSdDateE

SELECT @varKSAccount = link 
FROM s_accounts 
WHERE (cSinth = '501' and @varKSFinObjCode like '%_LIMIT%' or cSinth = '503' and @varKSFinObjCode like '%_ASSIGN%') and cAnalit = '13' and cSource = '1'  
	

INSERT INTO @tOborot (LINK_DOC, DATE_PROV, DEP, INDATE, VKR, EKR,DOP_CL, SUMMA)
SELECT LINK_UP, DATE_PROV,DEP_LINK, INDATE, KBK AS VKR, EKR, AP2 AS DOP_CL, isnull(k_summa,0)
from FB_LimitOborotByPeriod(@varKSdDateBegP,@varKSdDateEndP, @varKSAccount)
where DEP_LINK = @varKSiOwnDep and 
	not DATE_PROV  < @varKSdDateB and
	not DATE_PROV  > @varKSdDateE

INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, summa,0,0,0,0,0,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate1 and @varKSdEndDate1) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate1 and @varKSdEndDate1))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0, summa,0,0,0,0,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate2 and @varKSdEndDate2) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate2 and @varKSdEndDate2))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,summa,0,0,0,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate3 and @varKSdEndDate3) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate3 and @varKSdEndDate3))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,summa,0,0,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate4 and @varKSdEndDate4) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate4 and @varKSdEndDate4))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL,0,0,0,0,summa,0,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate5 and @varKSdEndDate5) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate5 and @varKSdEndDate5))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,summa,0,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate6 and @varKSdEndDate6) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate6 and @varKSdEndDate6))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,0,summa,0,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate7 and @varKSdEndDate7) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate7 and @varKSdEndDate7))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,0,0,summa,0,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate8 and @varKSdEndDate8) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate8 and @varKSdEndDate8))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,0,0,0,summa,0,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate9 and @varKSdEndDate9) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate9 and @varKSdEndDate9))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,0,0,0,0,summa,0,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate10 and @varKSdEndDate10) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate10 and @varKSdEndDate10))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL, 0,0,0,0,0,0,0,0,0,0,summa,0
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate11 and @varKSdEndDate11) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate11 and @varKSdEndDate11))
INSERT INTO @varKSTempTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT LINK_DOC, DEP, VKR, EKR, DOP_CL,0,0,0,0,0,0,0,0,0,0,0,summa
from @tOborot
where ((not INDATE is null and INDATE between @varKSdBegDate12 and @varKSdEndDate12) 
	or (INDATE is null and DATE_PROV between @varKSdBegDate12 and @varKSdEndDate12))
					
		
INSERT INTO @varKSresTable(LINK_DOC, DEP, VKR, EKR, DOP_CL, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
SELECT F.LINK_DOC, F.DEP, F.VKR, F.EKR, F.DOP_CL,  
sum(F.p1) * @varKSintSumType as p1,
sum(F.p2) * @varKSintSumType as p2, 
sum(F.p3) * @varKSintSumType as p3, 
sum(F.p4) * @varKSintSumType as p4, 
sum(F.p5) * @varKSintSumType as p5, 
sum(F.p6) * @varKSintSumType as p6, 
sum(F.p7) * @varKSintSumType as p7, 
sum(F.p8) * @varKSintSumType as p8, 
sum(F.p9) * @varKSintSumType as p9, 
sum(F.p10) * @varKSintSumType as p10, 
sum(F.p11) * @varKSintSumType as p11, 
sum(F.p12) * @varKSintSumType as p12
from @varKSTempTable F 
group by LINK_DOC, DEP, VKR, EKR, DOP_CL


RETURN
END
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[CHANGE_PERIOD_VAC]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[CHANGE_PERIOD_VAC]

GO

CREATE VIEW [dbo].[CHANGE_PERIOD_VAC]  AS 
SELECT 	VPC.LINK,
		E.DEP_LINK,
		dep.NAME as name_dep,
		VPC.LINK_EMPL,
		[TAB_NUM] = E.TAB,
		[NAME_EMPL] = dbo.sd_GetEmplName(VPC.LINK_EMPL),
		VPC.DATE1,
		VPC.DATE2,
		VPC.YEAR1,
		VPC.YEAR2,
		VPC.COMMENT
FROM dbo.VAC_PERIOD_CHANGE VPC INNER JOIN dbo.EMPL E ON E.LINK = VPC.LINK_EMPL
	inner JOIN dbo.DEPARTMENTS dep on dep.link = e.DEP_LINK

GO


GRANT SELECT ON dbo.[CHANGE_PERIOD_VAC] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[KU_EMPL_PLACING_FN]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[KU_EMPL_PLACING_FN]

GO

/*
© Кейсистемс (Keysystems), 2005
ВОЗВРАЩАЕТ СПИСОК ВСЕХ СОТРУДНИКОВ НА ДАТУ, ВКЛЮЧАЯ УВОЛЕННЫХ
УВОЛЕННЫЕ ФИКСИРУЮТСЯ ПОЛЕМ "SACK"
*/

CREATE   FUNCTION dbo.KU_EMPL_PLACING_FN(@dDATE datetime = null)
RETURNS @RESULT TABLE
		( [LINK] INT,
		[PERS_LINK]	INT,
		[DEP_LINK] INT,
		[DEP_NAME] VARCHAR(254),
		[TAB] VARCHAR(10),
		[FM] VARCHAR(100),
		[IM] VARCHAR(100),
		[OT] VARCHAR(100),
		[FIO] VARCHAR(100),
		[NAME_EMPL] VARCHAR(100),
		[SUBDIV_HEAD] INT,
		[SUBDIV_LINK] INT,
		[SUBDIV_CODE] VARCHAR(5),
		[SUBDIV_NAME] VARCHAR(254),
		[POST_LINK] INT,
		[POST_CODE] VARCHAR(10),
		[POST_NAME] VARCHAR(254),
		[STAFF_HEAD] INT,
		[STAFF_LINK] INT,
		[NUM_STAKE] NUMERIC(3,2),
		[STATUS] INT,
		[STATUS_NAME] VARCHAR(60),
		[NOTWORK] tinyint,
		[DATE_BEGIN] DATETIME,
		[DATE_MOV] DATETIME,
		[OKLAD] NUMERIC(10,2),
		[GRAPH_LINK] INT,
		[GRAPH_NAME] VARCHAR(60),
		[DATE_SACK]	DATETIME,
		[ITEM_MOVE_LINK] INT,
		[VIS] BIT,
		[LINK_KBK] INT,
		[CODE_KBK] VARCHAR(20),
		[NAME_KBK] VARCHAR(120),
		[RAZR] TINYINT,
		[SYST_PAY] TINYINT,
		[POST_GROUP] VARCHAR(60),
		KATEG VARCHAR(50),
		[CHIN] VARCHAR(150),
		[CHIN_DATE] DATETIME,
		[EMAIL] VARCHAR(254),
		[PHONE_WORK] VARCHAR(254),
		[PHONE_MOB] VARCHAR(254),
		[INN] VARCHAR(12),
		[SNILS] VARCHAR(14),
		[RESIDENT]	tinyint,
		[RESIDENT_N] VARCHAR(34),
		[SACK] INT,
		[SACK_PER] INT) 
AS
BEGIN
SET @dDATE = Isnull(@dDATE,(SELECT workdate FROM user_dates))

-- Сведения о чине --------------------------------------------------------------------------------------
DECLARE @CHIN_EMPL TABLE(EMPL_LINK INT, CHIN_CODE VARCHAR(2), CHIN_NAME VARCHAR(150), CHIN_DATE DATETIME)
---------------------------------------------------------------------------------------------------------
INSERT INTO @CHIN_EMPL (EMPL_LINK, CHIN_CODE, CHIN_NAME, CHIN_DATE)
SELECT EMPL_LINK, CODE, [NAME], DATE
FROM  dbo.EMPL_CHIN ch1 inner join dbo.DICTIONARY_CHIN dh ON  ch1.chin_link = dh.link
WHERE  ch1.[DATE] = 
				(SELECT TOP 1 C.DATE 
				 FROM dbo.EMPL_CHIN C 
				 WHERE C.EMPL_LINK = ch1.EMPL_LINK AND C.DATE <= @dDATE 
				 ORDER BY DATE DESC)	

-- Сведения о текушей должности -------------------------------------------------------------------------
DECLARE @POST_EMPL TABLE(EMPL_LINK INT,STAFF_HEAD INT,STAFF_LINK INT, NUM_STAKE NUMERIC(3,2), [STATUS] INT, OKLAD NUMERIC(10,2),
						 MOVE_LINK INT, LINK_KBK INT, POST_LINK INT, SUBDIV_LINK INT, DATE_BEG DATETIME)
---------------------------------------------------------------------------------------------------------
INSERT INTO @POST_EMPL (EMPL_LINK, STAFF_HEAD, STAFF_LINK, NUM_STAKE, [STATUS], OKLAD, MOVE_LINK, LINK_KBK,POST_LINK,SUBDIV_LINK, DATE_BEG)
SELECT A.EMPL_LINK, A.STAFF_HEAD, A.STAFF_LINK, A.NUM_STAKE, A.[STATUS], A.OKLAD, A.MOVE_LINK, A.LINK_KBK,A.POST_LINK,A.SUBDIV_LINK, A.DATE_BEGIN
FROM dbo.EMPL_STAFF(@dDATE) A

-- Сведения об увольнении -------------------------------------------------------------------------------
DECLARE @ITEM_DIS_FACE TABLE(EMPL_LINK int, DIS_DATE DATETIME)
---------------------------------------------------------------------------------------------------------
INSERT INTO @ITEM_DIS_FACE (EMPL_LINK,DIS_DATE)
SELECT empl_link, dis_date 
FROM dbo.item_dis_face IDF
WHERE dis_date =
	(SELECT TOP 1 dis_date 
	 FROM dbo.item_dis_face IDF1 
	 WHERE IDF1.EMPL_LINK = IDF.EMPL_LINK AND active =1 AND dis_date <=@dDATE 
	 ORDER BY dis_date desc)

-- Сведения о телефонах, эл.адресах сотрудников ---------------------------------------------------------
DECLARE @PHONE_MAIL_EMPL TABLE(EMPL_LINK INT, [EMAIL] VARCHAR(254), [PHONE_WORK] VARCHAR(254), [PHONE_MOB] VARCHAR(254))
---------------------------------------------------------------------------------------------------------
INSERT INTO @PHONE_MAIL_EMPL(EMPL_LINK, [EMAIL], [PHONE_WORK],[PHONE_MOB])
SELECT EMPL_LINK, EMAIL, CITY_NUMBER, MOB_NUMBER FROM dbo.EMPL_PHONE_STR

-- Заполнение результирующей таблицы --------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
INSERT INTO @RESULT([LINK],
		[PERS_LINK],		[DEP_LINK],		[DEP_NAME],
		[TAB],		[FM],	[IM],	[OT],	[FIO],
		[NAME_EMPL],		[SUBDIV_HEAD],	[SUBDIV_LINK],
		[SUBDIV_CODE],		[SUBDIV_NAME],	[POST_LINK],
		[POST_CODE],		[POST_NAME],	[STAFF_HEAD],
		[STAFF_LINK],		[NUM_STAKE],	[STATUS],
		[STATUS_NAME],		[NOTWORK],		[DATE_BEGIN], [DATE_MOV],
		[OKLAD],			[GRAPH_LINK],	[GRAPH_NAME],
		[DATE_SACK],		[ITEM_MOVE_LINK],		[VIS],
		[LINK_KBK], 		[CODE_KBK], 	[NAME_KBK],
		[RAZR],				[SYST_PAY],		[POST_GROUP], [KATEG],
		[CHIN],				[CHIN_DATE],	[EMAIL],
		[PHONE_WORK],		[PHONE_MOB],	[INN],
		[SNILS],			[RESIDENT],			[RESIDENT_N],		
		[SACK],			[SACK_PER])
SELECT	distinct
	T.*,
	CASE
		WHEN datediff(day,T.DATE_SACK, @dDATE) > 0  THEN 1
		ELSE 0
	END AS SACK,
	CASE
		WHEN YEAR(T.DATE_SACK) = YEAR(@dDATE)
		     AND MONTH(T.DATE_SACK) = MONTH(@dDATE) THEN 1
		ELSE 0
	END AS SACK_PER
FROM	(
	SELECT 
		[LINK] 			= 	E.LINK, 
		[PERS_LINK]		= 	P.LINK, 
		[DEP_LINK]		= 	E.DEP_LINK,
		[DEP_NAME]		=	DEP.NAME,
		[TAB]			= 	E.TAB,
		[FM]			= 	P.FM,
		[IM]			= 	P.IM, 
		[OT]			=	P.OT,
		[FIO]			=	LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LTRIM(RTRIM(IM)) + ' ' + LTRIM(RTRIM(OT)),'Не заполнено'))),100),
		[NAME_EMPL]		= 	LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30),
		[SUBDIV_HEAD]	=	DS.link_up,
		[SUBDIV_LINK]	=	DS.LINK,
		[SUBDIV_CODE]	=	DS.CODE,
		[SUBDIV_NAME]	=	DS.NAME,
		[POST_LINK]		=	DP.LINK,
		[POST_CODE]		=	DP.CODE,
		[POST_NAME]		=	DP.NAME,
		[STAFF_HEAD]	=	PE.STAFF_HEAD,
		[STAFF_LINK]	= 	PE.STAFF_LINK,
		[NUM_STAKE]		=	PE.NUM_STAKE,
		[STATUS]		=	PE.[STATUS],
		[STATUS_NAME]	=	CASE WHEN PE.[STATUS] = 1 THEN 'Основной' WHEN PE.[STATUS] = 2 THEN 'Совместитель' WHEN PE.[STATUS] = 3 THEN 'Внешний совместитель' END,
		[NOTWORK]		=	E.NOTWORK,
		[DATE_BEGIN]	=	IM.DATE_BEGIN,
		[DATE_MOV]		=	PE.DATE_BEG,
		[OKLAD]			=	PE.oklad,
		[GRAPH_LINK]	= 	G.LINK,
		[GRAPH_NAME]	=	G.NAME,
		[DATE_SACK]		=	IDF.DIS_DATE,
		[ITEM_MOVE_LINK] =	PE.MOVE_LINK,
		[VIS]			=	CONVERT(bit, 0),
		LINK_KBK		=	KBK.LINK,
		CODE_KBK		=	KBK.CODE,
		NAME_KBK		=	KBK.NAME,
		RAZR			=	COALESCE(IM.ETS_RAZR,0),
		[SYST_PAY]		=	E.SYST_PAY,		
		[POST_GROUP]	=	GR.NAME,
		[KATEG]			=	KAT.NAME,
		[CHIN]			=	CE.CHIN_NAME,
		[CHIN_DATE]		=	CE.CHIN_DATE,		
		[EMAIL]			=	PME.[EMAIL] ,
		[PHONE_WORK]	=	PME.[PHONE_WORK],
		[PHONE_MOB]		=	PME.[PHONE_MOB],
		[INN]			=	P.INN,
		[SNILS]			=	P.INSUR_NUM,
		[RESIDENT]		= 	 (CASE WHEN P.RESIDENT = 0 then 1 when P.RESIDENT = 1 then 2 else 3 END),
		[RESIDENT_N]	= 	 (CASE WHEN P.RESIDENT = 0 then 'Нерезидент (временно проживающий)' when P.RESIDENT = 1 then 'Резидент' else 'Нерезидент (постоянно проживающий)' END)	

	FROM			dbo.EMPL		E
		INNER JOIN	dbo.PERSON 			P	 ON e.pers_link=p.link
		LEFT JOIN	dbo.GRAPH			G	 ON e.graph_link=g.link
		LEFT JOIN	@POST_EMPL		PE	 ON E.LINK = PE.EMPL_LINK
		LEFT JOIN	dbo.SAL_SFIN		KBK	 ON KBK.LINK = PE.LINK_KBK		
		LEFT JOIN	dbo.SUBDIV			DS	 ON PE.subdiv_link = DS.LINK
		LEFT JOIN	dbo.POST			DP	 ON PE.post_link = DP.LINK
		LEFT JOIN	dbo.ITEM_MOVE		IM	 ON IM.ACTIVE = 1 AND IM.NEW_FACE = 1 AND IM.EMPL_LINK = E.LINK
		LEFT JOIN	dbo.DEPARTMENTS		DEP	 ON E.DEP_LINK = DEP.LINK
		LEFT JOIN	dbo.ITEM_MOVE	SE	 ON E.LINK = SE.EMPL_LINK AND @dDATE between SE.date_begin and SE.date_end and SE.active=1
		LEFT JOIN	@ITEM_DIS_FACE	IDF	 ON E.LINK = IDF.EMPL_LINK
		LEFT JOIN	@CHIN_EMPL		CE	 ON E.LINK = CE.EMPL_LINK
		LEFT JOIN   @PHONE_MAIL_EMPL PME ON E.LINK = PME.EMPL_LINK
		LEFT JOIN	dbo.STAFF ST ON ST.LINK = PE.STAFF_LINK
		LEFT JOIN	dbo.GR_GOS GR ON GR.LINK = ST.GR_GOS_LINK
		LEFT JOIN   DBO.KAT_GOS KAT ON KAT.LINK = ST.KAT_GOS_LINK
		--LEFT JOIN	dbo.KATEG KAT ON KAT.LINK = ST.KAT_LINK

	) T

RETURN
END


GO


GRANT SELECT ON dbo.[KU_EMPL_PLACING_FN] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_GZ_REESTR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[BB_GZ_REESTR]

GO


CREATE           VIEW dbo.BB_GZ_REESTR
AS
SELECT	LINK = G.LINK,
	G.COMMENT,
	G.NUMBER,
	G.[DATE],
	G.[DATE_PROV],
	[FLAG_JC] = CASE WHEN G.DATE_PROV IS NULL THEN 0 ELSE 1 END,
	[DEP_LINK]	= G.DEP,
	[DEP_CODE]	= D.CODE,
	[DEP_NAME]	= D.[NAME],
  	[ACC_LINK]	= G.ACC,
	[ACC_CODE]	= DA.CODE,		
	[ACC_NAME]	= DA.[ANAME],

	-- ДОГОВОР
	CON_PAY		= isnull(HC.CON_PAY, GZ.CON_PAY),
	CON_PAY_NAME	= (select NAME from dbo.CONDITIONS_PAY where VALUE = isnull(HC.CON_PAY, GZ.CON_PAY)),
	CON_LINK	= GC.[NUMBER],
	CON_TYPE	= isnull(HC.TYPE,GZ.TYPE),
	CON_TYPE_NAME	= cast(ZT.NAME as char(100)),
	CON_NUMBER	= GC.[NUMBER],
	CON_DATE	= GC.[DATE],
	CON_SUMMA 	= GC.[SUMMA],
	CONTRACT 	= cast((SELECT rtrim(NAME) from dbo.S_OBJECTS where LINK = GC.OBJECT) + ' № '  + rtrim(GC.[NUMBER]) + ' от ' + ISNULL(CONVERT(VARCHAR(30),GC.[DATE],104),'') as varchar(254)),
	[DEP_GZ_LINK]	= D2.LINK,
	[DEP_GZ_CODE]	= D2.CODE,
	[DEP_GZ_NAME]	= D2.[NAME],
	[DEP_GZ_TYPE2_NAME]	=cast(case 	when D2.DEP_TYPE2 = 1 then 'Малое предприятие'
						when D2.DEP_TYPE2 = 2 then 'Учреждение УИС'
						when D2.DEP_TYPE2 = 3 then 'Организация инвалидов'
						when D2.DEP_TYPE2 is null then ''
						else 'Прочие' end as char(25)) ,
	
	-- ДОКУМЕНТ	
	DOC_DATE	= GD.[DATE],
	DOC_LINK	= GD.LINK,
	DOC_NUMBER	= GD.[NUMBER],
	OPER_SUMMA	= G2.[SUMMA],
	PROV 		= ISNULL(G2.NAME,G1.NAME_OPER),
	
	DOC	 	= cast((SELECT rtrim(NAME) from dbo.S_OBJECTS where LINK = GD.OBJECT) + ' № ' + rtrim(GD.[NUMBER]) + ' от ' + ISNULL(CONVERT(VARCHAR(30),GD.[DATE],104),'') as varchar(254)),

	-- ТАБЛИЦА
	LINK_T		= GZT.LINK,
	GZT.NOMENCLATURE,
	NOMEN_CODE 	= N.CODE,
	NOMEN_NAME 	= N.NAME,
	OKDP_CODE 	= O.CODE,
	OKDP_NAME 	= O.NAME,
	OKPD_CODE 	= OP.CODE,
	OKPD_NAME 	= OP.NAME,
	N.UM,
	GZT.TYPE,
	[TYPE_NAME]	= cast(case GZT.TYPE	when 1 then 'Оплата'
						when 2 then 'Поставка' end as char(10)),
	GZT.COST,
	GZT.QUANTITY,
	GZT.SUMMA,
	UM_CODE		= UM.CODE,
	UM_NAME		= UM.NAME,
	[UNLOAD]	= case when GE.LINK_G is null then 0 else 1 end
 



from 		dbo.G_PROV G
inner join	dbo.GZ_REESTR GZR on GZR.LINK = G.LINK
inner join	dbo.G_PROV2 G2 on GZR.LINK_G_PROV2 = G2.LINK 
inner join	dbo.G_PROV1 G1 on G2.LINK_UP = G1.LINK  
inner join	dbo.G_PROV GD on G1.LINK_UP = GD.LINK 
inner join	dbo.S_OBJECTS SO on GD.OBJECT = SO.LINK
left join	dbo.G_PROV_AP GAPD on GAPD.LINK_UP = G2.LINK and GAPD.DB_KR = 0
left join	dbo.G_PROV_AP GAPK on GAPK.LINK_UP = G2.LINK and GAPK.DB_KR = 1
left join	dbo.G_PROV GC on GZR.LINK_CONTRACT = GC.LINK
left join	dbo.FINANSE_CONTRACT_HEAD HC on HC.LINK_G_PROV = GC.LINK
left join	dbo.GZ_NOT_CONTRACT_HEAD GZ on GZ.LINK = GC.LINK
left join	dbo.GZ_REESTR_DOP GZT on GZT.LINK_UP = G.LINK
left join	dbo.NOMENCLATURE N on N.LINK = GZT.NOMENCLATURE
left join 	dbo.DICTIONARY_DIGIT UM on N.UM = UM.LINK 
left join 	dbo.DEPARTMENTS D on G.DEP = D.LINK
left join 	dbo.DEPARTMENTS D2 on COALESCE(HC.DEP_LINK_P,GZ.DEP_LINK_P, GAPD.DEP, GAPK.DEP) = D2.LINK
left join 	dbo.DICTIONARY_ACCOUNTS DA on G.ACC = DA.LINK
left join 	dbo.FB_GZ_TYPE ZT on ISNULL(HC.TYPE, GZ.TYPE) = ZT.TYPE
left join 	dbo.OKDP O on O.LINK = N.LINK_OKDP
left join 	dbo.OKPD OP on OP.LINK = N.LINK_OKPD
left join	dbo.GZ_EXPORT_EVENTS GE on GE.LINK_G = G.LINK 
where  G.OBJECT in (select LINK from dbo.S_OBJECTS where CODE='BB_GZ_REESTR')














GO


GRANT SELECT ON dbo.[BB_GZ_REESTR] TO PUBLIC

GO



GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BD_JURN_BO]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[BD_JURN_BO]
GO


/*
© Кейсистемс (Keysystems), 2005
*/

CREATE     VIEW BD_JURN_BO
AS
SELECT
 [LINK] 	= JB.LINK,
 [FLAG_HAND]	= (CASE WHEN JB.LINK_PO_PROV IS NULL THEN 0 ELSE 1 END),
 [AP1]		= JB.LINK_DOC,
 [CODE_AP1]	= O.NUMBER,
 [DATE_AP1]	= JB.DATE_DOC,	
 [NAME_AP1]	= O.INFO,
 [TYPE_AP1]	= O.TYPE,
 [KBK_LINK]	= JB.LINK_KBK,
 [KBK_CODE]	= (SELECT CODE FROM dbo.KL_KBK WHERE LINK =JB.LINK_KBK),	
 [KBK_TYPE]	= (SELECT [TYPE] FROM dbo.KL_KBK WHERE LINK =JB.LINK_KBK),	
 [SGU_LINK]	= JB.LINK_SGU,
 [SGU_CODE]	= (SELECT CODE FROM dbo.DICTIONARY_KOSGU WHERE LINK =JB.LINK_SGU),	
 [SGU_NAME]	= (SELECT NAME FROM dbo.DICTIONARY_KOSGU WHERE LINK =JB.LINK_SGU),	
 [DOP_LINK]	= JB.LINK_DOP,
 [DOP_CODE]     = (SELECT CODE FROM dbo.BD_DOP_CLASSIF WHERE LINK =JB.LINK_DOP),	
 [DOP_NAME]     = (SELECT NAME FROM dbo.BD_DOP_CLASSIF WHERE LINK =JB.LINK_DOP),	
 [ACCOUNT_LINK] = JB.LINK_ACCOUNT,
 [ACCOUNT_CODE] = (SELECT CODE FROM dbo.DICTIONARY_ACCOUNTS WHERE LINK =JB.LINK_ACCOUNT),	
 [ACCOUNT_NAME] = (SELECT ANAME FROM dbo.DICTIONARY_ACCOUNTS WHERE LINK =JB.LINK_ACCOUNT),	
 [SUMMA]	=  JB.SUMMA,
 [IST_FIN]	=  JB.IST_FIN,
 FS_NAME = FS.NAME,
 [PROV_LINK]	=  JB.LINK_PO_PROV,
 [DATE_PR]	=  JB.DATE_PR,	
 [DATE_SN]	=  JB.DATE_SN,
 [COMMENT] 	=  JB.COMMENT,
 [TP]		= O.TP,
 [OBJECT]	= O.OBJECT,
 [DOC_LINK]	= O.DOC_LINK,
 [DEP]		= O.DEP,
 JB.DO,
 DO_NAME = case JB.DO when 1 then 'Денежное' else 'Бюджетное' end,
 CORR_NAME = D.NAME
FROM dbo.JURN_BO JB
inner join BB_FIN_SOURCE FS on FS.CODE = JB.IST_FIN
left join dbo.BD_OSNOV O on O.LINK =JB.LINK_DOC
left join dbo.FINANSE_CONTRACT_HEAD FH on O.DOC_LINK =FH.LINK_g_prov
left join dbo.DEPARTMENTS D on FH.DEP_LINK_P =D.LINK






GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_EMPL_FN]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[SD_EMPL_FN]

GO

CREATE FUNCTION DBO.SD_EMPL_FN(@LINK_EMPL INT = -1, @DATE DATETIME = NULL, @BUFF_ID VARCHAR(20) = NULL, @DEP_LINK INT = NULL)
RETURNS TABLE

RETURN

SELECT 
	[LINK] 			= 	E.LINK,
	[PERS_LINK]		=   E.PERS_LINK,
	[TAB]			=	E.TAB,
	[FM]			= 	P.FM,
	[IM]			= 	P.IM,
	[OT]			= 	P.OT,
	[FIO]			=	RTRIM(P.FM) + ' ' + SUBSTRING(RTRIM(P.IM),1,1) + '.' + SUBSTRING(RTRIM(P.OT),1,1) + '.',
	[DATE_BEGIN]		= IM.DATE_BEGIN,
	[DATE_END]		=   IDF.DIS_DATE,
	[INSUR_NUM]		= 	P.INSUR_NUM,
	[INN]			= 	P.INN,
	[IFNS]			= 	P.IFNS,
	[RESIDENT]		= 	 (CASE WHEN P.RESIDENT = 0 then 1 when P.RESIDENT = 1 then 2 else 3 END),
	[RESIDENT_N]	= 	 (CASE WHEN P.RESIDENT = 0 then 'Нерезидент (временно проживающий)' when P.RESIDENT = 1 then 'Резидент' else 'Нерезидент (постоянно проживающий)' END),	
	[SACK]			=   (CASE WHEN COALESCE(IDF.LINK,0) = 0 THEN 0 ELSE 1 END),
	[SYST_PAY] 		= 	E.SYST_PAY,
	[STAKE]			= 	COALESCE(D.NUM_STAKE,0),
	[AVANCE]		=   	E.AVANCE,	
	[GRAPH_LINK]		=	E.GRAPH_LINK, 
	[GRAPH_NAME]		=	G.[NAME],
	[STATUS_EMPL]		=	COALESCE(D.STATUS,0),	
	[NORTH]			=   	E.NORTH,	
	[KOEF]			= 	E.KOEF,
	[DEP_LINK]		= 	E.DEP_LINK,
	RAZR = COALESCE(D.ETS_RAZR,0),
	LINK_KBK 		= 	KBK.LINK,
	CODE_KBK 		= 	KBK.CODE,
	NAME_KBK 		= 	KBK.[NAME],
	[POST_LINK]		=	COALESCE(DP.LINK,0),
	[POST_CODE]		=	DP.CODE,
	[POST_NAME]		=	DP.[NAME],
	D.SUBDIV_HEAD,
	D.SUBDIV_LINK,
	[SUBDIV_CODE]	=	S.[CODE],
	[SUBDIV_NAME]	=	S.[NAME],
	KAT_LINK		= 	COALESCE(D.KAT_LINK,0),
	KAT_NAME		= 	KAT.[NAME],
	D.STAFF_HEAD,
	D.STAFF_LINK,

	INST_CHIEF_ACC, /*ПРИЗНАК ЗАМЕСТИТЕЛЯ ГЛАВНОГО БУХГАЛТЕРА (1-ДА, 2-НЕТ)*/

	INC_ETS1, /*УВЕЛИЧЕНИЕ РАЗРЯДА ПО 1 ПРИЧИНЕ НА КОЛИЧЕСТВО 1*/
	INC_ETS1_NAME = I1.[NAME],
	INC_ETS1_VALUE= COALESCE(INC_ETS1_VALUE,0),

	INC_ETS2, /*УВЕЛИЧЕНИЕ РАЗРЯДА ПО 2 ПРИЧИНЕ НА КОЛИЧЕСТВО 2*/
	INC_ETS2_NAME = I2.[NAME],
	INC_ETS2_VALUE= COALESCE(INC_ETS2_VALUE,0),

	INC_ETS3, /*УВЕЛИЧЕНИЕ РАЗРЯДА ПО 3 ПРИЧИНЕ НА КОЛИЧЕСТВО 3*/
	INC_ETS3_NAME = I3.[NAME],
	INC_ETS3_VALUE= COALESCE(INC_ETS3_VALUE,0),	

	KOEF_PKG,
	FOT = COALESCE(FOT,2),
	FOT_NAME = CASE WHEN COALESCE(FOT,2) = 1 THEN 'ПКГ' ELSE 'ЕТС' END,
	RAZR1 = COALESCE(D.ETS_RAZR,0) +COALESCE(INC_ETS1_VALUE,0) +COALESCE(INC_ETS2_VALUE,0) + COALESCE(INC_ETS3_VALUE,0),
	NO_RAION
FROM 
	DBO.PERSON P with (nolock)
	INNER JOIN DBO.EMPL E with (nolock) ON E.PERS_LINK = P.LINK AND E.DEP_LINK = COALESCE(@DEP_LINK,E.DEP_LINK)
	--INNER JOIN DBO.USER_DEP DEP ON COALESCE(@DEP_LINK, DEP.DEP_LINK) = E.DEP_LINK
	INNER JOIN (SELECT DBO.SALARYCALCPERIOD() AS DATE) AS CP ON 1=1
	LEFT JOIN DBO.SA_EMPLS_INFO(@DATE, @LINK_EMPL) D ON E.LINK = D.EMPL_LINK
	LEFT JOIN DBO.SUBDIV S with (nolock) ON S.LINK = D.SUBDIV_LINK
	LEFT JOIN POST DP with (nolock) ON D.POST_LINK = DP.LINK
	LEFT JOIN DBO.SAL_SFIN KBK ON KBK.LINK = D.LINK_KBK
	LEFT JOIN DBO.GRAPH G ON G.LINK = E.GRAPH_LINK
	LEFT JOIN DBO.ITEM_MOVE IM with (nolock) ON IM.EMPL_LINK = E.LINK AND IM.ACTIVE = 1 AND IM.NEW_FACE=1
	LEFT JOIN DBO.ITEM_DIS_FACE IDF with (nolock) ON IDF.EMPL_LINK = E.LINK AND IDF.ACTIVE=1 AND COALESCE(IDF.DIS_DATE,'29990101') < COALESCE(@DATE,CP.DATE)
	LEFT JOIN DBO.KATEG KAT with (nolock) ON D.KAT_LINK = KAT.LINK
	LEFT JOIN DBO.STS_REASONS_INCSCALE AS I1 ON I1.LINK = INC_ETS1
	LEFT JOIN DBO.STS_REASONS_INCSCALE AS I2 ON I2.LINK = INC_ETS2
	LEFT JOIN DBO.STS_REASONS_INCSCALE AS I3 ON I3.LINK = INC_ETS3	
WHERE
	(
		(@LINK_EMPL = -1 
		AND 
		(	@BUFF_ID IS NULL
			OR 
			@BUFF_ID IS NOT NULL AND E.LINK IN (SELECT LINK FROM DBO.BUFFER with (nolock) WHERE ID = @BUFF_ID)
		))
		OR
		(@LINK_EMPL > 0 AND E.LINK = @LINK_EMPL)
	)



GO


GRANT SELECT ON dbo.[SD_EMPL_FN] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[KU_EMPL_PLACING]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[KU_EMPL_PLACING]

GO

-- ДОБАВЛЕНЫ ПОЛЯ:
-- группа должностей
-- классный чин
-- дата присвоения (классного чина)
-- дата назначеняи на дожность
-- электронная почта
-- телефон (служебный)
-- телефон (мобильный)
-- ИНН
-- СНИЛС

CREATE  VIEW dbo.KU_EMPL_PLACING
AS
SELECT *
FROM dbo.KU_EMPL_PLACING_FN(default)




GO


GRANT SELECT ON dbo.[KU_EMPL_PLACING] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[FB_REST_FINANS_DEP]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[FB_REST_FINANS_DEP]

GO
CREATE FUNCTION dbo.FB_REST_FINANS_DEP(@varKSintFyear int, 
					@varKSdDate 		datetime, 
					@varKSintPer_num 	int, 
					@varKSintSumType 	numeric (5, 3), 
					@varKSFinLink 		int = 0, 
					@varKSFinObjCode 	char(100),
					@varKSintTypePer 	int = 1,
					@varKScTypeBudg 	Char(1) = '1',
					@varKSiIsRBS		INT	= 0,
					@varKSiDEP			int = 0)
-- за год @varKSintTypePer = 1 - за год,
--			   = 2 - по кварталам,
--			   = 3 - по месяцам
-- за период = + 10		  
RETURNS @varKSResTable TABLE
	(dep	[int] NULL,
	 dep_acc [int] NULL,
	 rbs_dep [int] NULL,
	 rbs_acc [int] NULL,
	 vkr	[int] NULL,
	 ekr	[int] NULL, 
	 dop_cl	[int] NULL, 
	 reg int null,
	 P1	[numeric](28, 2) NULL,
	 P2	[numeric](28, 2) NULL,
	 P3	[numeric](28, 2) NULL,
	 P4	[numeric](28, 2) NULL,
	 P5	[numeric](28, 2) NULL,
	 P6	[numeric](28, 2) NULL,
	 P7	[numeric](28, 2) NULL,
	 P8	[numeric](28, 2) NULL,
	 P9	[numeric](28, 2) NULL,
	 P10	[numeric](28, 2) NULL,
	 P11	[numeric](28, 2) NULL,
	 P12	[numeric](28, 2) NULL,
	 Y2	[numeric](28, 2) NULL,
	 Y3	[numeric](28, 2) NULL)

AS
BEGIN
DECLARE @varKSAccount int,
	@varKSFinObj int,
	@varKSdEndDate1 datetime,
	@varKSdEndDate2 datetime,
	@varKSdEndDate3 datetime,
	@varKSdEndDate4 datetime,
	@varKSdEndDate5 datetime,
	@varKSdEndDate6 datetime,
	@varKSdEndDate7 datetime,
	@varKSdEndDate8 datetime,
	@varKSdEndDate9 datetime,
	@varKSdEndDate10 datetime,
	@varKSdEndDate11 datetime,
	@varKSdEndDate12 datetime,
	@varKSdBegDate1 datetime,
	@varKSdBegDate2 datetime,
	@varKSdBegDate3 datetime,
	@varKSdBegDate4 datetime,
	@varKSdBegDate5 datetime,
	@varKSdBegDate6 datetime,
	@varKSdBegDate7 datetime,
	@varKSdBegDate8 datetime,
	@varKSdBegDate9 datetime,
	@varKSdBegDate10 datetime,
	@varKSdBegDate11 datetime,
	@varKSdBegDate12 datetime,
	@varKSdDateEndP	 datetime,
	@varKSdDateBegP	 datetime,
	@varKSiOwnDep	int,
	@iYear3			tinyint,
	@cSinth			char(3)
			

set @iYear3 = dbo.sa_get_option_by_code('FINANSE_3_YEAR')

DECLARE @varKSTempTable TABLE 
	(dep	[int] NULL,
	 dep_acc [int] NULL,
	 rbs_dep [int] NULL,
	 rbs_acc [int] NULL,
	 vkr	[int] NULL,
	 ekr	[int] NULL, 
	 dop_cl	[int] NULL, 
	 reg int null,
	 P1	[numeric](19, 2) NULL,
	 P2	[numeric](19, 2) NULL,
	 P3	[numeric](19, 2) NULL,
	 P4	[numeric](19, 2) NULL,
	 P5	[numeric](19, 2) NULL,
	 P6	[numeric](19, 2) NULL,
	 P7	[numeric](19, 2) NULL,
	 P8	[numeric](19, 2) NULL,
	 P9	[numeric](19, 2) NULL,
	 P10	[numeric](19, 2) NULL,
	 P11	[numeric](19, 2) NULL,
	 P12	[numeric](19, 2) NULL)

DECLARE @varKSTableOborot TABLE 
	(DATE_PROV	datetime null,
	 DEP	 	[int] NULL,
	 DEP_ACC 	[int] NULL,
	 RBS_DEP 	[int] NULL,
	 RBS_ACC 	[int] NULL,
	 INDATE 	datetime null,
	 VKR	[int] NULL,
	 EKR	[int] NULL, 
	 DOP_CL	[int] NULL, 
	REG int null,
	  SUMMA	[numeric](19, 2) NULL)

set @varKSiOwnDep = coalesce(@varKSiDEP, dbo.BK_GetDepZB (), dbo.GetOwnDepLink())

IF @varKSiIsRBS < 1 or @varKSiIsRBS is null
	set @varKSiIsRBS = dbo.FB_GetDepIS_RBS(@varKSiOwnDep,default) 

set @varKSdBegDate1 = convert(datetime,convert(char(4),@varKSintFyear) + '0101')
SET @varKSdBegDate2 =  convert(datetime,convert(char(4),@varKSintFyear) + '0201')
SET @varKSdBegDate3 =  convert(datetime,convert(char(4),@varKSintFyear) + '0301')
SET @varKSdBegDate4 =  convert(datetime,convert(char(4),@varKSintFyear) + '0401')
SET @varKSdBegDate5 =  convert(datetime,convert(char(4),@varKSintFyear) + '0501')
SET @varKSdBegDate6 =  convert(datetime,convert(char(4),@varKSintFyear) + '0601')
SET @varKSdBegDate7 =  convert(datetime,convert(char(4),@varKSintFyear) + '0701')
SET @varKSdBegDate8 =  convert(datetime,convert(char(4),@varKSintFyear) + '0801')
SET @varKSdBegDate9 =  convert(datetime,convert(char(4),@varKSintFyear) + '0901')
SET @varKSdBegDate10 =  convert(datetime,convert(char(4),@varKSintFyear) + '1001')
SET @varKSdBegDate11 =  convert(datetime,convert(char(4),@varKSintFyear) + '1101')
SET @varKSdBegDate12 =  convert(datetime,convert(char(4),@varKSintFyear) + '1201')
SET @varKSdEndDate1 = @varKSdBegDate2 - 1
SET @varKSdEndDate2 = @varKSdBegDate3 - 1
SET @varKSdEndDate3 = @varKSdBegDate4 - 1
SET @varKSdEndDate4 = @varKSdBegDate5 - 1
SET @varKSdEndDate5 = @varKSdBegDate6 - 1
SET @varKSdEndDate6 = @varKSdBegDate7 - 1
SET @varKSdEndDate7 = @varKSdBegDate8 - 1
SET @varKSdEndDate8 = @varKSdBegDate9 - 1
SET @varKSdEndDate9 = @varKSdBegDate10 - 1
SET @varKSdEndDate10 = @varKSdBegDate11 - 1
SET @varKSdEndDate11 = @varKSdBegDate12 - 1
SET @varKSdEndDate12 = convert(datetime,convert(char(4),@varKSintFyear + 1)+'0101') - 1


select @varKSintPer_num  = (case @varKSintTypePer
				when 13 then @varKSintPer_num				
				when 12 then (case when @varKSintPer_num < 4 then 1
						when @varKSintPer_num < 7 then 4
						when @varKSintPer_num < 10 then 7
						else 10 end)
				when 11 then 1
				else 0 end)
						
/*
IF @varKSFinObjCode like '%_ASSIGN%'
	SELECT	@varKSintLimType = 0,
		@varKSintLimPer = max(FIN_SMETA_PER)
		FROM WorkMode
ELSE
	SELECT	@varKSintLimType = max(FIN_LIM_TYPE),
		@varKSintLimPer = max(FIN_LIM_PER)
		FROM WorkMode

IF @varKSintLimType = 0 or @varKSintLimPer = 0 or @varKSintPer_num = 0
*/

IF @varKSintTypePer < 12 or @varKSintPer_num = 0
begin
	set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
	set @varKSdDateBegP= convert(datetime,convert(char(4),@varKSintFyear) + '0101')
end
else 
begin
	if @varKSintTypePer = 12
	BEGIN
		if @varKSintPer_num = 10
		begin
			set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '1001'))		
		end
		else
		begin
			if @varKSintPer_num = 7
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + convert(char(2),@varKSintPer_num + 3) + '01') - 1
			else 
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0' + convert(char(1),@varKSintPer_num + 3) + '01') - 1
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '0' + convert(char(1),@varKSintPer_num) + '01'))
		end
	END 
	else 
	BEGIN
		if @varKSintPer_num = 12
			set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0101') - 1
		else 		
			if @varKSintPer_num > 8
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + convert(char(2),@varKSintPer_num + 1) + '01') - 1
			else 
				set @varKSdDateEndP = convert(datetime,convert(char(4),@varKSintFyear+1) + '0' + convert(char(1),@varKSintPer_num + 1) + '01') - 1
		if @varKSintPer_num < 10
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + '0' + convert(char(1),@varKSintPer_num) + '01'))
		else 		
			set @varKSdDateBegP = convert(datetime,(convert(char(4),@varKSintFyear) + convert(char(2),@varKSintPer_num) + '01'))

	END
end   

-- дата расчета не должна выходить за пределы периода
if @varKSdDate > @varKSdDateEndP
	set @varKSdDate = @varKSdDateEndP
/*
if  @varKSFinLink = 0 or @varKSFinLink is null
	select  @varKSFinObj = link from s_objects where code = @varKSFinObjCode
else */
	select  @varKSFinObj = object from g_prov where link = @varKSFinLink
if @varKSFinObjCode like '%_ASSIGN%'
	set @cSinth = '503'
else
    if @varKSFinObjCode = 'FB_SMETA_VNEB' or @varKSFinObjCode = 'FB_PLAN_FHD'
    	set @cSinth = '504'
	else
	    set @cSinth = '501'

if @varKSFinObjCode like '%_SVOD' 
	--IF @varKSiIsRBS = 2
		SELECT @varKSAccount = link 
		FROM s_accounts 
		WHERE cSinth = @cSinth and cAnalit = '12' and cSource = @varKScTypeBudg  
	--else 
	--	SELECT @varKSAccount = link 
	--	FROM s_accounts 
	--	WHERE cSinth = @cSinth and cAnalit = '11' and cSource = @varKScTypeBudg  
else 
	IF @varKSiIsRBS > 1
		SELECT @varKSAccount = link 
		FROM s_accounts 
		WHERE cSinth = @cSinth and cAnalit = '14' and cSource = @varKScTypeBudg  
	ELSE
		SELECT @varKSAccount = link 
		FROM s_accounts 
		WHERE cSinth = @cSinth and cAnalit = '13' and cSource = @varKScTypeBudg  

SET @varKSFinObjCode = REPLACE(@varKSFinObjCode,'_CC','') 

IF /*@varKSFinObjCode like '%_ASSIGN%' or */ @varKSFinObjCode LIKE '%_SMETA%' or @varKSFinObjCode = 'FB_RESULT_FINANS' or @varKSFinObjCode LIKE 'FB_PLAN%'
	
INSERT INTO @varKSResTable (dep, dep_acc, rbs_dep, rbs_acc, vkr, ekr,dop_cl, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, Y2, Y3)
	SELECT DA.LINK_UP, FH.ACCOUNT, GP.dep, GP.ACC, F.vkr, F.ekr, F.dop_cl, F.REG, 
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 1) or (@varKSintTypePer = 13 and @varKSintPer_num = 1)) then sum(F.p1) * @varKSintSumType else 0 end) as p1,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 1) or (@varKSintTypePer = 13 and @varKSintPer_num = 2)) then sum(F.p2) * @varKSintSumType else 0 end) as p2,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 1) or (@varKSintTypePer = 13 and @varKSintPer_num = 3)) then sum(F.p3) * @varKSintSumType else 0 end) as p3,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 4) or (@varKSintTypePer = 13 and @varKSintPer_num = 4)) then sum(F.p4) * @varKSintSumType else 0 end) as p4,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 4) or (@varKSintTypePer = 13 and @varKSintPer_num = 5)) then sum(F.p5) * @varKSintSumType else 0 end) as p5,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 4) or (@varKSintTypePer = 13 and @varKSintPer_num = 6)) then sum(F.p6) * @varKSintSumType else 0 end) as p6,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 7) or (@varKSintTypePer = 13 and @varKSintPer_num = 7)) then sum(F.p7) * @varKSintSumType else 0 end) as p7,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 7) or (@varKSintTypePer = 13 and @varKSintPer_num = 8)) then sum(F.p8) * @varKSintSumType else 0 end) as p8,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 7) or (@varKSintTypePer = 13 and @varKSintPer_num = 9)) then sum(F.p9) * @varKSintSumType else 0 end) as p9,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 10) or (@varKSintTypePer = 13 and @varKSintPer_num = 10)) then sum(F.p10) * @varKSintSumType else 0 end) as p10,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 10) or (@varKSintTypePer = 13 and @varKSintPer_num = 11)) then sum(F.p11) * @varKSintSumType else 0 end) as p11,
	(case when (@varKSintPer_num = 0 or @varKSintTypePer < 12 or (@varKSintTypePer = 12 and @varKSintPer_num = 10) or (@varKSintTypePer = 13 and @varKSintPer_num = 12)) then sum(F.p12) * @varKSintSumType else 0 end) as p12,
	case @iYear3 when 1 then sum(F.Y2) * @varKSintSumType else 0 end as YS2,
	case @iYear3 when 1 then sum(F.Y3) * @varKSintSumType else 0 end as YS3
	from finanse F
	inner join G_Prov GP on GP.object in (select link from s_objects where REPLACE(Code,'_CC','') = @varKSFinObjCode)
				and GP.DATE_PROV is not null  
				and GP.DEP = @varKSiOwnDep
				and GP.DATE_PROV <= @varKSdDate
				and not GP.LINK = @varKSFinLink
				and F.link_up = GP.link
	inner join FINANSE_HEAD FH on FH.LINK = GP.LINK and FH.FYEAR = @varKSintFyear
	inner join department_accounts DA on da.link = FH.ACCOUNT
						and ((DA.type = 2 or DA.type = 3) and @varKScTypeBudg = '1'
						or (DA.type = 1 or DA.type = 4)  and @varKScTypeBudg = '2' or @varKScTypeBudg is null)
	group by DA.LINK_UP, FH.ACCOUNT, GP.dep, GP.ACC, vkr, ekr, dop_cl, REG
ELSE 
begin
	INSERT INTO @varKSTableOborot (DATE_PROV, DEP, DEP_ACC, RBS_DEP, RBS_ACC, INDATE, VKR, EKR,DOP_CL, REG, SUMMA)
	SELECT DATE_PROV,DEP, DEP_ACC, DEP_LINK, ACC_LINK, INDATE, KBK AS VKR, EKR, AP2 AS DOP_CL, AP3 as REG, isnull(k_summa,0)
	from FB_LimitOborotByPeriod(@varKSdDateBegP,@varKSdDateEndP, @varKSAccount)
	where not LINK_UP = @varKSFinLink
		and DEP_LINK = @varKSiOwnDep
		and not DATE_PROV > @varKSdDate
	IF @varKSiIsRBS > 1
	begin
		SELECT @varKSAccount = link 
		FROM s_accounts 
		WHERE cSinth = @cSinth and cAnalit = '13' and cSource = @varKScTypeBudg  
	
		INSERT INTO @varKSTableOborot (DATE_PROV, DEP, DEP_ACC, RBS_DEP, RBS_ACC, INDATE, VKR, EKR,DOP_CL, REG, SUMMA)
		SELECT DATE_PROV,DEP, DEP_ACC, DEP_LINK, ACC_LINK, INDATE, KBK AS VKR, EKR, AP2 AS DOP_CL,  AP3 as REG, isnull(k_summa,0)
		from FB_LimitOborotByPeriod(@varKSdDateBegP,@varKSdDateEndP, @varKSAccount)
		where not LINK_UP = @varKSFinLink
			and DEP_LINK = @varKSiOwnDep
			and not DATE_PROV > @varKSdDate
	end	


	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, summa,0,0,0,0,0,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate1 and @varKSdEndDate1) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate1 and @varKSdEndDate1))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0, summa,0,0,0,0,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate2 and @varKSdEndDate2) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate2 and @varKSdEndDate2))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,summa,0,0,0,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate3 and @varKSdEndDate3) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate3 and @varKSdEndDate3))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,summa,0,0,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate4 and @varKSdEndDate4) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate4 and @varKSdEndDate4))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL,REG, 0,0,0,0,summa,0,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate5 and @varKSdEndDate5) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate5 and @varKSdEndDate5))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,summa,0,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate6 and @varKSdEndDate6) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate6 and @varKSdEndDate6))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,0,summa,0,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate7 and @varKSdEndDate7) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate7 and @varKSdEndDate7))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,0,0,summa,0,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate8 and @varKSdEndDate8) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate8 and @varKSdEndDate8))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,0,0,0,summa,0,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate9 and @varKSdEndDate9) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate9 and @varKSdEndDate9))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,0,0,0,0,summa,0,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate10 and @varKSdEndDate10) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate10 and @varKSdEndDate10))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL, REG, 0,0,0,0,0,0,0,0,0,0,summa,0
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate11 and @varKSdEndDate11) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate11 and @varKSdEndDate11))
	INSERT INTO @varKSTempTable (DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR,DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
	SELECT DEP, DEP_ACC, RBS_DEP, RBS_ACC, VKR, EKR, DOP_CL,REG, 0,0,0,0,0,0,0,0,0,0,0,summa
	from @varKSTableOborot
	where ((not INDATE is null and INDATE between @varKSdBegDate12 and @varKSdEndDate12) 
		or (INDATE is null and DATE_PROV between @varKSdBegDate12 and @varKSdEndDate12))
					
	
		INSERT INTO @varKSresTable(dep, dep_acc, rbs_dep, rbs_acc, vkr, ekr, dop_cl, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
			SELECT f.dep, F.DEP_ACC, f.rbs_dep, f.rbs_acc, F.vkr, F.ekr, F.dop_cl, F.REG,  
			sum(F.p1) * @varKSintSumType as p1,
			sum(F.p2) * @varKSintSumType as p2, 
			sum(F.p3) * @varKSintSumType as p3, 
			sum(F.p4) * @varKSintSumType as p4, 
			sum(F.p5) * @varKSintSumType as p5, 
			sum(F.p6) * @varKSintSumType as p6, 
			sum(F.p7) * @varKSintSumType as p7, 
			sum(F.p8) * @varKSintSumType as p8, 
			sum(F.p9) * @varKSintSumType as p9, 
			sum(F.p10) * @varKSintSumType as p10, 
			sum(F.p11) * @varKSintSumType as p11, 
			sum(F.p12) * @varKSintSumType as p12
			from @varKSTempTable F 
			group by dep, DEP_acc, rbs_dep, rbs_acc, vkr, ekr, dop_cl, REG
END 	

IF @varKSintTypePer = 1 or @varKSintTypePer > 10
	UPDATE @varKSResTable
		SET p1 = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12,
		p2 = 0,	p3 = 0,	p4 = 0,	p5 = 0,	p6 = 0,	p7 = 0,	p8 = 0,	p9 = 0,	p10 = 0, p11 = 0, p12 = 0
IF @varKSintTypePer = 2
	UPDATE @varKSResTable
		SET p1 = p1 + p2 + p3, p2 = 0, p3 = 0,
		p4 = p4 + p5 + p6, p5 = 0, p6 = 0,
		p7 = p7 + p8 + p9, p8 = 0, p9 = 0,
		p10 = p10 + p11 + p12, p11 = 0, p12 = 0

RETURN
END




GO


GRANT SELECT ON dbo.[FB_REST_FINANS_DEP] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[ku_EmplExpirTable]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[ku_EmplExpirTable]

GO


/*
© Кейсистемс (Keysystems), 2005
*/

CREATE       FUNCTION dbo.ku_EmplExpirTable (
	@empl_link int,
	@Date datetime = null, 
	@mode int=0 
)  
RETURNS @R TABLE (expir_link int, expir_code varchar(10), years INT, months INT, days INT)
AS  
BEGIN 

	DECLARE @result int, @nyears int, @nmonths int, @ndays int, @ndate datetime, @tdate datetime, @cstr varchar(7000), @fname varchar(20)
	DECLARE @T TABLE (expir_link int, expir_code varchar(10), date_begin datetime, date_end datetime, koeff numeric(4,1), years numeric(5,2), months numeric(5,2), days numeric(5,2), lastday int)
	DECLARE @R_TEMP TABLE (expir_link int, expir_code varchar(10), years numeric(6,2), months numeric(6,2), days numeric(6,2))

	SELECT @date = dis_date FROM item_dis_face WHERE empl_link=@empl_link and active=1 and dis_date<@date

	SELECT @tdate = WORKDATE FROM USER_INFO
	IF @Date is null
		SELECT @Date = dbo.kd_DateBeginWork(@empl_link, @tdate)-1

	IF @mode=1
		INSERT @T
		SELECT e.link, e.code, o.date_begin, case when o.date_end<@Date then o.date_end else @Date end,
			o.koef, 0, 0, 0, 0
		FROM expir e
			left join (select ok.expir_link, ok.koef, eo.date_begin, eo.date_end, eo.empl_link
					from oldwork_koef ok left join empl_oldwork eo on ok.oldwork_link=eo.link
					where eo.date_begin<=@Date and eo.empl_link=@empl_link) o
			on o.expir_link=e.link

	INSERT @T
	SELECT mk.expir_link, e.code, date_begin, 
		case when date_end>@Date then @Date else date_end end,
		mk.koef, 0, 0, 0, 0
	FROM ku_only_moves im
		left join move_koef mk on mk.move_link=im.link
		left join expir e on mk.expir_link=e.link
	WHERE im.empl_link=@empl_link and im.date_begin<=@Date --and im.active=1

	UPDATE @T SET 
		years = year(date_end+1) - year(date_begin),
		months = month(date_end+1) - month(date_begin),
		days = day(date_end+1) - day(date_begin),
		lastday = 30/*datepart(day, dbo.DateBeginOfMonth(date_end+1) - 1)*/
				  /*case	when month(date_begin) = 2 then 30
						else datepart(day, dbo.DateBeginOfMonth(date_end+1) - 1)
				  end*/

	UPDATE @T SET years = convert(int, years), months = months + (years-convert(int, years)) * 12
	UPDATE @T SET months = convert(int, months), days = days + (months-convert(int, months)) * lastday
	UPDATE @T SET months = months - 1, days = days + lastday WHERE days<0
	UPDATE @T SET years = years - 1, months = months + 12 WHERE months<0

	IF @mode=0
		INSERT INTO @T (expir_link, expir_code, years, months, days, koeff)
		SELECT ee.expir_link, e.code, ee.years, ee.months, ee.days, 1
		FROM empl_expir ee LEFT JOIN expir e ON ee.expir_link=e.link
		WHERE empl_link = @empl_link

	INSERT @R_TEMP
	SELECT expir_link, expir_code, isnull(sum(years*koeff), 0), isnull(sum(months*koeff), 0), isnull(sum(days*koeff), 0)
	FROM @T GROUP BY expir_link, expir_code

	UPDATE @R_TEMP SET months = months + case when convert(int, years) != 0 then 12*(years - convert(int, years)) else 12*years end, years = convert(int, years)
	UPDATE @R_TEMP SET days = days + case when convert(int, months) != 0 then 30*(months - convert(int, months)) else 30*months end, months = convert(int, months)

	WHILE exists(SELECT * FROM @R_TEMP WHERE days>=30)
		UPDATE @R_TEMP SET days = days - 30, months = months + 1 WHERE days>=30

	WHILE exists(SELECT * FROM @R_TEMP WHERE months>=12)
		UPDATE @R_TEMP SET months = months - 12, years = years + 1 WHERE months>=12
	
	INSERT INTO @R
	SELECT * FROM @R_TEMP

	RETURN			
				
END


GO


GRANT SELECT ON dbo.[ku_EmplExpirTable] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[DOCUMENTS_ADD_ARCHE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[DOCUMENTS_ADD_ARCHE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE       VIEW dbo.DOCUMENTS_ADD_ARCHE
AS

SELECT
	[LINK]			= S.LINK,
	[NUMBER]		= S.NUMBER,
	[DATE]			= S.[DATE],
	[COMMENTARY]		= S.[COMMENTARY],
	[CODE_PAY]		 =P.CODE,
	[NAME_PAY]	 	= P.NAME,
	[REF_PAY]		= SD.LINK_PAY,
	[FLAG_JC]		= S.FLAG_JC,
	[TAB_NUMER]	 	= E.TAB,
	[NAME_EMPL]	 	= dbo.sd_GetEmplName(SD.LINK_EMPL),
	[REF_EMPL] 		= SD.LINK_EMPL,
	E.SYST_PAY,
	[SUMMA]			= COALESCE(SUM(ST.SUMMA),0),
	[SR_PREM]		= SD.SR_PREM,
	[TYP_PERIOD]		= SD.TYP_PERIOD,
	[DATE1]			= DIS.DATE1,
	[DATE2]			= DIS.DATE2,
	[DATE_BEGIN]		= SD.DATE_BEGIN,
	[LIMIT]			= SD.LIMIT,
	[PER_ARHE]		= DIS.DATE,
	[NUM_ARHE]		= DIS.NUMBER,
	[REF_ARHE]		= SD.REF_DOC,
	[CODE_TYP_ARHE]		= DIS.CODE_TYP_ARHE,
	[NAME_TYP_ARHE]		= COALESCE(DIS.NAME_TYP_ARHE,''),
	[REF_TYP_ARHE]		= DIS.REF_TYP_ARHE,
	[STAG]			= DIS.NEPR_YEAR,
	[STAG_MONTH]		= DIS.NEPR_MONTH,
	[SUMMA_BASE0]		= SD.SR_ZAR,
	[SUMMA_BASE1]		= ROUND(SD.SR_ZAR,2,0),
	[LINK_DEP]  		= S.LINK_DEP,
	RAB_SUM			= COALESCE(SUM(CASE WHEN COALESCE(PAYER,0) = 1 then ST.SUMMA else 0 end),0),
	RAB_DAYS		= COALESCE(SUM(CASE WHEN COALESCE(PAYER,0) = 1 then ST.DAYS else 0 end),0),
	FSS_SUM			= COALESCE(SUM(CASE WHEN COALESCE(PAYER,0) = 0 then ST.SUMMA else 0 end),0),
	FSS_DAYS		= COALESCE(SUM(CASE WHEN COALESCE(PAYER,0) = 0 then ST.DAYS else 0 end),0),
	DOHOD			= COALESCE((Select SUM(T3.SUMMA1) + SUM(T3.SUMMA2) + SUM(T3.SUMMA3) 
					+ SUM(T3.SUMMA4) + SUM(T3.SUMMA5) + SUM(T3.SUMMA6) 
					+ SUM(T3.SUMMA7) + SUM(T3.SUMMA8) + SUM(T3.SUMMA9) 
					+ SUM(T3.SUMMA10) + SUM(T3.SUMMA11) + SUM(T3.SUMMA12)
				FROM dbo.SDOC_ADIS_TABLE3 T3  WHERE LINK_UP = S.LINK),0),
	ITOGO_DNI 		= COALESCE(SUM(ST.DAYS),0),
	ITOGO_CH 		= COALESCE(SUM(ST.HOURS),0),
	RP_DAYS			= COALESCE(MAX(T2.DAYS),0),
	RP_HOURS		= COALESCE(MAX(T2.HOURS),0),
	RP_DAYS_N		= COALESCE(MAX(T2.DAYS_N),0),
	RP_HOURS_N		= COALESCE(MAX(T2.HOURS_N),0),
	RP_SUMMA_PREM		= COALESCE(MAX(T2.SUMMA_PREM),0),
	RP_SUMMA		= COALESCE(MAX(T2.SUMMA),0),
	DIS.DEKRET,
	dep.NAME as name_dep,
	STARUS = EI.[status],
	STATUSC = CASE EI.[status] WHEN 1 THEN 'Основной' WHEN 2 THEN 'Совместитель' ELSE 'Вн. совместитель' END,
	SD.INSTRUCT,
	--Начало расчетного периода в случае наличия завяления на замену расчетного периода
	BEGIN_RP = MIN(CASE WHEN C.YEAR1 IS NULL THEN NULL ELSE dbo.ConvertDMY2Date(1,1,dbo.IS_MIN(C.YEAR1, C.YEAR2)) END)
FROM 
	dbo.SDOC S 
	INNER JOIN dbo.SDOC_ADIS SD ON (S.LINK = SD.LINK_UP AND S.OBJECT =(SELECT LINK FROM S_OBJECTS WHERE CODE = 'DOCUMENTS_ADD_ARCHE'))
	INNER JOIN dbo.PAYS P ON SD.LINK_PAY = P.LINK
	INNER JOIN dbo.EMPL E ON E.LINK = SD.LINK_EMPL 
	INNER JOIN dbo.SA_EMPLS_INFO(DEFAULT, DEFAULT) EI ON EI.empl_link = E.LINK
	INNER JOIN dbo.DEPARTMENTS dep ON dep.link = s.LINK_DEP
	LEFT JOIN dbo.DIS ON SD.REF_DOC = DIS.LINK
	left join (
		Select LINK_UP, DATE1, PAYER = MAX(PAYER), DAYS = MAX(T1.DAYS), HOURS = MAX(T1.HOURS), SUMMA = SUM(T1.SUMMA) from dbo.SDOC_ADIS_TABLE1 T1 GROUP BY LINK_UP, DATE1
		) ST on ST.LINK_UP = S.LINK
	LEFT JOIN (
		SELECT LINK_UP, SUMMA = SUM(SUMMA), SUMMA_PREM = SUM(SUMMA_PREM), 
			 DAYS = SUM(DAYS), HOURS = SUM(HOURS), DAYS_N = SUM(DAYS_N), HOURS_N = SUM(HOURS_N) 
		FROM (
			Select LINK_UP, PERIOD, SUMMA = SUM(SUMMA), SUMMA_PREM = SUM(SUMMA_PREM), 
			 DAYS = MAX(DAYS), HOURS = MAX(HOURS), DAYS_N = MAX(DAYS_N), HOURS_N = MAX(HOURS_N) 
			from dbo.SDOC_ADIS_TABLE2 GROUP BY LINK_UP, PERIOD) T2_1 
		GROUP BY LINK_UP ) T2 ON T2.LINK_UP = S.LINK
	LEFT JOIN dbo.VAC_PERIOD_CHANGE C ON C.LINK_EMPL = SD.LINK_EMPL AND DIS.DATE1 BETWEEN C.DATE1 AND C.DATE2
group by
	S.link, S.NUMBER, S.[DATE], S.[COMMENTARY], P.CODE, P.[NAME], SD.LINK_PAY, SD.INSTRUCT, S.FLAG_JC, E.TAB, SD.LINK_EMPL, E.SYST_PAY,
	S.SUMMA_T, SD.SR_PREM, SD.TYP_PERIOD, DIS.DATE1, DIS.DATE2, SD.DATE_BEGIN, SD.LIMIT, DIS.[DATE], DIS.NUMBER,
	SD.REF_DOC, DIS.CODE_TYP_ARHE, DIS.NAME_TYP_ARHE, DIS.REF_TYP_ARHE, DIS.NEPR_YEAR, DIS.NEPR_MONTH, SD.SR_ZAR, S.LINK_DEP,DIS.DEKRET,dep.NAME,EI.[status]
GO


GRANT SELECT ON dbo.[DOCUMENTS_ADD_ARCHE] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_EMPL]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW dbo.[SD_EMPL]

GO

CREATE VIEW [dbo].[SD_EMPL]  AS 
SELECT * FROM dbo.SD_EMPL_FN( default, default, default, default)

GO


GRANT SELECT ON dbo.[SD_EMPL] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_RestSaldoForLedgerByDate1]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BB_RestSaldoForLedgerByDate1]

GO

/*Возвращает остатки по субсчету на  дату
Для Главной книги
Бочкарев Е.Ю.
*/
CREATE FUNCTION dbo.BB_RestSaldoForLedgerByDate1 (@Date datetime, @Account int = null, @KBK int = 1)
RETURNS TABLE
AS
RETURN
	SELECT 
		T1.ACCOUNT,
		T1.SGU,
		T1.KBK,
		T1.KAU,
		D_SUMMA = SUM (T1.D_SUMMA),
		K_SUMMA = SUM (T1.K_SUMMA),
		T1.DEP_LINK
	FROM (
		SELECT 
			TTT.ACCOUNT,
			CASE
				WHEN @KBK = 1 OR @KBK = 2 THEN TTT.SGU
				ELSE NULL
			END AS SGU,
			CASE
				WHEN @KBK = 1 THEN TTT.KBK
				ELSE NULL
			END AS KBK,
			TTT.KAU,
			TTT.D_SUMMA,
			TTT.K_SUMMA,
			TTT.DEP_LINK
		FROM dbo.ARestTableByDate (@DATE, @ACCOUNT) TTT
		)AS T1
	GROUP BY
		T1.ACCOUNT,
		T1.SGU,
		T1.KBK,
		T1.KAU,
		T1.DEP_LINK

GO


GRANT SELECT ON dbo.[BB_RestSaldoForLedgerByDate1] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[CalcNalogBalanceOS]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[CalcNalogBalanceOS]
GO

--- Функция вычисляет объекты для налога на имущества ---
CREATE         FUNCTION dbo.CalcNalogBalanceOS (@dDate DATETIME = NULL, @intDepLink INT = NULL)
-- Если @intDepLink = NULL то расчет без учета DEP_LINK, т.е. для всех организаций
RETURNS @varKSOUT_TABLE TABLE
	(	DEP_LINK	INT,
		[ACCOUNT] [INT],
		[GRP_CODE] [CHAR] (8) NOT NULL,
		[INV]	[INT] NOT NULL,
		[OST_SUM] [NUMERIC] (20,2) NULL,
		[BALANS] [NUMERIC] (20,2) NULL,
		[AMORT] [NUMERIC] (20,2) NULL,
		[NO_NALOG] BIT NOT NULL,
		[DATE_BEGIN] DATETIME NULL
	)
AS
BEGIN
	DECLARE
		@AMORT_FULL NUMERIC (28,2),
		@DATE_BEGIN	DATETIME,
		@intNOT_USE_NASTR	INT,
		@intACCOUNT	INT,
		@dDATE_REST	DATETIME,
		@YEAR_CALC	INT

	IF @dDate IS NULL
		SELECT @dDate = WORKDATE FROM dbo.USER_INFO

	SET @intNOT_USE_NASTR = ISNULL (dbo.XK_GET_NASTR_INT ('XK_NASTR_ND_AV_ASS_ALL_OS'), 0)
	
	IF @intNOT_USE_NASTR = 0
	BEGIN
		SELECT @AMORT_FULL = dbo.BK_GET_AMORT_FULL_TAX (@dDate)

		SELECT @DATE_BEGIN = MAX (DATE_BEGIN) FROM dbo.AMORT_FULL_TAX T2
		WHERE T2.DATE_BEGIN <= @dDate
	END
		ELSE 
			SET @AMORT_FULL = 0

	SET @YEAR_CALC = YEAR (@dDate) 

	---	Изменения в НК в 2013 (с учетом изменеий в 2014) ---
	DECLARE @TAB_INPUT_INV TABLE
		(INV	INT,
		DEP_LINK	INT
		)

	IF @YEAR_CALC >= 2013 AND @YEAR_CALC < 2015
		INSERT INTO @TAB_INPUT_INV
		SELECT
			T1.INV,
			T1.DEP_LINK
		FROM dbo.BK_GetTableOperINV
			(DEFAULT,
			'20130101',
			@dDATE,
			2,
			@intDepLink) T1
		INNER JOIN dbo.INVENTORY INV ON (INV.LINK = T1.INV)	
		INNER JOIN dbo.NOMENCLATURE NOMEN ON (NOMEN.LINK = INV.NOMENCLATURE)	
		INNER JOIN dbo.GROUP_INV GRA ON (GRA.LINK = NOMEN.GROUP_INV
			AND GRA.CODE LIKE '101[2-3]%')	
		GROUP BY
			T1.INV,
			T1.DEP_LINK

	SET @dDATE_REST	= @dDate

	-- Балансовая стоимость --
	DECLARE @T_BALANS TABLE
		(
		DEP_LINK	INT,
		ACCOUNT		INT,
		INV			INT,
		BALANS		NUMERIC (28,4),
		QTY			NUMERIC (28,4)
		)

	SELECT
		@intACCOUNT = LINK
	FROM dbo.S_ACCOUNTS
	WHERE CODE = '101'	

	INSERT INTO @T_BALANS 
		(
		DEP_LINK,
		ACCOUNT,
		INV,
		BALANS,
		QTY
		)
	SELECT
		T1.DEP_LINK,
		T1.ACCOUNT,
		ISNULL (T1.INV, 0),
		SUM (T1.D_SUMMA),
		SUM (T1.D_QUANTITY)
	FROM dbo.ARestTableByDate (@dDATE_REST, @intACCOUNT) T1
	WHERE
		(@intDepLink IS NULL OR @intDepLink IS NOT NULL AND T1.DEP_LINK = @intDepLink)
		AND (@YEAR_CALC >= 2013 AND @YEAR_CALC < 2015
				AND NOT EXISTS (SELECT * FROM @TAB_INPUT_INV TTT WHERE TTT.INV = T1.INV)
			OR @YEAR_CALC < 2013
			OR @YEAR_CALC > 2014
			)
	GROUP BY
		T1.DEP_LINK,
		T1.ACCOUNT,
		ISNULL (T1.INV, 0)

	-- Амортизация --
	DECLARE @T_AMORT TABLE
		(
		DEP_LINK	INT,
		ACCOUNT		INT,
		INV			INT,
		SUMMA		NUMERIC (28,4)
		)

	SELECT
		@intACCOUNT = LINK
	FROM dbo.S_ACCOUNTS
	WHERE CODE = '104'	

	INSERT INTO @T_AMORT 
		(
		DEP_LINK,
		ACCOUNT,
		INV,
		SUMMA
		)
	SELECT
		T1.DEP_LINK,
		T1.ACCOUNT,
		ISNULL (T1.INV, 0),
		SUM (T1.K_SUMMA)
	FROM dbo.ARestTableByDate (@dDATE_REST, @intACCOUNT) T1
	WHERE
		(@intDepLink IS NULL OR @intDepLink IS NOT NULL AND T1.DEP_LINK = @intDepLink)
		AND (@YEAR_CALC > 2012 AND @YEAR_CALC < 2015
				AND NOT EXISTS (SELECT * FROM @TAB_INPUT_INV TTT WHERE TTT.INV = T1.INV)
			OR @YEAR_CALC < 2013
			OR @YEAR_CALC > 2014
			)
	GROUP BY
		T1.DEP_LINK,
		T1.ACCOUNT,
		ISNULL (T1.INV, 0)

	--- !!!Результат!!! ---
	INSERT @varKSOUT_TABLE
		(DEP_LINK,
		ACCOUNT,
		INV,
		BALANS,
		GRP_CODE,
		NO_NALOG,
		DATE_BEGIN,
		AMORT,
		OST_SUM
		)
	SELECT
		T1.DEP_LINK,
		T1.ACCOUNT,
		ISNULL (T1.INV, 0),
		T1.BALANS,
		GRI.CODE,
		ISNULL(ASS.NO_TAX, 0),
		ASS.DATE_BEGIN,
		ISNULL (T2.SUMMA, 0),
		T1.BALANS - ISNULL (T2.SUMMA, 0)
	FROM @T_BALANS T1
	INNER JOIN dbo.INVENTORY INV ON (INV.LINK = T1.INV)	
	INNER JOIN dbo.NOMENCLATURE NOMEN ON (NOMEN.LINK = INV.NOMENCLATURE)	
	INNER JOIN dbo.GROUP_INV GRI ON (GRI.LINK = NOMEN.GROUP_INV)	
	LEFT JOIN dbo.ASSETS ASS ON (ASS.LINK_UP = INV.LINK)
	LEFT JOIN dbo.DEPRE_GROUP DGR ON (DGR.LINK = ASS.DEPRE_GROUP) 
	LEFT MERGE JOIN @T_AMORT T2 ON (T2.INV = T1.INV)
	WHERE
		(@intNOT_USE_NASTR = 0
			AND ASS.DATE_BEGIN <= @dDate
			AND (T1.BALANS <> 0
				AND (T1.QTY = 0 AND T1.BALANS > @AMORT_FULL
					OR T1.QTY <> 0
						AND ABS (T1.BALANS) > ABS (T1.QTY) * @AMORT_FULL
					))
			OR @intNOT_USE_NASTR = 1)
		AND (@YEAR_CALC < 2015
			OR @YEAR_CALC > 2014 AND ISNULL (DGR.CODE, '') NOT LIKE '0[1-2]'
			)	

	RETURN
END
GO


GRANT SELECT ON dbo.[CalcNalogBalanceOS] TO PUBLIC
GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[PrintDoc_GetDepData2]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[PrintDoc_GetDepData2]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE        FUNCTION dbo.PrintDoc_GetDepData2(@varKSnLinkDep INT)
RETURNS @varKSRET TABLE 
	(DEP_LINK INT, longname varchar (2000), ORGNAME VARCHAR(254), GLBUH VARCHAR(250),
		CHIEF VARCHAR(250), CHIEF_DIV VARCHAR(250), CHIEF_FIN VARCHAR(250), CHIEF_POST VARCHAR(120), okpo varchar(40),okato varchar(14), OKTMO VARCHAR(14),INN VARCHAR(12),
		sono char(4),REGION VARCHAR(254),
		OKVED VARCHAR (10), OKVED1 VARCHAR (10),DEP_FULL_NAME varchar(2000),VED varchar(3), VED_NAME VARCHAR(250),
        [isp] VARCHAR(250),
        [isp_post] VARCHAR(250),
        [isp_tel] VARCHAR(250),
        cb_name VARCHAR(250),
        cb_ogrn VARCHAR(250),
        cb_inn VARCHAR(250),
        cb_kpp VARCHAR(250),
        cb_address VARCHAR(250),
        ul_fio VARCHAR(250),
        ul_post VARCHAR(250))
AS BEGIN
	DECLARE @varKSGLBUH VARCHAR(250), @varKSCHIEF VARCHAR(250), @varKSCHIEF_POST VARCHAR(120),
		@boss_div varchar(250), @boss_fin_econ varchar(250)

	SELECT 
		@varKSGLBUH = GLBUH.SHORT_NAME
	FROM dbo.GetOtvFaceData(@varKSnLinkDep, 'Главный бухгалтер') GLBUH 
	WHERE GLBUH.link_dep = @varKSnLinkDep

	SELECT 
		@varKSCHIEF = CHIEF.SHORT_NAME,
		@varKSCHIEF_POST = CHIEF.POST_NAME
	FROM dbo.GetOtvFaceData(@varKSnLinkDep, 'Руководитель') chief 
	WHERE chief.link_dep = @varKSnLinkDep

	if isnull(@varKSGLBUH,'') = ''
	begin
		select @varKSGLBUH = BUH from report_dict_web_print where link_org = @varKSnLinkDep
	end

	if isnull(@varKSCHIEF,'') = ''
	begin
		select @varKSCHIEF = BOSS from report_dict_web_print where link_org = @varKSnLinkDep
	end

	select @boss_div = boss_div, @boss_fin_econ = boss_fin_econ
	from report_dict_web_print where link_org = @varKSnLinkDep

	INSERT INTO @varKSRET
	SELECT DD1.LINK,
		CONVERT(VARCHAR(254),DD1.FULL_NAME) AS FULL_NAME, CONVERT(VARCHAR(254),DD1.NAME) AS NAME,
		@varKSGLBUH,
		@varKSCHIEF,
		@boss_div,
		@boss_fin_econ,
		@varKSCHIEF_POST,
		DD1.OKPO,
		DD1.OKATO,
		DD1.OKTMO,
		DD1.INN,
		convert(varchar(4), DD1.NALOG),
		(SELECT RTRIM(LTRIM(NAME)) + ' ' + LTRIM(RTRIM(SOCR)) FROM DICTIONARY_KLADR WHERE CODE = LEFT(DD1.NALOG, 2) + REPLICATE('0', 11)),
		DD1.OKVED,
		REPLACE (DD1.OKVED, '.', ''),
        CONVERT(VARCHAR(2000),DD1.FULL_NAME),
        left(DD1.VED,3),
        DD1.[VED_NAME],
        W.[isp],
        W.[isp_post],
        W.[isp_tel],
        W.cb_name,
        W.cb_ogrn,
        W.cb_inn,
        W.cb_kpp,
        W.cb_address,
        W.ul_fio,
        W.ul_post
	FROM DICTIONARY_DEPARTMENT DD1 LEFT JOIN dbo.report_dict_web_print W ON DD1.[LINK] = W.[link_org]
	WHERE DD1.LINK = @varKSnLinkDep
	RETURN
   
END



GO


GRANT SELECT ON dbo.[PrintDoc_GetDepData2] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BV_ViborRestMz]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[BV_ViborRestMz]

GO

/*
© Кейсистемс (Keysystems), 2005
*/
-- Определить справочные записи можно по ACC_LINK = 0

CREATE	FUNCTION dbo.BV_ViborRestMz(@varKSDate DATETIME = NULL, @varKScTypeInv VARCHAR(30) = NULL)

RETURNS @varKSRES TABLE (LINK INT NOT NULL,
	CODE VARCHAR(20) NULL,
	[NAME] VARCHAR(80) NULL,
	SUMMA NUMERIC (28,2) NOT NULL,
	QUANTITY NUMERIC (28,4) NOT NULL,
	PRICE NUMERIC (28,6) NOT NULL,
	SOU_LINK INT,
	SOU_CODE VARCHAR(1),
	ACC_LINK INT NOT NULL,
	ACC_CODE VARCHAR(13) NOT NULL,
	EMP_LINK INT NULL, 
	EMP_FIO VARCHAR(100) NULL,
	UM_LINK INT NULL,
	UM_CODE CHAR(5) NULL,
	UM_NAME VARCHAR(30) NULL,
	DEP_LINK INT NOT NULL,
	ZABALANS TINYINT,
	PRICE_TYPE TINYINT DEFAULT (0),
	GRP_LINK	INT,
	GRP_CODE	VARCHAR (10))
AS
BEGIN
IF @varKSDate IS NULL
	SELECT @varKSDate = WORKDATE FROM USER_INFO

SET @varKSDate = @varKSDate + 1

IF @varKScTypeInv IS NULL
	SET @varKScTypeInv = 'BV_NOMENCLATURE'

--- Таблица остатков ---
DECLARE	@TABLE_REST TABLE (ACCOUNT INT,
			INV INT,
			NOMEN INT,
			TMC INT,
			EMP INT,
			DEP_LINK INT,
			PRICE_TYPE TINYINT,
			PRICE NUMERIC (28,4),
			QTY NUMERIC (28,4),
			SUMMA NUMERIC (28,4))

INSERT INTO @TABLE_REST
SELECT ART.ACCOUNT,
	ART.INV,
	ART.NOMEN,
	ART.TMC,
	ART.EMP,
	ART.DEP_LINK,
	ART.PRICE_TYPE,
	CASE
		WHEN ART.PRICE_TYPE = 1 THEN ART.PRICE
		ELSE 0
	END,
	SUM (ART.D_QUANTITY),
	SUM (ART.D_SUMMA)
FROM dbo.ARestTableByDate (@varKSDate, DEFAULT) ART
GROUP BY ART.ACCOUNT,
	ART.INV,
	ART.NOMEN,
	ART.TMC,
	ART.EMP,
	ART.DEP_LINK, 
	ART.PRICE_TYPE,
	CASE
		WHEN ART.PRICE_TYPE = 1 THEN ART.PRICE
		ELSE 0
	END
HAVING SUM(ART.D_SUMMA) <> 0
	OR SUM(ART.D_QUANTITY) <> 0 

UPDATE @TABLE_REST SET PRICE = CASE
					WHEN QTY <> 0 THEN SUMMA / QTY
					ELSE SUMMA
				END
WHERE PRICE = 0

IF @varKScTypeInv = 'BV_NOMENCLATURE'
	INSERT INTO @varKSRES (LINK, CODE,
		NAME, SUMMA, QUANTITY, PRICE,
		SOU_LINK, SOU_CODE,
		ACC_LINK, ACC_CODE, EMP_LINK,
		EMP_FIO, UM_LINK, UM_CODE,
		UM_NAME, DEP_LINK, ZABALANS, PRICE_TYPE,
		GRP_LINK, GRP_CODE)
	SELECT I.LINK, 
		CODE = CONVERT(VARCHAR(20), I.CODE), 
		[NAME] = CONVERT(VARCHAR(80), LEFT(I.[NAME],80)), 
		SUMMA = ISNULL (TR.SUMMA, 0),
		QUANTITY = ISNULL (TR.QTY, 0),
		PRICE = ISNULL (TR.PRICE, 0),

		FS.LINK,
		FS.CODE,

		ACC_LINK = ISNULL (SA.LINK, 0),
		ACC_CODE = ISNULL (SA.CODE, ''),
		EMP_LINK = ISNULL (TR.EMP, 0),
		EMP_FIO  = CONVERT(VARCHAR(100), dbo.sd_GetEmplName (TR.EMP)), 
		UM_LINK = CONVERT(INT,D.LINK),
		UM_CODE = CONVERT(CHAR(5),D.CODE),
		UM_NAME = CONVERT(VARCHAR(30),D.[NAME]),
		DEP_LINK = ISNULL (TR.DEP_LINK, 0),
		ZABALANS = ISNULL (SA.ZABALANS, 0),
		PRICE_TYPE = ISNULL (NF.PRICE_TYPE, 0),
		ISNULL (GR.LINK, 0),
		ISNULL (GR.CODE, '')
	FROM dbo.NOMENCLATURE I
	INNER JOIN dbo.GROUP_INV GR ON (GR.LINK = I.GROUP_INV)
	LEFT JOIN dbo.BK_GetNomenPriceFACT () NF ON (NF.LINK = I.LINK)
	LEFT JOIN dbo.DICTION D ON (D.LINK = I.UM)
	LEFT JOIN @TABLE_REST TR ON (TR.NOMEN = I.LINK)	
	LEFT JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = TR.ACCOUNT)	
	LEFT JOIN dbo.FIN_SOURCE FS ON (FS.CODE = SA.cSOURCE)
	ORDER BY I.CODE

IF @varKScTypeInv = 'INVENTORY_CARD'
	INSERT INTO @varKSRES (LINK, CODE,
		NAME, SUMMA, QUANTITY, PRICE,
		SOU_LINK, SOU_CODE,
		ACC_LINK, ACC_CODE, EMP_LINK,
		EMP_FIO, UM_LINK, UM_CODE,
		UM_NAME, DEP_LINK, ZABALANS, PRICE_TYPE,
		GRP_LINK, GRP_CODE)
	SELECT I.LINK, 
		CODE = CONVERT(VARCHAR(20), I.CODE), 
		[NAME] = CONVERT(VARCHAR(80), LEFT(I.[NAME],80)), 
		SUMMA = ISNULL (TR.SUMMA, 0),
		QUANTITY = ISNULL (TR.QTY, 0),
		PRICE = CASE
				WHEN ISNULL (TR.PRICE, 0) = 0 THEN ISNULL (I.COST, 0)
				ELSE TR.PRICE
			END, 
		FS.LINK,
		FS.CODE,

		ACC_LINK = ISNULL (SA.LINK, 0),
		ACC_CODE = ISNULL (SA.CODE, ''),
		EMP_LINK = ISNULL (TR.EMP, 0),
		EMP_FIO  = CONVERT(VARCHAR(100), dbo.sd_GetEmplName (TR.EMP)), 
		UM_LINK = CONVERT(INT, D.LINK),
		UM_CODE = CONVERT(CHAR(5), D.CODE),
		UM_NAME = CONVERT(VARCHAR(30), D.[NAME]),
		DEP_LINK = ISNULL (TR.DEP_LINK, 0),
		ZABALANS = ISNULL (SA.ZABALANS, 0),
		PRICE_TYPE = 0,
		ISNULL (GR.LINK, 0),
		ISNULL (GR.CODE, '')
	FROM dbo.INVENTORY I
	INNER JOIN dbo.NOMENCLATURE N ON (N.LINK = I.NOMENCLATURE)
	INNER JOIN dbo.GROUP_INV GR ON (GR.LINK = N.GROUP_INV)
	LEFT JOIN dbo.DICTION D ON (D.LINK = N.UM)
	LEFT JOIN @TABLE_REST TR ON (TR.INV = I.LINK)	
	LEFT JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = TR.ACCOUNT)	
	LEFT JOIN dbo.FIN_SOURCE FS ON (FS.CODE = SA.cSOURCE)
	ORDER BY I.CODE

IF @varKScTypeInv = 'DICTIONARY_TMC'
	INSERT INTO @varKSRES (LINK, CODE,
		NAME, SUMMA, QUANTITY, PRICE,
		SOU_LINK, SOU_CODE,
		ACC_LINK, ACC_CODE, EMP_LINK,
		EMP_FIO, UM_LINK, UM_CODE,
		UM_NAME, DEP_LINK, ZABALANS, PRICE_TYPE,
		GRP_LINK, GRP_CODE)
	SELECT I.LINK, 
		CODE = CONVERT(VARCHAR(16), I.CODE), 
		[NAME] = CONVERT(VARCHAR(80), LEFT(I.[NAME],80)), 
		SUMMA = ISNULL (TR.SUMMA, 0),
		QUANTITY = ISNULL (TR.QTY, 0),
		PRICE = CASE
				WHEN ISNULL (TR.PRICE, 0) = 0 THEN ISNULL (I.PRICE, 0)
				ELSE TR.PRICE
			END, 
		FS.LINK,
		FS.CODE,

		ACC_LINK = ISNULL (SA.LINK, 0),
		ACC_CODE = ISNULL (SA.CODE, ''),
		EMP_LINK = ISNULL (TR.EMP, 0),
		EMP_FIO  = CONVERT(VARCHAR(100), dbo.sd_GetEmplName (TR.EMP)), 
		UM_LINK = CONVERT(INT, I.REF_LINK_D),
		UM_CODE = CONVERT(CHAR(5), I.REF_CODE_D),
		UM_NAME = CONVERT(VARCHAR(30), I.REF_NAME_D),
		DEP_LINK = ISNULL (TR.DEP_LINK, 0),
		ZABALANS = ISNULL (SA.ZABALANS, 0),
		PRICE_TYPE = 0,
		0, ''
	FROM dbo.DICTIONARY_TMC I
	LEFT JOIN @TABLE_REST TR ON (TR.TMC = I.LINK)	
	LEFT JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = TR.ACCOUNT)	
	LEFT JOIN dbo.FIN_SOURCE FS ON (FS.CODE = SA.cSOURCE)
	ORDER BY I.CODE

RETURN
END






GO


GRANT SELECT ON dbo.[BV_ViborRestMz] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[PV_UnfoldDish]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[PV_UnfoldDish]

GO

CREATE          FUNCTION dbo.PV_UnfoldDish (@nDishLink INT)

RETURNS @varKSReturnTable TABLE (
	[LINK_NOM] [INT] NOT NULL,
	[NETTO] [NUMERIC] (19,4) NULL,
	[GROSS] [NUMERIC] (19,4) NULL)

AS 
BEGIN
	DECLARE @nTmpDishLink INT, @iNumber INT

	DECLARE @varTmpTable TABLE (LINK_NOM INT NOT NULL, NETTO NUMERIC(19,4) NULL, GROSS NUMERIC(19,4) NULL)

	DECLARE DISHS_IN_DISH CURSOR LOCAL STATIC READ_ONLY FOR
	SELECT	LINK_DISH, ISNULL(NUMBER,0) AS NUMBER FROM PA_RECIPE WHERE LINK_UP = @nDishLink AND TYPE = 2

	INSERT INTO @varTmpTable(LINK_NOM, NETTO, GROSS)
	SELECT	[LINK_NOM] = LINK_NOMENCLATURE, 
		[NETTO] = ISNULL(NETTO,0) * ISNULL(NUMBER,0),
		[GROSS] = ISNULL(GROSS,0) * ISNULL(NUMBER,0)
	FROM PA_RECIPE
	WHERE LINK_UP = @nDishLink AND TYPE = 1
	
	OPEN DISHS_IN_DISH
	FETCH NEXT FROM DISHS_IN_DISH INTO @nTmpDishLink, @iNumber
	
	WHILE @@FETCH_STATUS = 0
	BEGIN
		INSERT INTO @varTmpTable(LINK_NOM, NETTO, GROSS)
		SELECT LINK_NOM, NETTO * @iNumber, GROSS * @iNumber FROM dbo.PV_UnfoldDish(@nTmpDishLink)
		FETCH NEXT FROM DISHS_IN_DISH INTO @nTmpDishLink, @iNumber
	END
	CLOSE DISHS_IN_DISH
	DEALLOCATE DISHS_IN_DISH

	INSERT INTO @varKSReturnTable (LINK_NOM, NETTO, GROSS)
	SELECT LINK_NOM, SUM(NETTO), SUM(GROSS) FROM @varTmpTable GROUP BY LINK_NOM

	RETURN
END




GO


GRANT SELECT ON dbo.[PV_UnfoldDish] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[XU_GET_SYSOBJ_ORDER]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[XU_GET_SYSOBJ_ORDER]

GO
CREATE   PROCEDURE dbo.XU_GET_SYSOBJ_ORDER (@insert_script varchar(254) = NULL )
AS
Declare @NoScriptObjects table (ID int NOT NULL)
INSERT INTO @NoScriptObjects(ID)
SELECT id
FROM dbo.sysobjects 
Where name in ('syssegments', 'sysconstraints')
--------------------------------------------------------------------------
set nocount on
---Declare #Depends table (id1 bigint not null, id2 bigint not null)
CREATE TABLE #Depends (id1 bigint not null, id2 bigint not null)
CREATE INDEX #TMP_IDX_Depends1 ON #Depends (id1)
CREATE INDEX #TMP_IDX_Depends2 ON #Depends (id2)

Declare @ObjOrdered table (id bigint not null, name sysname, level int NULL, xtype char(2) not null)

if object_id('tempdb.dbo.#t2') is not null
	drop table #t2

create table #t2 (text varchar(8000), id int identity(1,1))

Declare @obj table (id bigint not null, xtype char(2), name nvarchar(128))
insert into @obj(id, xtype, name)
select id, xtype, object_name(id) as name
from dbo.sysobjects
where xtype in ('TF', 'FN', 'IF', 'V', 'TR')
and id not in (select id from @NoScriptObjects)
and objectproperty(id, 'IsMSShipped') = 0
order by object_name(id)

print 'Создание порядка объектов БД'
Declare @wet_depends table (id_wet bigint not null, depid_wet bigint not null)

declare alfa cursor local for select name from @obj where xtype <> 'P'
Declare @name sysname, @ID bigint, @Value sql_variant, @Text varchar(8000), @err int
open alfa
declare @str varchar(1000), @mytext varchar(8000), @pos int
FETCH NEXT FROM alfa into @name
WHILE @@FETCH_STATUS = 0
BEGIN
IF @name <> 'DB_USERS'
BEGIN

	truncate table #t2
	insert into #t2
	execute ssp_helptext @name

	SELECT TOP 1 @ID = id, @mytext = text from #t2 where text like '%CREATE%' ORDER BY ID
	SET @pos = PATINDEX('%CREATE%', @mytext)
	SET @mytext = LEFT(@mytext, @pos-1) + 'ALTER' + SUBSTRING(@mytext, @pos + 6, 8000)
	UPDATE #t2 set text = @mytext where ID = @ID 

	exec @err = dbo.ssp_execresultset 'select text from #t2 order by id'

	insert into @wet_depends(id_wet, depid_wet)
	select id, depid from dbo.sysdepends sd where sd.id = object_id(@name)

END
ELSE
BEGIN
	-- DB_USERS от dbo.sd_GetEmplName
	--execute sp_helptext @name
	insert into @wet_depends(id_wet, depid_wet)
	SELECT object_id('DB_USERS'), object_id('dbo.sd_GetEmplName')
END

FETCH NEXT FROM alfa into @name
END
close alfa
deallocate alfa

insert into #Depends(id1, id2)
	select distinct sd.id_wet, sd.depid_wet
	from @wet_depends sd, @obj so1, @obj so2
	where sd.id_wet = so1.id AND sd.depid_wet = so2.id

insert into @ObjOrdered(id, name, level, xtype)
select id, object_name(id), null, xtype
from @obj

--Исключения
UPDATE @ObjOrdered
SET level = 1
WHERE id IN (OBJECT_ID('DICTIONARY_STORAGE_DOCUMENTS'), OBJECT_ID('dbo.GetObjLink'))

declare @lev int
set @lev = 2

WHILE exists(select * from @ObjOrdered where level is null)
BEGIN

	update @ObjOrdered
	set level = @lev
	where level is null
		and not exists(select * from #Depends sd where sd.id1 = id)

	IF not exists(select * from @ObjOrdered where level = @lev)
	BEGIN
		set @ID = null
		select top 1 @ID = id
		from @ObjOrdered s
		where level is null
			and exists(select * from #Depends sd where sd.id1 = s.id)
			and exists(select * from #Depends sd where sd.id2 = s.id)
			and xtype IN ('FN', 'TF', 'IF')
		order by (select count(*) from #Depends sd where sd.id1 = s.id or sd.id2 = s.id)
		
		update @ObjOrdered set level = @lev where id = @ID

	END

	delete from #Depends where id1 in (select id from @ObjOrdered where level = @lev)

	delete from #Depends where id2 in (select id from @ObjOrdered where level = @lev)

	set @lev = @lev + 1

	if @lev = 100 begin --Чтобы не зависал
--		select * from @ObjOrdered where level IS NULL
		update @ObjOrdered set level = @lev where level IS NULL
	end	
END

DELETE FROM @ObjOrdered
WHERE id in (SELECT id FROM @NoScriptObjects)

IF @insert_script is not null begin

	SELECT * INTO #TMP1 FROM @ObjOrdered

	DECLARE @SQL VARCHAR(2000)
	SET @SQL = @insert_script + ' 
	SELECT *, convert(bit, 0) as inSP FROM #TMP1
	UNION ALL
	SELECT id, name, ' + CONVERT(VARCHAR(10),@lev) + ', xtype, convert(bit, 0) FROM sysobjects WHERE xtype=''P''
	ORDER BY level	'

	exec (@SQL)
end
else
	SELECT *, convert(bit, 0) as inSP FROM @ObjOrdered
	UNION ALL
	SELECT id, name, @lev, xtype, convert(bit, 0) FROM sysobjects WHERE xtype='P'
	ORDER BY level

print 'Готово'

GO


GRANT EXECUTE ON dbo.[XU_GET_SYSOBJ_ORDER] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_CALC_TABLE_INVENTORY_DBKT]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_CALC_TABLE_INVENTORY_DBKT]
GO

CREATE PROCEDURE dbo.BK_CALC_TABLE_INVENTORY_DBKT
	@intDepLink	INT = NULL,
	@dDateCalc	DATETIME	= NULL,
	@intDB_KT	INT	= 0,
	@strBufferAcct	VARCHAR (100) = ''
AS
BEGIN
	IF @dDateCalc IS NULL 
		SELECT @dDateCalc = WORKDATE FROM dbo.USER_INFO
	SET @dDateCalc = DATEADD (DAY, 1, @dDateCalc)

	SET @intDB_KT = ISNULL (@intDB_KT, 0)

	IF @intDepLink IS NULL
		SET @intDepLink = dbo.GetOwnDepLink ()

	-- Отбор субсчетов --
	DECLARE @TABLE_ACCT TABLE
		(LINK INT)
	
	IF @strBufferAcct = ''
		INSERT INTO @TABLE_ACCT
		SELECT 
			T1.LINK
		FROM dbo.FT_ALL_SA_NASTR_DOC (dbo.GetObjLink ('DOCUMENTS_INVENTORY_DBKT'), @intDB_KT)	T1
		GROUP BY
			T1.LINK
	ELSE
	BEGIN
		INSERT INTO @TABLE_ACCT
		SELECT
			T1.LINK
		FROM dbo.BufferGetTableByID (@strBufferAcct) T1 
		GROUP BY
			T1.LINK

		EXEC dbo.BufferClear @strBufferAcct
	END

	-- Выборка данных --  
	SELECT
		T.ACCOUNT AS ACC_LINK,
		SA.CODE AS ACC_CODE,
		SA.cSINTH AS ACC_SINTH,
		SA.cANALIT AS ACC_AN,
		SA.[NAME] AS ACC_NAME,
		SA.cSOURCE AS CODE_SOU,
		T.DEP AS DEP_LINK,
		ISNULL (D.CODE, '') AS DEP_CODE,
		ISNULL (D.[NAME], '') AS DEP_NAME,
		T.SUMMA AS SUMMA_ALL
	FROM
		(SELECT
			REST.ACCOUNT,
			REST.DEP,
			SUMMA = SUM (REST.D_SUMMA + REST.K_SUMMA)
		FROM dbo.ARestTableByDate (@dDateCalc, DEFAULT) REST
		INNER JOIN @TABLE_ACCT AC ON (AC.LINK = REST.ACCOUNT)
		WHERE REST.DEP_LINK = @intDepLink
		GROUP BY
			REST.ACCOUNT, REST.DEP
		) AS T
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = T.ACCOUNT)
	LEFT JOIN dbo.DEPARTMENTS D ON (D.LINK =T.DEP)
	ORDER BY
		SA.CODE,
		D.[NAME]
END
GO

GRANT EXECUTE ON dbo.[BK_CALC_TABLE_INVENTORY_DBKT] TO PUBLIC
GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BA_SAVE_G_PROV1_CHARGE_MP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BA_SAVE_G_PROV1_CHARGE_MP]

GO
/*******************************************************************************

	© Кейсистемс (Keysystems), 2006

*******************************************************************************/
-- Процедура сохранения записей в таблице ОПЕРАЦИЙ (G_PROV1).
CREATE PROCEDURE dbo.[BA_SAVE_G_PROV1_CHARGE_MP]
   @iG_PROV_LINK INT = NULL, -- Поле LINK_DOC.
   @tDel         INT = 0     -- 1- Признак удаления существующих проводок данного документа, 0 - иначе.
AS
DECLARE
	@liRowCount     INT, -- Число обработанных строк.
	@liError        INT, -- Код ошибки.
	@liReturn       INT, -- Возвращаемый код ошибки (0 - нет ошибок).

	@liLINK_INV     INT,      -- Ссылка на ИНВЕНТАРЬ.
	@liLINK_NOMEN   INT,      -- Ссылка на НОМЕНКЛАТУРУ.
	@ldDATE         DATETIME, -- Дата проводок.
	@liDEP_LINK     INT,      -- Ссылка на организацию.
	@liMOL_LINK_KT  INT,      -- Ссылка на МОЛ в кредитовом счете.


	@liORDERS        INT,         -- Номер операции по порядку.
	@liLINK_G_PROV1  INT,         -- Ссылка на операцию.
	@lvcNameOper     VARCHAR(50), -- Название текущей операции.


	@lvcTYPE      VARCHAR(30),   -- Поле INV_TYPE. |
	@liLINK       INT,           -- Поле INV_LINK. |
	@lvcCODE      VARCHAR(20),   -- Поле INV_CODE. | BA_VIEW_MP_CHARGE_TABLE
	@lnQTY        NUMERIC(12,4), -- Поле QTY.      |

	@liTO         INT,         -- Ссылка на текущую типовую операцию (в цикле).
	@lvcTO        VARCHAR(60), -- Наименование текущей типовой операции (в цикле).
	@liTO_INV     INT,         -- Cсылка на типовую операцию для ИНВЕНТРАРЯ.
	@liTO_NOMEN   INT,         -- Cсылка на типовую операцию для НОМЕНКЛАТУРЫ.
	@lvcTO_INV    VARCHAR(60), -- Наименование типовой операции для ИНВЕНТАРЯ.
	@lvcTO_NOMEN  VARCHAR(60),  -- Наименование типовой операции для НОМЕНКЛАТУРЫ.
	@OTR_LINK	INT,
	@ACCOUNT	INT,
	@SUMMA	NUMERIC (28,4)

SET IMPLICIT_TRANSACTIONS OFF  -- Режим явного определения транзакций.
SET LOCK_TIMEOUT 3000          -- Время ожидания разблокировки ресурсов 3 сек.
PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Вход.'

DECLARE curBA_MP_CHARGE_TABLE CURSOR LOCAL STATIC READ_ONLY FOR
	SELECT
		LINK,
		[INV_TYPE], 
		[INV_LINK],
		[INV_CODE], 
		ACCOUNT,		
		[QTY],
		SUMMA
	FROM dbo.[BA_SELECT_MP_CHARGE_TABLE](@iG_PROV_LINK)
	WHERE [LINK_UP] = @iG_PROV_LINK

-- Проверка ссылки на ДОКУМЕНТ.
IF @iG_PROV_LINK IS NULL OR 
   @iG_PROV_LINK <= 0
BEGIN
	PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Не задана ссылка на документ.'
	PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки -1.'
	RETURN -1 -- Возврат кода ошибки.
END

BEGIN TRANSACTION -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

   -- Удаление существующих проводок, если нужно.
   IF @tDel = 1 
   BEGIN
   	DELETE 
      FROM dbo.[G_PROV1]
      WHERE [LINK_UP] = @iG_PROV_LINK

   	IF @@ERROR <> 0 
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Ошибка при удалении старых проводок.'
         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки 2.'
   		RETURN -6 -- Возврат кода ошибки.
   	END
   END

   -- Определение ТИПОВЫХ ОПЕРАЦИЙ для НОМЕНКЛАТУРЫ и ИНВЕНТАРЯ.
	SELECT
		@liTO_NOMEN  = [TYP_LINK_1],
		@liTO_INV    = [TYP_LINK_2], 
		@lvcTO_NOMEN = [TYP_NAME_1],
		@lvcTO_INV   = [TYP_NAME_2]
	FROM dbo.[BA_DOC_MP_CHARGE_OPTIONS]

   -- Ошибки, если типовые операции для используемых в проводках МЦ не заданы
   IF @liTO_NOMEN IS NULL AND
      EXISTS(SELECT *
             FROM dbo.[BA_SELECT_MP_CHARGE_TABLE](@iG_PROV_LINK)
             WHERE [LINK_UP] = @iG_PROV_LINK AND
                   [INV_TYPE] = 'BV_NOMECLATURE')
   BEGIN
   	ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
      COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
      PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Не задана типовая операция для номенклатуры.'
      PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки -9.'
		RETURN -9 -- Возврат кода ошибки.
   END

   IF @liTO_INV IS NULL AND
      EXISTS(SELECT *
             FROM dbo.[BA_SELECT_MP_CHARGE_TABLE](@iG_PROV_LINK)
             WHERE [LINK_UP] = @iG_PROV_LINK AND
                   [INV_TYPE] = 'INVENTORY_CARD')
   BEGIN
   	ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
      COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
      PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Не задана типовая операция для инвентаря.'
      PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки -10.'
		RETURN -10 -- Возврат кода ошибки.
   END

   -- Определение даты и организации 
   SELECT @ldDATE     = [G].[DATE] + 1,
          @liDEP_LINK = [G].[DEP]
   FROM dbo.[G_PROV] [G]
   WHERE [G].[LINK] = @iG_PROV_LINK

   -- Определение МОЛ проводок.
   SELECT @liMOL_LINK_KT = [EMPL]
   FROM dbo.[G_PROV_EMPL] 
   WHERE [DOC_LINK] = @iG_PROV_LINK AND
         [OBJECT]   = dbo.[XA_GET_SO_LINK]('BA_DOC_MP_CHARGE_MOL_LINK')


/*
   SELECT @liMOL_LINK_KT = [E].[EMPL]
   FROM dbo.[G_PROV] [G] 
   LEFT JOIN dbo.[G_PROV_EMPL] [E] ON [G].[LINK]   = [E].[DOC_LINK]
   LEFT JOIN dbo.[S_OBJECTS]   [O] ON [E].[OBJECT] = [O].[LINK]
   WHERE [G].[LINK] = @iG_PROV_LINK AND
         [O].[CODE] = 'MP_CHARGE_MOL_LINK'

*/


   OPEN curBA_MP_CHARGE_TABLE -- Открытие курсора с МЦ документа.

   -- Выборка очередного МЦ документа.
   FETCH NEXT 
   FROM curBA_MP_CHARGE_TABLE
   INTO @OTR_LINK,
		@lvcTYPE,
        @liLINK,
        @lvcCODE,
        @ACCOUNT,
        @lnQTY,
        @SUMMA


   SET @liORDERS = 0

   WHILE @@FETCH_STATUS = 0
   BEGIN
      IF @lvcTYPE = 'BV_NOMENCLATURE'
      BEGIN
         SELECT @lvcNameOper  = 'Номен.№',
                @liTO         = @liTO_NOMEN,
                @lvcTO        = @lvcTO_NOMEN,
                @liLINK_NOMEN = @liLINK,
                @liLINK_INV   = NULL
      END                
      ELSE BEGIN
         SELECT @lvcNameOper  = 'Инв.№',
                @liTO         = @liTO_INV,
                @lvcTO        = @lvcTO_INV,
                @liLINK_NOMEN = NULL,
                @liLINK_INV   = @liLINK
      END

      SELECT @liORDERS    = @liORDERS + 1,
             @lvcNameOper = LTRIM(RTRIM(ISNULL(@lvcTO,'Операция'))) + ' '+ 
                            @lvcNameOper + ' "' + LTRIM(RTRIM(@lvcCODE)) + '"',
             @liLINK_G_PROV1 = NULL
      
	   EXEC dbo.[XA_UPDATE_G_PROV1] @liLINK_G_PROV1 OUTPUT, 
                                   @iG_PROV_LINK, 
                                   @liTO, 
                                   @lvcTO, 
                                   @liORDERS

   	IF @liLINK_G_PROV1 IS NULL
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Ошибка при формировании операции.'
         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки -3.'
   		RETURN -3 -- Возврат кода ошибки.
      END

   	EXEC @liReturn = dbo.[BA_SAVE_G_PROV2_CHARGE]
   			@iG_PROV_LINK,
			@liLINK_G_PROV1, 
			@ldDATE,
			@liTO,                                              
			@liLINK_NOMEN,   
			@liLINK_INV,
			NULL,
			@liDEP_LINK,
			@lnQTY,
			@liMOL_LINK_KT,
			0,
			@SUMMA,
			@ACCOUNT
                        
      IF @liReturn <> 0 
      BEGIN
         ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.

         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Ошибка при формировании проводки.'
         PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход. Код ошибки -4.'
         RETURN -4 -- Возврат кода ошибки.

      END

		UPDATE dbo.OUT_TABLE_ROW
		SET LINK_OPER = @liLINK_G_PROV1
		WHERE LINK = @OTR_LINK
	
      -- Выборка очередного МЦ документа.
      FETCH NEXT 
      FROM curBA_MP_CHARGE_TABLE
	   INTO @OTR_LINK,
			@lvcTYPE,
			@liLINK,
			@lvcCODE,
			@ACCOUNT,
			@lnQTY,
			@SUMMA
   END

   CLOSE curBA_MP_CHARGE_TABLE
   DEALLOCATE curBA_MP_CHARGE_TABLE
   
   EXEC dbo.[X_SALDO_COMMITCHANGES]

COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
PRINT 'Х.п. BA_SAVE_G_PROV1_CHARGE_MP : Выход.'
RETURN 0 -- Ошибок нет.



GO


GRANT EXECUTE ON dbo.[BA_SAVE_G_PROV1_CHARGE_MP] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_U_NDFL_FILL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_U_NDFL_FILL]

GO

CREATE PROCEDURE [dbo].[SD_U_NDFL_FILL]
	@varKSlinkEmpl	 int,  
	@varKSRef_Pay  int, 	 
	@varKSDate datetime, 	 
	@varKSLinkVKR int,
	@varKSLinkEKR int,	
	@varKSfl int = 0

AS 
SET NOCOUNT ON
DECLARE @varKSMonth int, 
	  @varKSYear int, 
	  @varKSLINK_FACE int, 
	  @varKSPred_Mesto_Rab numeric(15,2), 
	  @varKSFlagD int,
	  @Status int	-->>NEW

IF @varKSfl>0
	SET @varKSfl = 1

DECLARE @NDFL_OPT8 TINYINT --Разрешить отрицательные суммы налога
SET @NDFL_OPT8 = dbo.sa_get_option_by_code('NDFL_OPT8')

SET @varKSMonth= month(@varKSDate)
SET @varKSYear = year(@varKSDate)

declare @DEP_LINK int
SELECT @DEP_LINK = DEP_LINK, @varKSLINK_FACE = PERS_LINK FROM DBO.EMPL WHERE LINK = @varKSlinkEmpl

DECLARE @Link211EKR int
Set @Link211EKR = ISNULL((SELECT TOP 1 LINK FROM KOSGU WHERE CODE = '211'),0)

if @varKSfl = 1
	Select [Организация] = [NAME] from dbo.DEPARTMENTS where link = @DEP_LINK

Select @Status= [STATUS] from dbo.ITEM_MOVE where ACTIVE = 1 and EMPL_LINK = @varKSlinkEmpl	-->>NEW

SET @varKSFlagD = 0

DECLARE @DIS_DATE DATETIME
SET @DIS_DATE = COALESCE((SELECT TOP 1 IDF.DIS_DATE FROM DBO.ITEM_DIS_FACE IDF with (nolock) WHERE IDF.EMPL_LINK = @varKSlinkEmpl AND IDF.ACTIVE=1),'29990101')

SET @varKSPred_Mesto_Rab = 0
IF YEAR(dbo.kd_DateBeginWork(@varKSlinkEmpl,@varKSDate)) = @varKSYear
BEGIN

	SET @varKSPred_Mesto_Rab =(SELECT ISNULL(SUM(SUMMA_TYP_INCOMS),0) FROM dbo.SD_EMPL_PREV_DOHOD WHERE LINK_EMPL = @varKSlinkEmpl)
			- (SELECT ISNULL(SUM(SUMMA_DED),0) FROM dbo.SD_EMPL_PREV_DED WHERE LINK_EMPL = @varKSlinkEmpl and 
					LINK_DED IN (SELECT distinct REF_DEDUCT FROM DICTIONARY_TYP_INCOMS where REF_DEDUCT is not null) )
	IF @varKSPred_Mesto_Rab IS null or @varKSPred_Mesto_Rab < 0
		SET @varKSPred_Mesto_Rab = 0
	SET @varKSFlagD = 1
END


IF @varKSfl = 1 
	SELECT Case @Status when 1 then 'Основной сотрудник' when 2 then 'Внутренний совместитель' else 'Внешний совместитель' end + 
	': '+rtrim(TAB)+ ' ' +rtrim(dbo.sd_GetEmplName(LINK))+  ', месяц ' + rtrim(convert(varchar(100),@varKSMonth))+ 
			 ', год ' +rtrim( convert(varchar(100),@varKSYear )) as 'Исходные данные'  FROM dbo.EMPL WHERE LINK = @varKSlinkEmpl   
IF  @varKSfl = 1 
	SELECT 'Совокупный доход: '+ rtrim(isnull(convert(varchar(100),(select sum(summa_TYP_INCOMS) from dbo.SD_EMPL_PREV_DOHOD where link_empl =@varKSlinkEmpl)),'0')) + ' , предоставленные вычеты: '+
	 rtrim( isnull( convert(varchar(100),(select sum(summa_ded) from dbo.SD_EMPL_PREV_DED where link_empl =@varKSlinkEmpl and LINK_DED NOT IN (SELECT distinct REF_DEDUCT FROM DICTIONARY_TYP_INCOMS where REF_DEDUCT is not null) )),'0'))
	+ ' , предоставлены скидки: '+
	 rtrim( isnull( convert(varchar(100),(select sum(summa_ded) from dbo.SD_EMPL_PREV_DED where link_empl =@varKSlinkEmpl and LINK_DED IN (SELECT distinct REF_DEDUCT FROM DICTIONARY_TYP_INCOMS where REF_DEDUCT is not null) )),'0'))  as 'Данные с предыдущего места работы'


/*Доходы*/
Declare @isPrevPreiod tinyint
--Суммы начислений включать в базу расчета в том месяце, в котором он был начислен.                   
Set @isPrevPreiod = dbo.sa_get_option_by_code('NDFL_OPT6')
Set @isPrevPreiod = 1 - ISNULL(@isPrevPreiod,0)

Declare @SJC table (link_empl int, link_pays int, link_vkr int, link_ekr int, typ_per tinyint, typ_oper tinyint, summa numeric(18,2), period_begin datetime, date1 datetime)

Insert into @SJC (link_empl, link_pays, link_vkr, link_ekr, typ_per, typ_oper, summa, period_begin, date1)
Select 
	JC.LINK_EMPL, P.LINK, link_vkr, ISNULL(JC.LINK_EKR,P.LINK_EKR), P.TYP_PER, P.OBJECT, summa, 
	period_begin = (case when @isPrevPreiod = 0 then JC.period_begin 
			else (Case 
					when JC.DATE_BEGIN < JC.period_begin and year(JC.DATE_BEGIN) = year(JC.period_begin) and d.code <> 'DOCUMENTS_ADD_PREMIUM' and d.code <> 'DOCUMENTS_ADD_PERCENT'
					then JC.DATE_BEGIN else JC.period_begin 
				end) 
			end),
	JC.DATE_BEGIN
from 
	dbo.CALCULATE_JURNAL JC 
	INNER JOIN dbo.EMPL E ON JC.LINK_EMPL = E.LINK
	INNER JOIN dbo.PAYS P ON JC.LINK_PAYS = P.LINK
	LEFT JOIN (Select d.link, o.code from sdoc d inner join dbo.s_objects o on d.object = o.link) d on jc.LINK_DOC = d.link
where
	P.OBJECT = 1
	AND
	P.LINK in (Select TAX_LINK from dbo.group_tax(@varKSRef_Pay)) 
	AND (
			@isPrevPreiod = 0 and @varKSMonth >= month(JC.PERIOD_BEGIN) and @varKSYear = year(JC.PERIOD_BEGIN)
		or 
			@isPrevPreiod = 1 
			and (@varKSMonth >= month(JC.DATE_BEGIN) or @varKSMonth >= month(JC.PERIOD_BEGIN) )
			and (@varKSYear = year(JC.DATE_BEGIN) or @varKSYear = year(JC.PERIOD_BEGIN) )
		)
	AND  
		(	-->>NEW
		@Status <> 1 AND JC.LINK_EMPL = @varKSlinkEmpl /*Если не основной сотрудник, то доход по своему табельному номеру*/
		or
		@Status = 1 AND E.PERS_LINK = @varKSLINK_FACE /*Если основной сотрудник, то доход по всем табельным номерам*/
		)	
	AND JC.LINK_DEP = @DEP_LINK 
	

DECLARE @varKSVal TABLE 
([MONTH] 		[int],
 [EMPL_SUMMA] 		[numeric](19, 2),
 [SUMMA] 		[numeric](19, 2),
 [EMPL_SUMMA_VKR]	[numeric](19, 2),
 [SUMMA_VKR]		[numeric](19, 2),
 [SUMMA_M]		[numeric](19, 2),
 [SUMMA_M_211]  [numeric](19, 2), --для расчёта коэффициента при предоставлении вычета только по 211 ЭКР
 [SUMMA_M_VKR]		[numeric](19, 2)
 --[SUMMA_M_VKR1]		[numeric](19, 2)
)

INSERT INTO @varKSVal([MONTH],[SUMMA],[EMPL_SUMMA], [SUMMA_VKR], [EMPL_SUMMA_VKR],[SUMMA_M],[SUMMA_M_211],[SUMMA_M_VKR])--,[SUMMA_M_VKR1])
SELECT T.NUM AS [MONTH],  
		[SUMMA] = SUM(SJ.SUMMA), 
		[EMPL_SUMMA] = SUM(CASE WHEN SJ.LINK_EMPL = @varKSlinkEmpl THEN SJ.SUMMA ELSE 0 END),
		[SUMMA_VKR] = SUM(CASE WHEN SJ.LINK_VKR = @varKSLinkVKR   AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END), 
		[EMPL_SUMMA_VKR] = SUM(CASE WHEN SJ.LINK_VKR = @varKSLinkVKR AND SJ.LINK_EMPL = @varKSlinkEmpl AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END), 
		[SUMMA_M] = SUM(CASE WHEN Month(sj.period_begin) = T.NUM AND SJ.LINK_EMPL = @varKSlinkEmpl THEN SJ.SUMMA ELSE 0 END), 
		[SUMMA_M_211] = SUM(CASE WHEN Month(sj.period_begin) = T.NUM AND SJ.LINK_EMPL = @varKSlinkEmpl AND SJ.LINK_EKR = @Link211EKR THEN SJ.SUMMA ELSE 0 END), 
		[SUMMA_M_VKR] = SUM(CASE WHEN Month(sj.period_begin) =T.NUM AND SJ.LINK_VKR = @varKSLinkVKR AND SJ.LINK_EMPL = @varKSlinkEmpl AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END)
--		[SUMMA_M_VKR1] = SUM(CASE WHEN Month(sj.period_begin) =T.NUM AND SJ.LINK_VKR = @varKSLinkVKR AND SJ.LINK_EMPL = @varKSlinkEmpl THEN SJ.SUMMA ELSE 0 END)
FROM dbo.MONTHS T, @SJC SJ
WHERE SJ.TYP_OPER = 1 AND T.NUM <= @varKSMonth
		AND T.NUM >= Month(sj.period_begin)
		AND  @varKSYear = Year(sj.period_begin)
GROUP BY  T.NUM

if @varKSfl = 1 
	select [month] as [Месяц], [summa] as [Сумма ФЛ с нач года ],summa_vkr as [Сумма ФЛ с нач года по ВКР], summa_m as [Сумма сотр за месяц], 
	summa_m_vkr as [Сумма сотр за месяц по ВКР]  from @varKSVal

/*Доходы для вычетов*/
DECLARE @varKSVal2 TABLE 
([MONTH] 		[int],
 [SUMMA] 		[numeric](19, 2),
 [EMPL_SUMMA] 		[numeric](19, 2),
 [SUMMA_VKR]		[numeric](19, 2),
 [EMPL_SUMMA_VKR]	[numeric](19, 2),
 [SUMMA_M]		[numeric](19, 2),
 [SUMMA_M_VKR]		[numeric](19, 2))


INSERT INTO @varKSVal2([MONTH],[SUMMA],[EMPL_SUMMA], [SUMMA_VKR], [EMPL_SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR])
SELECT T.NUM AS [MONTH],
		[SUMMA] = SUM(SJ.SUMMA),
		[EMPL_SUMMA] = SUM(CASE WHEN SJ.LINK_EMPL = @varKSlinkEmpl THEN SJ.SUMMA ELSE 0 END),
		[SUMMA_VKR] = SUM(CASE WHEN SJ.LINK_VKR = @varKSLinkVKR AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END),
		[EMPL_SUMMA_VKR] = SUM(CASE WHEN SJ.LINK_VKR = @varKSLinkVKR AND (SJ.LINK_EMPL = @varKSlinkEmpl) AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END), 
		[SUMMA_M] = SUM(CASE WHEN (CASE WHEN SJ.TYP_PER=1 THEN Month(sj.period_begin) ELSE MONTH(sj.DATE1) END)=T.num AND SJ.LINK_EMPL = @varKSlinkEmpl then sj.summa else 0 end),
		[SUMMA_M_VKR] = SUM(CASE WHEN ((CASE WHEN SJ.TYP_PER=1 THEN Month(sj.period_begin) ELSE MONTH(sj.DATE1) END)=T.num)
							AND sj.link_vkr = @varKSLinkVKR AND SJ.LINK_EMPL = @varKSlinkEmpl AND SJ.LINK_EKR = @varKSLinkEKR THEN SJ.SUMMA ELSE 0 END)
FROM dbo.MONTHS T, @SJC SJ
WHERE SJ.TYP_OPER = 1 
		AND T.NUM <= @varKSMonth AND
		T.NUM >=(CASE WHEN SJ.TYP_PER=1 THEN Month(sj.period_begin) ELSE MONTH(SJ.DATE1) END)
		AND @varKSYear =(case WHEN SJ.TYP_PER=1 THEN Year(sj.period_begin) ELSE YEAR(sj.DATE1) END)
GROUP BY  T.NUM

insert into @varKSVal2 ([MONTH],[SUMMA],[EMPL_SUMMA], [SUMMA_VKR], [EMPL_SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR])
select T.NUM, 0, 0, 0, 0, 0, 0  from dbo.MONTHS T where T.NUM < (Select min([month]) from @varKSVal2)

if @varKSfl = 1 
	select [month] as [Месяц], [summa] as [Сумма ФЛ с нач года], @varKSPred_Mesto_Rab as [Сумма ФЛ с предыдущего места работы], summa_vkr as [Сумма ФЛ с нач года по ВКР ], summa_m as [Сумма сотр за месяц], 
	summa_m_vkr as [Сумма сотр за месяц по ВКР]  from @varKSVal2 order by [month]

/*Какие бывают скидки*/
if @varKSfl=1 
   select code as [Код вычета], name as [Наименование вычета], SUMMA as [Сумма] from dbo.Salary_deductions(@varKSDate) WHERE TYPE = 5

/*
Если это не внешний совместитель, то Скидки и вычеты предоставляем только по основному табельному номеру
Если это внешний совместитель, предоставляем скидки
*/

/*Какие скидки у физ.лица*/
DECLARE @varKSTemp1 TABLE 
([NUM] 			[int],
 [REF_PAY]		[int],	
 [MP]		 	[numeric](19, 2),
 [MP_M]			[numeric](19, 2),
 [MP_M_VKR]		[numeric](19, 2),
 [PREDEL]		[numeric](19, 2))

--Расчет скидок
INSERT INTO @varKSTemp1 ([NUM],[REF_PAY],[MP],[MP_M],[MP_M_VKR],[PREDEL])
SELECT m.num,T1.REF_PAY,
	/*Годовая сумма дохода со скидкой по физ.лицу*/
	[mp] = SUM(case when Month(sj.period_begin)<=m.num then SJ.summa else 0 end), 
	/*Месячная сумма дохода со скидкой по физ.лицу*/
	[mp_m] = sum(case when Month(sj.period_begin)=m.num then (case when Month(sj.period_begin)<=m.num then SJ.summa else 0 end) else 0 end),
	/*Месячная сумма дохода со скидкой по физ. лицу  в разрезе КБК*/
	[mp_m_vkr] = sum(case when Month(sj.period_begin) = m.num AND sj.link_vkr = @varKSLinkVKR AND SJ.LINK_EKR = @varKSLinkEKR then (case when Month(sj.period_begin)<=m.num then SJ.summa else 0 end) else 0 end),
	[PREDEL] = T1.SUMMA -(case when @varKSFlagD = 1 then isnull((select sum(summa_ded) from dbo.SD_EMPL_PREV_DED where LINK_DED = T1.REF_PAY and  link_empl=@varKSlinkEmpl),0)  else 0 end) 
FROM 
	dbo.MONTHS M, @SJC SJ, dbo.Salary_deductions(@varKSDate) T1
WHERE  
	Year(sj.period_begin) = @varKSYear and m.num<=@varKSMonth AND T1.TYPE = 6 --Тип вычета "Скидка на материальную помощь"
	AND T1.REF_PAY = (select ref_deduct  from dbo.DICTIONARY_TYP_INCOMS where link = (select LINK_INC from dbo.PAYS where LINK = SJ.LINK_PAYS)) 
	AND @Status in (1 /*Основной*/, 3 /*Внешний совместитель*/) AND SJ.LINK_EMPL = @varKSlinkEmpl
GROUP BY m.num, T1.REF_PAY, T1.SUMMA

IF @varKSfl=1 
	select [num] as [Месяц], [Вычет] = (select name from diction where link = ref_pay), [mp] as [Сумма ФЛ с нач года], mp_m as [Сумма ФЛ за месяц], 
	mp_m_vkr as [Сумма ФЛ за месяц по ВКР], predel as [Предел]  from @varKSTemp1

DECLARE @varKSTemp2 TABLE 
([NUM] 			[int],
 [REF_PAY]		[int],	
 [MP]		 	[numeric](19, 2),
 [MP_M]			[numeric](19, 2),
 [MP_M_VKR]		[numeric](19, 2), [PREDEL]		[numeric](19, 2),
 [SALDO]		[numeric](19, 2),
 [KOEF] 		[numeric](19, 10))

INSERT INTO @varKSTemp2 ([NUM],[REF_PAY],[MP],[MP_M],[MP_M_VKR],[PREDEL],[SALDO],[KOEF])
SELECT T1.NUM,T1.REF_PAY,T1.MP,T1.MP_M,T1.MP_M_VKR,T1.PREDEL, 
	[SALDO] = (CASE WHEN PREDEL < 0 THEN 0 ELSE PREDEL END) - ISNULL((select sum(mp_m) from @varKSTemp1 T2 where T2.num < T1.num and T2.REF_PAY = T1.REF_PAY),0),
	[KOEF] =  (CASE WHEN MP_M = 0 THEN 0 ELSE MP_M_VKR/MP_M END)
FROM @varKSTemp1 T1

DECLARE @varKSTemp3 TABLE 
([NUM] 			[int],
 [REF_PAY]		[int],	
 [MP_M]			[numeric](19, 2),
 [MP_M_VKR]		[numeric](19, 2),
 [KOEF] 		[numeric](19, 10),
 [DED]			[numeric](19, 2)
  )

INSERT INTO @varKSTemp3 ([NUM],[REF_PAY],[MP_M],[MP_M_VKR],[KOEF],[DED])
SELECT [NUM],[REF_PAY],[MP_M],[MP_M_VKR],[KOEF], 
	   [DED] = 	case when SALDO < 0 then 
				- case when (CASE WHEN PREDEL < 0 THEN 0 ELSE PREDEL END) - ISNULL(MP,0) > 0	then
					(CASE WHEN PREDEL < 0 THEN 0 ELSE PREDEL END) - ISNULL(MP,0) 
					else 0
				end
			else
				(CASE WHEN MP_M > SALDO THEN SALDO ELSE MP_M END)
			end
FROM @varKSTemp2 

/*Очитстка от мусора: были рассчитаны вычеты и скидки с КБК, которые теперь в этом году больше не используются.
Врезультате эти суммы вычетов не очищаются при расчете и вылазят в 2НДФЛ*/
delete
from 
	dbo.SAL_DED_MONTH
where
	YEAR(dbo.SAL_DED_MONTH.DATE_DED) = YEAR(@varKSDate)
	and
	not exists (
		Select j.LINK 
		from dbo.calculate_jurnal j
		where 
			j.link_pays in (Select TAX_LINK from dbo.group_tax(@varKSRef_Pay)) 
			and YEAR(j.PERIOD_BEGIN) = YEAR(@varKSDate)
			and j.link_empl = dbo.SAL_DED_MONTH.link_empl and j.LINK_VKR = dbo.SAL_DED_MONTH.LINK_VKR
	)

/*Удалить все вычеты и скидки по сотруднику, чтобы затем вновь рассчитать их*/
DELETE FROM dbo.SAL_DED_MONTH
WHERE 
	LINK_EMPL = @varKSlinkEmpl 
	AND LINK_VKR = @varKSLinkVKR 
	AND ISNULL(LINK_EKR,@varKSLinkEKR) = @varKSLinkEKR 
	AND YEAR(DATE_DED) = YEAR(@varKSDate) 
	AND MONTH(DATE_DED) <= MONTH(@varKSDate) 

/*Заново рассчитать годовые скидки*/
INSERT INTO dbo.SAL_DED_MONTH (LINK_EMPL,REF_DED,SUMMA,DATE_DED,LINK_VKR,LINK_EKR,TYPE)
SELECT [LINK_EMPL] = @varKSlinkEmpl,
		 [REF_DED]   = T.REF_PAY,
		 [SUMMA] 	 = ISNULL(T.DED,0) * ISNULL(T.KOEF,1),
		 [DATE_DED]  = dbo.ConvertDMY2Date(1,t.num,year(@varKSDate)),
		 [LINK_VKR]	 = @varKSLinkVKR,
		 [LINK_EKR]	 = @varKSLinkEKR,
		 [TYPE] = 2
FROM @varKSTemp3 T WHERE T.MP_M_VKR <> 0 AND T.DED <> 0 

/* Скидки */

DECLARE @varKSTotTab TABLE
([MONTH] 		[int],
 [EMPL_SUMMA]		[numeric](19, 2), --
 [EMPL_SUMMA_VKR]	[numeric](19, 2), --
 [SUMMA_VKR]		[numeric](19, 2),
 [SUMMA_M]		[numeric](19, 2),
 [SUMMA_M_211]  [numeric](19, 2), --для расчёта коэффициента при предоставлении вычета только по 211 ЭКР
 [SUMMA_M_VKR]		[numeric](19, 2), --для каждого ЭКР, ВКР
 [DED_M_ALL] 		[numeric](19, 2),
 --[DED_M_ALL_211] 	[numeric](19, 2), --для расчёта коэффициента при предоставлении вычета только по 211 ЭКР
 [DED]			[numeric](19, 2),
 [DED_M]		[numeric](19, 2),
 [DED0]			[numeric](19, 2)
 ) 

/* Вычеты делятся между КБК пропорционально с помощью коэффициентов пропорциональности */
INSERT INTO @varKSTotTab([MONTH], [EMPL_SUMMA], [EMPL_SUMMA_VKR], [SUMMA_VKR],[SUMMA_M],[SUMMA_M_211],[SUMMA_M_VKR],[DED_M_ALL],[DED],[DED_M],DED0)
SELECT 	
		M.[NUM], 
		ISNULL(T1.EMPL_SUMMA,0), 
		ISNULL(T1.[EMPL_SUMMA_VKR],0), 
		ISNULL(T1.[SUMMA_VKR],0), 
		ISNULL(T1.[SUMMA_M],0),
		ISNULL(T1.[SUMMA_M_211],0),	 
		ISNULL(T1.[SUMMA_M_VKR],0),
	 	[DED_M_ALL] = ISNULL((SELECT SUM(T2.DED) FROM @varKSTemp3 T2 WHERE T2.NUM=M.[NUM]),0),
		[DED] 		= ISNULL((SELECT SUM(T2.DED * T2.KOEF) FROM @varKSTemp3 T2 WHERE T2.NUM <= M.[NUM]),0),
		[DED_M] 	= ISNULL((SELECT SUM(T2.DED * T2.KOEF) FROM @varKSTemp3 T2 WHERE T2.NUM = M.[NUM]),0),
		[DED0] 		= ISNULL((SELECT SUM(T2.DED) FROM @varKSTemp3 T2 WHERE T2.NUM <= M.[NUM]),0)
FROM  dbo.months M LEFT JOIN @varKSVal T1 on M.num = T1.[MONTH] 
WHERE M.NUM <= @varKSMonth
GROUP BY M.[NUM], T1.[EMPL_SUMMA], T1.[EMPL_SUMMA_VKR], T1.SUMMA_VKR, T1.SUMMA_M_VKR, T1.SUMMA_M, T1.SUMMA_M_211

IF @varKSfl=1 
select [month] as [Месяц],summa_vkr as [Сумма ФЛ с нач года по ВКР], summa_m as [Сумма сотр за месяц], 
	summa_m_vkr as [Сумма за месяц по ВКР], ded_m_all as [Скидки всего], ded as [Скидки всего по ВКР], ded_m as [Скидки за месяц по ВКР]  from @varKSTotTab

DECLARE @varKSTT TABLE
([REF_PAY] 	[int],
 [PREDEL]	[numeric](19, 2),
 [SUMMA]		[numeric](19, 2),
 [MONTHEND]	[int])

--- Вычеты и скидки: Определение достижения предела
INSERT INTO @varKSTT ([REF_PAY],[PREDEL],[SUMMA],[MONTHEND])
SELECT TD.REF_PAY,TD.PREDEL,TD.SUMMA, 
		[MonthEnd] =  (SELECT TOP 1 T1.[MONTH] FROM  @varKSVal2 T1 
 							WHERE (SUMMA+ISNULL(@varKSPred_Mesto_Rab,0) - ISNULL((select sum(ded) from @varKSTemp3 where num<=T1.[MONTH]),0))
							<(CASE WHEN TD.PREDEL = 0 THEN 999999999999 ELSE TD.PREDEL END)
							ORDER BY T1.[MONTH] DESC)
FROM 
	dbo.Salary_deductions(@varKSDate ) as TD where TYPE = 1

DECLARE @varKSTotal TABLE
( link int not null IDENTITY(1,1),
 [REF_PAY] 	[int],
 [MONTH_BEGIN]	[int],
 [MONTH_END]	[int],		
 [SUMMA]	[numeric](19, 2),
[SUMMA_V] numeric(18,2), [SUMMA_D] numeric(18,2), [Ostatok_V] numeric(18,2)-- Для определения факт вычетов
)

--Предоставление стандартных вычетов
--'Всегда,При наличии любого дохода за месяц,При наличии только положительного дохода за месяц'
declare @NDFL_OPT5 tinyint
SET @NDFL_OPT5 =  ISNULL((SELECT top 1 CONVERT(INT,VALUE) FROM S_OPTIONS WHERE OBJECT = (SELECT LINK FROM S_OBJECTS WHERE CODE = 'NDFL_OPT5')),1)

INSERT INTO @varKSTotal ([REF_PAY],[MONTH_BEGIN],[MONTH_END],[SUMMA],[SUMMA_V],[SUMMA_D])
SELECT 		
	[REF_PAY] 		= TT.REF_PAY, 
	[MONTH_BEGIN]	= M.[NUM],--SDE.MONTH_BEGIN,
	[MONTH_END] 	= M.[NUM],--(CASE WHEN TT.MonthEnd> SDE.MONTH_END THEN SDE.MONTH_END ELSE TT.MonthEnd END),
	[SUMMA] 		= TT.SUMMA,
	[SUMMA_V]		= TT.SUMMA,	-- Для определения факт вычетов
	[SUMMA_D]		= ISNULL(D.[summa_m],0)	-- Для определения факт вычетов
				- ISNULL((select sum(ded) from @varKSTemp3 where num = M.[NUM]),0)
FROM 
	@varKSTT TT
	INNER JOIN (SELECT link_ded, month_begin,month_end FROM DBO.salary_ded_empl(@varKSlinkEmpl,@varKSMonth, @varKSYear)T1 WHERE t1.month_begin<=t1.month_end) SDE
		ON SDE.LINK_DED =TT.REF_PAY
	INNER JOIN dbo.Months M ON TT.MonthEnd >= M.[NUM] AND M.[NUM] between SDE.MONTH_BEGIN and SDE.MONTH_END
	LEFT JOIN @varKSVal2 D ON M.NUM = D.[month] -- Для определения факт вычетов
WHERE 
	@Status in (1 /*Основной*/, 3 /*Внешний совместитель*/)	-->>NEW
	AND 
		(@NDFL_OPT5 = 1 or @NDFL_OPT5 = 2 and D.SUMMA_M <> 0 or @NDFL_OPT5 = 3 and D.SUMMA_M > 0)
	AND --Вычет дается, если сотрудник в этом месяце не уволен или есть положительный доход.
		(D.SUMMA_M <> 0 OR dbo.DateEndOfMonth(@DIS_DATE) >= dbo.DateEndOfMonth( dbo.ConvertDMY2Date(1,M.[NUM],@varKSYear)))
ORDER BY
	M.NUM

---Вычеты от взносов в пенсионый фонд
INSERT INTO @varKSTotal ([REF_PAY],[MONTH_BEGIN],[MONTH_END],[SUMMA],[SUMMA_V],[SUMMA_D])
select 
	TA.LINK_DED, MONTH(cj.PERIOD_BEGIN), MONTH(cj.PERIOD_BEGIN), SUM(SUMMA),SUM(SUMMA), (SELECT MAX(A.SUMMA_D) FROM @varKSTotal A WHERE A.MONTH_BEGIN = MONTH(cj.PERIOD_BEGIN))
from 
	dbo.EMPL E inner join dbo.calculate_jurnal cj on e.link = cj.link_empl
	inner join dbo.TAX2_APP TA on TA.LINK_UP = CJ.LINK_PAYS
where 
	year(period_begin) = @varKSYear
	and
	E.LINK = @varKSlinkEmpl	
	and
	@Status in (1 /*Основной*/, 3 /*Внешний совместитель*/) and MONTH(cj.PERIOD_BEGIN) <= Month(@varKSDate) 
	and
	ISNULL(TA.LINK_DED,0) > 0
GROUP BY 
	TA.LINK_DED, MONTH(cj.PERIOD_BEGIN)

/*
Раздение на части сумм вычетов, на которые человек имеет право: фактически предоставленные и остаток непредоставленных вычетов
*/
declare @VychOpt1 int -- ограничивать месячный вычет месячным доходом
declare	@VychOpt2 int  -- месячный вычет давать с нарастающим итогом (компенсировать не предоставленный вычет, если в определенном месяце сотрудник не получал дохода)

if @NDFL_OPT5 > 1 begin
	Set @VychOpt1 = ISNULL((SELECT top 1 CONVERT(INT,VALUE) FROM S_OPTIONS WHERE OBJECT = (SELECT LINK FROM S_OBJECTS WHERE CODE = 'NDFL_OPT1')),0)
	Set @VychOpt2 = ISNULL((SELECT top 1 CONVERT(INT,VALUE) FROM S_OPTIONS WHERE OBJECT = (SELECT LINK FROM S_OBJECTS WHERE CODE = 'NDFL_OPT2')),0)
end
else
	Select @VychOpt1 = 0, @VychOpt2 = 0

IF @VychOpt1 = 1 --Если ограничивать месячный вычет месячным доходом
BEGIN

	DECLARE @Cur1 CURSOR, @MES tinyint, @REF_V int, @SUMMA_V numeric(18,2), @SUMMA_D numeric(18,2), @Ostatok_V numeric(18,2), @Ostatok numeric(18,2), @Ostatok_m numeric(18,2), @link int
	Declare @SumVPred numeric(18,2) --Сумма уже предоставленных вычетов в отчетном месяце
	SET @Cur1 = CURSOR FORWARD_ONLY

	FOR select link, MONTH_BEGIN, REF_PAY, SUMMA_V, SUMMA_D, Ostatok_V from @varKSTotal order by link
	
	OPEN @Cur1
	FETCH NEXT FROM @Cur1 INTO @link, @MES, @REF_V, @SUMMA_V, @SUMMA_D, @Ostatok_V
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN
			Set @Ostatok = ISNULL((Select Sum(Ostatok_V)  from @varKSTotal 
				where ((@VychOpt2 = 1 and MONTH_BEGIN <= @MES) -- ограниченный месячным доходом вычет давать с нарастающим итогом (компенсировать не предоставленный вычет)
					or (@VychOpt2 = 0 and MONTH_BEGIN = @MES)) -- ограниченный месячным доходом вычет давать без нарастающего итога
					and link < @link and REF_PAY = @REF_V) ,0)
				
			Set @Ostatok_m = ISNULL((Select Sum(Ostatok_V)  from @varKSTotal where Ostatok_V > 0 and MONTH_BEGIN = @MES and link < @link),0)
			Set @SUMMA_V = ISNULL((Select Sum(SUMMA_V)  from @varKSTotal where MONTH_BEGIN = @MES and link <= @link),0)
			Set @SumVPred = ISNULL((Select Sum(SUMMA_V)  from @varKSTotal where MONTH_BEGIN = @MES and link < @link),0)
	
			update @varKSTotal
			Set 	SUMMA_V = (case when ISNULL(@SUMMA_V,0) + @Ostatok > ISNULL(SUMMA_D,0) 
					then ISNULL(SUMMA_D,0) - @SumVPred
					else (case when @Ostatok_m = 0 then ISNULL(@SUMMA_V,0) + @Ostatok - @SumVPred else 0 end) 
				end),
				Ostatok_V = (case when ISNULL(@SUMMA_V,0) + @Ostatok > ISNULL(SUMMA_D,0)
							then ISNULL(@SUMMA_V,0) - ISNULL(SUMMA_D,0)
							else  - @Ostatok
						end)
			where link = @link

		END
	
		FETCH NEXT FROM @Cur1 INTO @link, @MES, @REF_V, @SUMMA_V, @SUMMA_D, @Ostatok_V
	END
	
	CLOSE @Cur1
	DEALLOCATE @Cur1

	IF @varKSfl=1 
	select [Вычет] = (select  rtrim(sname) + ' ' + LEFT(rtrim(name),100) from dbo.DICTIONARY_TYP_DEDUCTION where link = REF_PAY),
		month_begin as [Месяц начала], month_end as [Месяц окончания], summa as [Сумма вычета по НК], summa_v as [Сумма вычета факт], Ostatok_V as [Изменение остатка вычетов] from @varKSTotal order by month_begin,  REF_PAY
	
	update @varKSTotal 
	Set summa = summa_v
END
/**/

/* ^^^^^^ Имущественные вычеты - Начало расчета ^^^^^^^^*/

declare @VychOpt9 int -- имущественный вычет предоставлять с даты регистрации уведомсления
Set @VychOpt9 = ISNULL((SELECT top 1 CONVERT(INT,VALUE) FROM dbo.S_OPTIONS WHERE OBJECT = (SELECT LINK FROM S_OBJECTS WHERE CODE = 'NDFL_OPT9')),0)

declare @SprOtherDed table(LINK_DICTION int, MONTH1 TINYINT, Summa numeric(18,2))

insert into @SprOtherDed
Select LINK_DICTION, MONTH1, SUM(SUM_DED) 
from 
	EMPL E 
	inner join TAX_DEDUCTIONS TD on E.PERS_LINK = TD.LINK_PERSON AND E.DEP_LINK = TD.LINK_DEP
where 
	E.LINK = @varKSlinkEmpl 
	and [YEAR] = @varKSYear 
	AND @Status in (1 /*Основной*/, 3 /*Внешний совместитель*/) 
	and MONTH1 <= Month(@varKSDate) --DATE_REF <= dbo.DateEndOfMonth(@varKSDate)
	AND E.DEP_LINK = @DEP_LINK
Group by 
	LINK_DICTION, MONTH1

IF @varKSfl=1 
	select [Код]= rtrim(SNAME), [Имущественный вычет] = rtrim(name), [Сумма вычета] = ISNULL(OD.summa,0) from @SprOtherDed OD inner join dbo.DICTIONARY_TYP_DEDUCTION  D on D.link = OD.LINK_DICTION

declare @TMP Table ([REF_PAY] int, [MONTH_BEGIN] int, [MONTH_END] int, [SUMMA] numeric(18,2))
Insert into @TMP
Select [REF_PAY], M.NUM, M.NUM, SUM([SUMMA]) 
from dbo.Months M, @varKSTotal T1 
 where M.[NUM] between [MONTH_BEGIN] and [MONTH_END] and [REF_PAY] not in (select LINK_DICTION from @SprOtherDed) 
group by [REF_PAY], M.NUM

DECLARE @REF_PAY int, @MONTH_BEGIN int, @SUMMA numeric(18,2), @Saldo numeric(18,2), @STD_VYCH NUMERIC(18,2), @MONTH1 TINYINT

DECLARE @Cur CURSOR
SET @Cur = CURSOR FORWARD_ONLY
FOR 
	Select M.NUM, LINK_DICTION, [SUMMA], MONTH1 = (CASE WHEN @VychOpt9 = 1 THEN OD.MONTH1 ELSE 1 END) 
	from @SprOtherDed OD, dbo.Months M 
	WHERE M.NUM BETWEEN (CASE WHEN @VychOpt9 = 1 THEN OD.MONTH1 ELSE 1 END) AND @varKSMonth

OPEN @Cur
FETCH NEXT FROM @Cur INTO @MONTH_BEGIN, @REF_PAY, @SUMMA, @MONTH1
WHILE (@@fetch_status <> -1)
BEGIN
	IF (@@fetch_status <> -2)
	BEGIN
		Set @Saldo = ISNULL(@SUMMA,0) - ISNULL((Select Sum(Summa) from @tmp T where T.REF_PAY = @REF_PAY),0)

		SET @STD_VYCH = ISNULL((SELECT SUM(SUMMA) FROM @varKSTotal WHERE [MONTH_BEGIN] < @MONTH1),0)

		INSERT INTO @TMP ([REF_PAY],[MONTH_BEGIN],[MONTH_END],[SUMMA])
		Select --
			@REF_PAY, @MONTH_BEGIN, @MONTH_BEGIN, 
			(Case When @Saldo > (ISNULL(DS.EMPL_SUMMA,0) - ISNULL(DS.DED0,0) 
								- (ISNULL(DS2.EMPL_SUMMA,0) - ISNULL(DS2.DED0,0) - @STD_VYCH)
								- ISNULL((Select SUM(summa) from @TMP where MONTH_BEGIN <=  @MONTH_BEGIN ),0))
				then (ISNULL(DS.EMPL_SUMMA,0) - ISNULL(DS.DED0,0) 
						- (ISNULL(DS2.EMPL_SUMMA,0) - ISNULL(DS2.DED0,0) - @STD_VYCH)
						- ISNULL((Select SUM(summa) from @TMP where MONTH_BEGIN <=  @MONTH_BEGIN ),0))
			else
				@Saldo
			end)
		from
			@varKSTotTab DS
			LEFT JOIN @varKSTotTab DS2 ON DS2.[Month] = @MONTH1-1 
		where
			DS.[Month] = @MONTH_BEGIN
			and
			(ISNULL(DS.EMPL_SUMMA,0) - ISNULL(DS.DED0,0)
				- (ISNULL(DS2.EMPL_SUMMA,0) - ISNULL(DS2.DED0,0) - @STD_VYCH) 
				- ISNULL((Select SUM(summa) from @TMP where MONTH_BEGIN <=  @MONTH_BEGIN ),0)) > 0
			and 
			@Saldo > 0

	END
	FETCH NEXT FROM @Cur INTO @MONTH_BEGIN, @REF_PAY, @SUMMA, @MONTH1
END

CLOSE @Cur
DEALLOCATE @Cur

INSERT INTO @varKSTotal ( [REF_PAY], [MONTH_BEGIN], [MONTH_END], [SUMMA])
Select * from @TMP where [REF_PAY] in (select LINK_DICTION from @SprOtherDed)

/* vvvvvv Имущественные вычеты - Конец расчета vvvvvvv */


IF @varKSfl=1 
select [Вычет] = (select  rtrim(sname) + ' ' + LEFT(rtrim(name),50) from dbo.DICTIONARY_TYP_DEDUCTION where link = REF_PAY),
	month_begin as [Месяц начала], month_end as [Месяц окончания], summa as [Сумма вычета]  from @varKSTotal T1  order by month_begin, REF_PAY


DECLARE @varKSTotal1 TABLE
([KOL]			[int],
 [REF_PAY] 		[int],
 [MONTH_BEGIN]		[int],
 [MONTH_END]		[int],		
 [SUMMA]		[numeric](19, 2))

INSERT INTO @varKSTotal1 ([KOL],[REF_PAY],[MONTH_BEGIN],[MONTH_END],[SUMMA])
SELECT COUNT(*) AS [KOL],REF_PAY,MONTH_BEGIN,MONTH_END,SUMMA
FROM @varKSTotal 
GROUP BY REF_PAY,MONTH_BEGIN,MONTH_END,SUMMA

DECLARE @varKSvych TABLE
([MONTH] 	[int],
 [REF_PAY] 	[int],
 [DEDUCT]	[numeric] (19, 2),
 [COMMENT]  [varchar] (254),
 [KOEF_VKR] [numeric] (18,10),
 [kol] [numeric] (18,2),
 [SPR_SUM]  NUMERIC(18,2)	
)

DECLARE @NDFL_OPT7 int
SET @NDFL_OPT7 = dbo.sa_get_option_by_code('NDFL_OPT7')

DECLARE @Koef table (Mon int, koef NUMERIC(18,10), doh tinyint, koef2 NUMERIC(18,10))
insert into @Koef (Mon, Koef, doh, koef2)
Select 	T2.[Month], 
	CASE WHEN @NDFL_OPT7 = 1 --Вычеты применять только к доходу по 211 ЭКР
	THEN 
		CASE WHEN @varKSLinkEKR = @Link211EKR 
		THEN --Начислять пропорционально КБК
			--CONVERT(NUMERIC(18,10), case when (t2.summa_m_211- t2.ded_m_all) <> 0 then ((v.summa_m_vkr-T2.ded_m)/(t2.summa_m_211- t2.ded_m_all)) else 0 end )
			CONVERT(NUMERIC(18,10), case when t2.summa_m_211 <> 0 then (v.summa_m_vkr/t2.summa_m_211) else 0 end )
		ELSE 
			0 
		END
	ELSE --Начислять пропорционально КБК и ЭКР
		--CONVERT(NUMERIC(18,10), case when (t2.summa_m- t2.ded_m_all) <> 0 then ((t2.summa_m_vkr-T2.ded_m)/(t2.summa_m- t2.ded_m_all)) else 0 end )
		CONVERT(NUMERIC(18,10), case when t2.summa_m <> 0 then (t2.summa_m_vkr/t2.summa_m) else 0 end )
	END,
	(Case when t2.summa_m <> 0 then 1 else 0 end),
	CONVERT(NUMERIC(18,10), case when t2.summa_m <> 0 then (t2.summa_m_vkr/t2.summa_m) else 0 end )	
from 
	@varKSTotTab T2 
	inner join @varKSVal V on T2.[month] = V.[month]

--СПРАВОЧНИК ВИДОВ ИМУЩЕСТВЕННЫХ ВЫЧЕТОВ
DECLARE @DICT_TAX_DEDUCTIONS TABLE (LINK INT)
INSERT INTO @DICT_TAX_DEDUCTIONS (LINK)
SELECT LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE NUMBER = 4

/*Расстановка коэффициентов на вычеты. Если нет дохода, то вычета по коэф. будующего месяца, в котором доход есть*/
INSERT INTO @varKSvych ([MONTH],[REF_PAY],[DEDUCT],[COMMENT],[KOEF_VKR],[KOL], [SPR_SUM])
SELECT [MONTH] = T1.MONTH_BEGIN, T1.REF_PAY,
	[DEDUCT] = 
			CASE WHEN NOT EXISTS (SELECT * FROM @DICT_TAX_DEDUCTIONS D WHERE D.LINK = T1.REF_PAY) THEN	
				CONVERT(NUMERIC(18,10), T1.KOL*T1.SUMMA * 
				case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef from @Koef K where K.Mon >= T1.MONTH_BEGIN and doh <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef from @Koef K where K.Mon = T1.MONTH_BEGIN and K.Koef <> 0 order by Mon),0) end)
			ELSE
				CONVERT(NUMERIC(18,10), T1.KOL*T1.SUMMA * 
				case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon >= T1.MONTH_BEGIN and doh <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon = T1.MONTH_BEGIN and K.Koef2 <> 0 order by Mon),0) end)
			END,		

	[COMMENT] = 
			CASE WHEN NOT EXISTS (SELECT * FROM @DICT_TAX_DEDUCTIONS D WHERE D.LINK = T1.REF_PAY) THEN	
				'('+RTRIM(LTRIM(STR(T1.KOL)))+'*'+RTRIM(LTRIM(CONVERT(VARCHAR(100),T1.SUMMA)))+ 
				'*'+ rtrim(ltrim(convert(varchar(100), CONVERT(NUMERIC(18,2), case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef from @Koef K where K.Mon >= T1.MONTH_BEGIN and K.Koef <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef from @Koef K where K.Mon = T1.MONTH_BEGIN and doh <> 0 order by Mon),0) end)) )) +')'
			ELSE
				'('+RTRIM(LTRIM(STR(T1.KOL)))+'*'+RTRIM(LTRIM(CONVERT(VARCHAR(100),T1.SUMMA)))+ 
				'*'+ rtrim(ltrim(convert(varchar(100), CONVERT(NUMERIC(18,2), case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon >= T1.MONTH_BEGIN and K.Koef2 <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon = T1.MONTH_BEGIN and doh <> 0 order by Mon),0) end)) )) +')'
			END,

	[KOEF_VKR] =
			CASE WHEN NOT EXISTS (SELECT * FROM @DICT_TAX_DEDUCTIONS D WHERE D.LINK = T1.REF_PAY) THEN
				 CONVERT(NUMERIC(18,10), case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef from @Koef K where K.Mon >= T1.MONTH_BEGIN and K.Koef <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef from @Koef K where K.Mon = T1.MONTH_BEGIN and doh <> 0 order by Mon),0) end )
			ELSE
				 CONVERT(NUMERIC(18,10), case when D.summa_m = 0 then ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon >= T1.MONTH_BEGIN and K.Koef2 <> 0 order by Mon),0)
					else ISNULL((Select top 1 K.Koef2 from @Koef K where K.Mon = T1.MONTH_BEGIN and doh <> 0 order by Mon),0) end )				
			END,		
	T1.KOL,
	T1.KOL*T1.SUMMA
FROM @varKSTotal1 t1 left join @varKSTotTab D on T1.MONTH_BEGIN = D.[Month]--, @varKSTotTab T2 WHERE T2.[MONTH] BETWEEN T1.MONTH_BEGIN AND T1.MONTH_END 
ORDER BY 1

INSERT INTO dbo.SAL_DED_MONTH (LINK_EMPL,REF_DED,SUMMA,DATE_DED,LINK_VKR,LINK_EKR,TYPE, KOEF_VKR, KOL )
SELECT 	[LINK_EMPL] = @varKSlinkEmpl,
			[REF_DED] 	= T.REF_PAY,
			[SUMMA] 	= T.DEDUCT,
			[DATE_DED] 	= dbo.ConvertDMY2Date(1,t.[month],year(@varKSDate)),
			[LINK_VKR]	= @varKSLinkVKR,
			[LINK_EKR]	= @varKSLinkEKR,
			[TYPE] 		= 1, --convert(NUMERIC(3,0),B.VALUE)
			[KOEF_VKR],
			[KOL]
FROM @varKSvych T WHERE T.DEDUCT <> 0 

--========================================================================================
--Блок проверки и коррестировки ошибки, связанной с погрешностья округления разбитых по источникам вычетов
SELECT S.REF_DED, MONTH(DATE_DED) AS MN, V.SPR_SUM - SUM(SUMMA) AS SUMMA
INTO #CORRECT
FROM dbo.SAL_DED_MONTH S INNER JOIN @varKSvych V ON V.[MONTH] = MONTH(S.DATE_DED) AND S.REF_DED = V.REF_PAY
WHERE YEAR(DATE_DED) = year(@varKSDate) AND LINK_EMPL = @varKSlinkEmpl
GROUP BY S.REF_DED, MONTH(DATE_DED), V.SPR_SUM
HAVING ABS(V.SPR_SUM - SUM(SUMMA)) BETWEEN 0.01 AND 0.02

IF EXISTS(SELECT * FROM #CORRECT) BEGIN

	UPDATE V
	SET V.DEDUCT = ISNULL(V.DEDUCT,0) + ISNULL(C.SUMMA,0)
	FROM @varKSvych V INNER JOIN #CORRECT C ON V.[MONTH] = C.MN AND C.REF_DED = V.REF_PAY

	DELETE FROM dbo.SAL_DED_MONTH 
	WHERE YEAR(DATE_DED) = year(@varKSDate) AND LINK_EMPL = @varKSlinkEmpl AND [LINK_VKR] = @varKSLinkVKR AND [LINK_EKR] = @varKSLinkEKR
		AND REF_DED IN (SELECT REF_PAY FROM @varKSvych)

	INSERT INTO dbo.SAL_DED_MONTH (LINK_EMPL,REF_DED,SUMMA,DATE_DED,LINK_VKR,LINK_EKR,TYPE, KOEF_VKR, KOL )
	SELECT 	[LINK_EMPL] = @varKSlinkEmpl,
				[REF_DED] 	= T.REF_PAY,
				[SUMMA] 	= T.DEDUCT,
				[DATE_DED] 	= dbo.ConvertDMY2Date(1,t.[month],year(@varKSDate)),
				[LINK_VKR]	= @varKSLinkVKR,
				[LINK_EKR]	= @varKSLinkEKR,
				[TYPE] 		= 1, --convert(NUMERIC(3,0),B.VALUE)
				[KOEF_VKR],
				[KOL]
	FROM @varKSvych T WHERE T.DEDUCT <> 0 

END
-----------------------------------------------------------------------------------------

DECLARE @varKSTota TABLE
([MONTH] 		[int],
 [PERS_SUMMA_VKR]	[numeric](19, 2),
 [SUMMA_VKR]	[numeric](19, 2),
 [SUMMA_M]		[numeric](19, 2),
 [SUMMA_M_VKR]	[numeric](19, 2),
 [DED_M_ALL] 	[numeric](19, 2),
 [DED]			[numeric](19, 2),
 [DED_M]			[numeric](19, 2),
 [VYCH]			[numeric](19, 2),
 [VYCH_M]		[numeric](19, 2),
 [DOHOD_ALL]	[numeric](19, 2),
 [VICHET_ALL]	[numeric](19, 2)
 ) 

INSERT INTO @varKSTota([MONTH], [PERS_SUMMA_VKR], [SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR],[DED_M_ALL],[DED],[DED_M],[VYCH],[VYCH_M],[DOHOD_ALL],[VICHET_ALL])
SELECT T1.[MONTH],T1. [SUMMA_VKR], T1.[EMPL_SUMMA_VKR],T1.[SUMMA_M],T1.[SUMMA_M_VKR],T1.[DED_M_ALL],T1.[DED],T1.[DED_M],
		[VYCH]	=ISNULL((SELECT SUM(V.DEDUCT) FROM @varKSvych v WHERE V.[MONTH]<= T1.[MONTH]),0),
		[VYCH_M] =ISNULL((SELECT SUM(V.DEDUCT) FROM @varKSvych v WHERE V.[MONTH] = T1.[MONTH]),0),
		[DOHOD_ALL] = T1.[EMPL_SUMMA],
		[VICHET_ALL] = ISNULL((SELECT SUM(V.SPR_SUM) FROM @varKSvych v WHERE V.[MONTH]<= T1.[MONTH]),0)
FROM @varKSTotTab T1

IF @varKSfl=1 
	select [month] as [Месяц],pers_summa_vkr as [Сумма ФЛ с нач года по ВКР], summa_vkr as [Сумма сотр с нач года по ВКР], summa_m as [Сумма сотр за месяц], 
	summa_m_vkr as [Сумма сотр за месяц по ВКР], ded_m_all as [Скидки всего], ded as [Скидки всего по ВКР], ded_m as [Скидки за месяц по ВКР], 
	vych as [Вычеты всего], vych_m  as [Вычеты за месяц] from @varKSTota

----
declare @varKSSumDed numeric(15,2), @varKSRange  numeric(15,2), @varKSResid int, @varKSStrCom varchar(1000)

SET @varKSSumDed = ISNULL(
	(SELECT sum(summa) 
	FROM
		dbo.PAYS P INNER JOIN dbo.CALCULATE_JURNAL SJ ON P.LINK = SJ.LINK_PAYS
	WHERE
		SJ.LINK_PAYS = @varKSRef_Pay
		AND YEAR(SJ.PERIOD_BEGIN) = @varKSYear
		AND MONTH(SJ.PERIOD_BEGIN) <=@varKSMonth 
		AND SJ.LINK_EMPL = @varKSlinkEmpl 
		AND SJ.LINK_VKR = @varKSLinkVKR
		AND SJ.LINK_DEP = @DEP_LINK 
		AND ISNULL(SJ.LINK_EKR,P.LINK_EKR) = @varKSLinkEKR)
	,0)	
	
SET @varKSSumDed = @varKSSumDed + ISNULL( (SELECT SUM(SR.NDFL) FROM dbo.SAL_REMAIN SR WHERE SR.LINK_EMPL = @varKSlinkEmpl AND SR.YEAR_SAL = @varKSYear AND SR.LINK_VKR = @varKSLinkVKR AND SR.LINK_EKR = @varKSLinkEKR), 0)

set @varKSRange =  dbo.SalaryGetNDFLRange (@varKSlinkEmpl,@varKSDate)
set @varKSResid = dbo.GetEmplResident(@varKSlinkEmpl)

IF @varKSfl=1 
	select [Удержано с нач года] = @varKSSumDed, [Ставка налога] = @varKSRange, [Статус] = (case when @varKSResid = 1  then 'Резидент' else 'Не резидент' end)


set @varKSStrCom = ''
DECLARE @varKSCurs CURSOR,
		  @varKSCurCOMMENT varchar(255)

SET @varKSCurs = CURSOR FORWARD_ONLY
FOR SELECT COMMENT FROM @varKSvych WHERE DEDUCT <> 0 and [month]=@varKSMonth
OPEN @varKSCurs
FETCH NEXT FROM @varKSCurs INTO @varKSCurCOMMENT
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @varKSStrCom = @varKSStrCom + ' ' + isnull(@varKSCurCOMMENT,'0')+ ' +'
	FETCH NEXT FROM @varKSCurs INTO @varKSCurCOMMENT
END 
CLOSE @varKSCurs
DEALLOCATE @varKSCurs
IF LEN(@varKSStrCom) > 2
	SET @varKSStrCom = LEFT(@varKSStrCom,LEN(@varKSStrCom)-2) 


IF @varKSfl=1 
BEGIN	
	PRINT 'Расчет налога с общего дохода по КБК'
	
	SELECT T.*,
	[sum_ded]=  isnull(@varKSSumDed,0),
	[summa] = 	case when DOHOD_ALL > VICHET_ALL THEN
					convert(numeric(18,2),(summa_vkr -ded - (case when @varKSResid = 1 then vych else 0 end))*@varKSRange/100)
				ELSE
					0
				END,
	[comment] = @varKSStrCom
	FROM @varKSTota T
	WHERE [MONTH] = @varKSMonth
	
END

/*Вычеты, скидки и налог пропорционально доли больничных за счет ФСС/зарплате в общем доходе работника*/
IF @varKSfl<>1 
SELECT 
	[MONTH],
	PERS_SUMMA_VKR= convert(numeric(18,2), [PERS_SUMMA_VKR]),
	SUMMA_VKR= convert(numeric(18,2), [SUMMA_VKR]),
	SUMMA_M= convert(numeric(18,2), [SUMMA_M]),
	SUMMA_M_VKR= convert(numeric(18,2), [SUMMA_M_VKR]),
	DED_M_ALL= convert(numeric(18,2), [DED_M_ALL]),
	DED= convert(numeric(18,2),[DED]),
	DED_M= convert(numeric(18,2),[DED_M]),
	VYCH= convert(numeric(18,2), [VYCH]),
	VYCH_M= convert(numeric(18,2), [VYCH_M]),
	[sum_ded]=  convert(numeric(18,0), isnull(@varKSSumDed,0)), 
	[summa] = 	case when convert(numeric(18,0),(summa_vkr -ded - (case when @varKSResid = 1 then vych else 0 end))*@varKSRange/100) > 0
			then 
				case when DOHOD_ALL > VICHET_ALL THEN
					convert(numeric(18,0),(summa_vkr -ded - (case when @varKSResid = 1 then vych else 0 end))*@varKSRange/100)
				ELSE
					0
				END					
			else 
				CASE WHEN @NDFL_OPT8 = 0 
				THEN 
					0
				ELSE
					convert(numeric(18,0),(summa_vkr -ded - (case when @varKSResid = 1 then vych else 0 end))*@varKSRange/100)
				END
			end,
	[comment] = Case when len(rtrim(ltrim(@varKSStrCom))) > 0 then '{' + RTRIM(LTRIM(@varKSStrCom)) + '}' else '' end,
	[RANGE] = @varKSRange/100
FROM @varKSTota T
WHERE [MONTH] = @varKSMonth




GO


GRANT EXECUTE ON dbo.[SD_U_NDFL_FILL] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RN_PRINT_169_2015]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RN_PRINT_169_2015]

GO

/*
© Кейсистемс (Keysystems), 2009
*/

CREATE PROCEDURE dbo.[RN_PRINT_169_2015]
	@namesTables varchar(8000),        -- имена глобальных временных таблиц через запятую, где хранятся таблицы
									-- нужно самим сделать select, первый select отностится к c_data2
									-- после работы, нужно удалить!
	@LSF int
AS
	create table #all (COL1 varchar(8000), COL2 varchar(8000), COL3 float, COL4 float, COL5 float, COL6 varchar(8000),  CODE varchar(50), DEL bit, ITOG int, orders int IDENTITY(1,1))
	declare @table varchar(100), @RunStr varchar(8000),@table1 varchar(100),@table2 varchar(100),@table3 varchar(100) 
	
	exec dbo.RO_FORMULA_FUNCTIONS 1, @namesTables output, @table1 output, ','

	set @RunStr = 'DELETE A 
	               FROM  ' + @table1 +' A 
	               WHERE EXISTS(SELECT * FROM '+@table1 +' B WHERE SUBSTRING(A.CODE,18,9) = SUBSTRING(B.CODE,18,9) AND SUBSTRING(B.CODE,1,17) <> ''00000000000000000'')  
	               AND SUBSTRING(A.CODE,1,17) = ''00000000000000000'''  
   PRINT @RunStr
	execute(@RunStr)

--	set @RunStr = 'SELECT * FROM ' + @table1 
--	execute(@RunStr)

--	set @RunStr = 'drop table ' + @table1
--	execute(@RunStr)


	exec dbo.RO_FORMULA_FUNCTIONS 1, @namesTables output, @table2 output, ','
	set @RunStr = 'DELETE A 
	               FROM  ' + @table2 +' A 
	               WHERE EXISTS(SELECT * FROM '+@table2 +' B WHERE SUBSTRING(A.CODE,18,9) = SUBSTRING(B.CODE,18,9) AND SUBSTRING(B.CODE,1,17) <> ''00000000000000000'')  
	               AND SUBSTRING(A.CODE,1,17) = ''00000000000000000'''  
   PRINT @RunStr
	execute(@RunStr)

--	set @RunStr = 'SELECT * FROM ' + @table2 
--	execute(@RunStr)

--	set @RunStr = 'drop table ' + @table2
--	execute(@RunStr)

	exec dbo.RO_FORMULA_FUNCTIONS 1, @namesTables output, @table3 output, ','
	set @RunStr = 'DELETE A 
	               FROM  ' + @table3 +' A 
	               WHERE EXISTS(SELECT * FROM '+@table3 +' B WHERE SUBSTRING(A.CODE,18,9) = SUBSTRING(B.CODE,18,9) AND SUBSTRING(B.CODE,1,17) <> ''00000000000000000'')  
	               AND SUBSTRING(A.CODE,1,17) = ''00000000000000000'''  
   PRINT @RunStr
	execute(@RunStr)

--	set @RunStr = 'SELECT * FROM ' + @table3 
--	execute(@RunStr)

--	set @RunStr = 'drop table ' + @table3
--	execute(@RunStr)


set @RunStr = 'SELECT DEL,ORDERS, CODE,COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9 FROM ' + @table1 +'
UNION ALL  
SELECT DEL,ORDERS,CODE,COL1,COL2+COL3+COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11 FROM ' + @table2 +'
UNION ALL
SELECT DEL,ORDERS,CODE,COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9 FROM ' + @table3 
execute(@RunStr)

set @RunStr = 'SELECT * FROM ' + @table2 +' WHERE 1=0' 
execute(@RunStr)

set @RunStr = 'SELECT * FROM ' + @table3 +' WHERE 1=0' 
execute(@RunStr)

	
exec dbo.RO_FORMULA_FUNCTIONS 1, @namesTables output, @table output, ','
set @RunStr = 'SELECT * FROM ' + @table 
PRINT @RunStr
execute(@RunStr)

set @RunStr = 'drop table ' + @table
execute(@RunStr)


GO


GRANT EXECUTE ON dbo.[RN_PRINT_169_2015] TO PUBLIC

GO



GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RB_CALC_0503125G_15_NEW]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RB_CALC_0503125G_15_NEW]

GO

/*
    © Кейсистемс (Keysystems), 2007
    Процедура формирования строк и значений формы 0503125
*/

CREATE PROCEDURE dbo.RB_CALC_0503125G_15_NEW
@iLSF int,
@table int
AS

declare @dBeginDate datetime,
		@dEndDate datetime,
		@dEndDate_pl datetime,
		@dCALC_DATE datetime,
		@iThisDep int,
		@nPeriod_Type tinyint,
		@cStrSql varchar(8000)
----------		
DECLARE @LF	int, 
		@LT	int,
		@LC	int,
		@orderCol int,
		@iLinkCalcForm int,
		@iLinkColDt int,
		@bid varchar(100),
		@nabor_filter varchar(1000)
---------------
				
declare @tTempRes table(DEP_NAME varchar(254),
						INN VARCHAR(12),
						PPP varchar(3), 
						OKTMO varchar(11), 
						EL_BUDG varchar(2), 
						KBK varchar(17), 
						ACC_CODE varchar(9), 
						summa_db numeric(20,4), 
						summa_kr numeric(20,4), 
						korr_acc varchar(9), 
						DEP_K_NAME varchar(254),
						INN_K VARCHAR(12),
						PPP_K varchar(3), 
						OKTMO_K varchar(11), 
						D_ND tinyint) 

declare @tTempRes2 table(DEP_NAME varchar(254),
						 INN VARCHAR(12),
						 PPP varchar(3), 
						 OKTMO varchar(11), 
						 EL_BUDG varchar(2), 
						 KBK varchar(17), 
						 ACC_CODE varchar(9), 
						 summa_db numeric(20,4), 
						 summa_kr numeric(20,4), 
						 korr_acc varchar(9),
						 DEP_K_NAME varchar(254),
						 INN_K VARCHAR(12),
						 PPP_K varchar(3), 
						 OKTMO_K varchar(11),  
						 D_ND tinyint,
						 NUM_PP int IDENTITY(1,1)) 
declare @filter_kbk table (kbk varchar(20))

-- определяем период (если в январе формируем, то берём весь предыдущий год не включая 31 декабря)
select @dEndDate = Begin_Date, @nPeriod_Type = period_type from dbo.report_saved_forms where link_saved_form = @iLSF

select @dBeginDate = dbo.DateBeginOfYear(@dEndDate)

-- set @dEndDate = case when datepart(mm,(@dBeginDate - (datepart(dd,@dBeginDate)))) = 12 then (@dBeginDate - (datepart(dd,@dBeginDate))) - 1 else @dBeginDate /*- (datepart(dd,@dBeginDate))*/ end
-- set @dBeginDate = convert(datetime,convert(char(4),YEAR(@dEndDate))+'-01'+'-01'+' 00:00:00.000')


--if @nPeriod_Type <> 1 
--	set @dEndDate = case when datepart(mm,(@dBeginDate - (datepart(dd,@dBeginDate)))) = 12 then @dBeginDate - 1 else @dBeginDate end
--else
--	set @dEndDate = @dBeginDate
--
--	set @dBeginDate = convert(datetime,convert(char(4),YEAR(@dEndDate))+'-01'+'-01'+' 00:00:00.000')

select @nabor_filter = REPLACE(dbo.rn_get_atr_value(@iLSF,'REPORTS_FILTER_KBK'), 'Не отобрано', '')

insert @filter_kbk (kbk)   
Select RTRIM(code) FROM rn_get_filter(@iLSF,'REPORTS_FILTER_KBK')


---------------------------------------****************************
declare @temp_nastr table (link int, [Link_Col] int NOT NULL, 
	[Calc_Order] int NOT NULL , [Sign] tinyint NOT NULL, link_dt int, link_kt int, dt_ekr varchar(1000),
	kt_ekr varchar(1000), [type] tinyint, type_kbk tinyint, mask_kbk varchar(100), dt_kt tinyint)
declare @temp_nastr_xor table (	link int, [Link_Col] int NOT NULL , 
	[Calc_Order] int NOT NULL , [Sign] tinyint NOT NULL , link_dt int, link_kt int, dt_ekr varchar(1000),
	kt_ekr varchar(1000), [type] tinyint, type_kbk tinyint, dt_kt tinyint)
declare @temp_nastr_rest table (	link int, [Link_Col] int NOT NULL , 
	[Calc_Order] int NOT NULL , [Sign] tinyint NOT NULL , link_account int, ekr varchar(1000),
	[type] tinyint, type_kbk tinyint, mask_kbk varchar(100), dt_kt tinyint)
declare @temp_nastr_rest_xor table (link int, [Link_Col] int NOT NULL , 
	[Calc_Order] int NOT NULL , [Sign] tinyint NOT NULL , link_account int, ekr varchar(1000),
	[type] tinyint, type_kbk tinyint, dt_kt tinyint)


-------- ЧИТАЕМ ДАННЫЕ ОТЧЕТА
select @LF = RSF.Link_Form, 
		@iThisDep 	= Link_Organization, 
		@dEndDate	= Begin_Date + 1,
		@dCALC_DATE	= Begin_Date, 
		@dBeginDate	= dbo.DateBeginOfYear(Begin_Date),
		@nPeriod_Type = period_type
from report_saved_forms RSF  where RSF.link_saved_form = @iLSF

SET @iLinkCalcForm = dbo.RK_GET_NASTR_CALC_REPORT (@iLSF, 1)
print @iLinkCalcForm


if @iLinkCalcForm is null 
BEGIN
	exec RT_CALC_0503125G @iLSF, @table
	RETURN 0
END

set @iLinkColDt = (select top 1 RC.LINK_COL
					from dbo.REPORT_COLOUMNS RC
					inner join dbo.REPORT_TABLES RT on RC.Link_Table = RT.Link_Table and RT.Link_Form = @LF and RT.orders = @table and RT.orders = @table
					where @table = 2 and RC.Export_Order = 9 or @table <> 2 and RC.Export_Order = 7)
---------------------------------------------------------------------
----- ПОЛУЧАЕМ ВЫБОРКУ ИЗ ТАБЛИЦЫ НАСТРОЕК ----
insert @temp_nastr 
select C.link, C.Link_Col, Calc_Order, [Sign], DT.link , KT.link, dt_ekr, kt_ekr, [type], type_kbk, mask_kbk, dt_kt
from dbo.REPORT_CALC C 
INNER JOIN  dbo.REPORT_COLOUMNS RC on C.Link_Col = RC.Link_Col
INNER JOIN  dbo.REPORT_TABLES RT on RC.Link_Table = RT.Link_Table and RT.orders = @table and RT.Link_Form = @LF
INNER JOIN dbo.report_calc_rows CR on CR.Link_calc = C.link
left join dbo.s_accounts DT on
	DT.Code like case when CR.DT_Mask = '%' or rtrim (CR.DT_Mask) = '' then 'x' else rtrim (CR.DT_Mask) + '%' end
left join dbo.s_accounts KT on
	KT.Code like case when CR.KT_Mask = '%' or rtrim (CR.KT_Mask) = ''then 'x' else rtrim (CR.KT_Mask) + '%' end
WHERE C.LINK_UP = @iLinkCalcForm
	AND [sign] in (1,2) and CR.[type] = 1 
	AND (rtrim (CR.DT_Mask) = '' OR CR.DT_Mask = '%' OR rtrim (CR.DT_Mask) <> '' AND DT.LINK IS NOT NULL)
	AND (rtrim (CR.KT_Mask) = '' OR CR.KT_Mask = '%' OR rtrim (CR.KT_Mask) <> '' AND KT.LINK IS NOT NULL)


-- проводки, которые мы исключаем --
insert @temp_nastr_xor 
select C.link, C.Link_Col, Calc_Order, [Sign], DT.link , KT.link, dt_ekr, kt_ekr, [type], type_kbk, dt_kt
from dbo.report_calc C 
INNER JOIN  dbo.REPORT_COLOUMNS RC on C.Link_Col = RC.Link_Col
INNER JOIN  dbo.REPORT_TABLES RT on RC.Link_Table = RT.Link_Table and RT.orders = @table and RT.Link_Form = @LF
INNER JOIN dbo.report_calc_rows CR on CR.Link_calc = C.link
left join dbo.s_accounts DT on
	DT.Code like case when CR.DT_Mask = '%' or rtrim (CR.DT_Mask) = '' then 'x' else rtrim (CR.DT_Mask) + '%' end
left join dbo.s_accounts KT on
	KT.Code like case when CR.KT_Mask = '%' or rtrim (CR.KT_Mask) = ''then 'x' else rtrim (CR.KT_Mask) + '%' end
where C.LINK_UP = @iLinkCalcForm
	AND [sign] = 3 and CR.[type] = 1 


--- Выборка счетов для расчета остатков ---
insert @temp_nastr_rest 
select C.link, C.Link_Col, Calc_Order, [Sign],
	case
		when DT.link is NULL then KT.link
		else DT.link
	end,
	case
		when DT.link is NULL then kt_ekr
		else dt_ekr
	end, [type],
	type_kbk,
	mask_kbk,
	dt_kt
from dbo.report_calc C 
INNER JOIN  dbo.REPORT_COLOUMNS RC on C.Link_Col = RC.Link_Col
INNER JOIN  dbo.REPORT_TABLES RT on RC.Link_Table = RT.Link_Table and RT.orders = @table and RT.Link_Form = @LF
INNER JOIN dbo.report_calc_rows CR on CR.Link_calc = C.link
left join dbo.s_accounts DT on
	DT.Code like case when CR.DT_Mask = '%' or rtrim (CR.DT_Mask) = '' then 'x' else rtrim (CR.DT_Mask) + '%' end
left join dbo.s_accounts KT on
	KT.Code like case when CR.KT_Mask = '%' or rtrim (CR.KT_Mask) = ''then 'x' else rtrim (CR.KT_Mask) + '%' end
WHERE C.LINK_UP = @iLinkCalcForm 
	AND CR.[type] in (2,3) and [sign] in (1,2) 
	AND (rtrim (CR.DT_Mask) = '' OR rtrim (CR.DT_Mask) <> '' AND DT.LINK IS NOT NULL)
	AND (rtrim (CR.KT_Mask) = '' OR rtrim (CR.KT_Mask) <> '' AND KT.LINK IS NOT NULL)

/*
select S1.CODE, * from @temp_nastr_rest T, S_ACCOUNTS S1 
WHERE S1.LINK = T.LINK_account
*/
--- Счета, которые исключаем для расчета остатков ---
insert @temp_nastr_rest_xor
select C.link, C.Link_Col, Calc_Order, [Sign],
	case
		when DT.link is NULL then KT.link
		else DT.link
	end,
	case
		when DT.link is NULL then kt_ekr
		else dt_ekr
	end,
	[type],
	type_kbk,
	dt_kt
from dbo.report_calc C 
INNER JOIN  dbo.REPORT_COLOUMNS RC on C.Link_Col = RC.Link_Col
INNER JOIN  dbo.REPORT_TABLES RT on RC.Link_Table = RT.Link_Table and RT.orders = @table and RT.Link_Form = @LF
INNER JOIN dbo.report_calc_rows CR on CR.Link_calc = C.link
left join dbo.s_accounts DT on
	DT.Code like case when CR.DT_Mask = '%' or rtrim (CR.DT_Mask) = '' then 'x' else rtrim (CR.DT_Mask) + '%' end
left join dbo.s_accounts KT on
	KT.Code like case when CR.KT_Mask = '%' or rtrim (CR.KT_Mask) = ''then 'x' else rtrim (CR.KT_Mask) + '%' end
WHERE  C.LINK_UP = @iLinkCalcForm 
	AND CR.[type] in (2,3) and [sign] = 3 
	AND (DT.LINK IS NOT NULL
		OR KT.LINK IS NOT NULL)
---------------------------------------****************
---- Обороты

	insert into @tTempRes
	select	DEP_NAME = isnull(D.FULL_NAME, 'корреспондент_не_указан'), -- Наименование контрагента
			INN = isnull(D.INN, ''),
			PPP = case when TMP.Mask_KBK like '%АДМ%' then isnull(VED.CODE, '') else '' end, -- ППП
			--OKATO = case when TMP.Mask_KBK like '%ОКАТО%' then isnull(replace(D.OKATO,' ',''), '') else '' end, -- ОКАТО
			OKTMO = case when TMP.Mask_KBK like '%ОКТМО%' then isnull(replace(D.OKTMO,' ',''), '') else '' end, -- ОКАТО
			EL_BUDG = case when TMP.Mask_KBK like '%ЭЛЕМЕНТ%' then isnull(BUDG.CODE_EL, '') else '' end, -- Элемент бюджета
			KBK = isnull(replace(KBK.CODE,'.',''),''), --KBK
			ACC_CODE = case TMP.dt_kt when 0 then isnull(left(replace(SAD.CODE,'.',''),6),'') + isnull(DTS.CODE,'') else isnull(left(replace(SAK.CODE,'.',''),6),'') + isnull(KTS.CODE,'')  end,
			SUMMA_DB = case TMP.LINK_COL when @iLinkColDt then isnull(G2.SUMMA,'') else 0 end, -- сумма дебет
			SUMMA_KR = case TMP.LINK_COL when @iLinkColDt then 0 else isnull(G2.SUMMA,'') end, -- сумма кредит
			korr_acc = case TMP.dt_kt when 0 then isnull(left(replace(SAK.CODE,'.',''),6),'')  + isnull(KTS.CODE,'') else isnull(left(replace(SAD.CODE,'.',''),6),'') + isnull(DTS.CODE,'')  end, -- корреспондирующий счет
			DEP_K_NAME = '',
			INN_K = '',
			PPP_K = '', 
			OKTMO_K = '', 
			D_ND = case when TMP.Mask_KBK like '%ДЕН%' then 1 else 0 end-- Признак платежа

	FROM dbo.G_PROV G
	INNER JOIN dbo.G_PROV1 G1 ON (G1.LINK_UP = G.LINK)
	INNER JOIN dbo.G_PROV2 G2 ON (G2.LINK_UP = G1.LINK)


	LEFT JOIN dbo.G_PROV_AP DT ON (DT.LINK_UP = G2.LINK AND DT.DB_KR = 0)
	LEFT JOIN dbo.G_PROV_AP KT ON (KT.LINK_UP = G2.LINK AND KT.DB_KR = 1)

	LEFT JOIN dbo.KOSGU DTS ON (DTS.Link = DT.SGU)
	LEFT JOIN dbo.KOSGU KTS ON (KTS.Link = KT.SGU)
	
	INNER JOIN @TEMP_NASTR TMP ON (TMP.LINK_DT = DT.ACCOUNT OR TMP.LINK_DT IS NULL)
			AND (TMP.LINK_KT = KT.ACCOUNT OR TMP.LINK_KT IS NULL)
		AND (dbo.RO_LIKE_LIST(DTS.Code, TMP.DT_EKR) > 0 OR TMP.DT_EKR = '')
		AND (dbo.RO_LIKE_LIST(KTS.Code, TMP.KT_EKR) > 0 OR TMP.KT_EKR = '')

	LEFT JOIN dbo.S_ACCOUNTS SAD ON SAD.LINK = DT.ACCOUNT

	LEFT JOIN dbo.S_ACCOUNTS SAK ON SAK.LINK = KT.ACCOUNT 

	LEFT JOIN dbo.KL_KBK KBK ON (TMP.dt_kt = 0 AND KBK.LINK = DT.KBK OR TMP.DT_KT = 1 AND KBK.LINK = KT.KBK)
	left join dbo.G_PROV_OS1 OS on OS.LINK_OS1 = G.LINK
	LEFT JOIN dbo.DEPARTMENTS D ON D.LINK = (case	when DT.Dep is not NULL and DT.Dep <> G.Dep then DT.Dep
										when KT.Dep is not NULL and KT.Dep <> G.Dep then KT.Dep
										when OS.Dep_pass is not NULL and OS.Dep_pass <> G.Dep then OS.Dep_pass
										when OS.Dep_receive is not NULL and OS.Dep_receive <> G.Dep then OS.Dep_receive
										else isnull((SELECT top 1 GPDA.DEPARTMENT FROM dbo.G_PROV_DEPARTMENT GPDA, dbo.S_OBJECTS SO WHERE GPDA.DOC_LINK = G.LINK AND GPDA.OBJECT = SO.LINK and (SO.CODE = 'NOTICE_LINK_DEP_RECEIVER' or SO.CODE = 'NOTICE_LINK_DEP_SENDER') AND GPDA.DEPARTMENT <> G.Dep), NULL) end)
	left join dbo.KL_ADMIN_BS VED WITH (NOLOCK) on VED.LINK = D.VED_LINK
	left join dbo.KL_BUDG_TYPE BUDG WITH (NOLOCK) on VED.Link_Budg = BUDG.LINK
	LEFT JOIN @filter_kbk F on KBK.Code = F.kbk
	WHERE G.DATE_PROV BETWEEN @dBeginDate AND @dCALC_DATE
		AND G.DEP = @iThisDep
		AND (F.kbk IS NOT NULL OR isnull(@nabor_filter, '') = '')
		AND (TMP.TYPE_KBK = 0 OR (TMP.TYPE_KBK & KBK.[TYPE]) / KBK.[TYPE] = 1)
		AND not exists(select top 1 *
				from @temp_nastr_xor xor
				where xor.link = tmp.link
					and xor.link_dt = dt.account and xor.link_kt = kt.account
					and (CHARINDEX(RTRIM(DTS.Code), xor.dt_ekr) > 0
						or RTRIM(isnull(DTS.Code,'')) like RTRIM(xor.dt_ekr) + '%') 
					and (RTRIM(isnull(KTS.Code,'
			')) like RTRIM(xor.kt_ekr) + '%' or CHARINDEX(RTRIM(KTS.Code),xor.kt_ekr) > 0)) -- исключаем
			
----------------- остатки ------------------------------
while exists(select top 1 * from @temp_nastr_rest)
begin
	select top 1 @LC = Link_Col from @temp_nastr_rest

	set @bid = 'calc_col_' + LTRIM(RTRIM(STR(@LC)))

	insert dbo.buffer(ID, Link)
	select @bid, link_account
	from @temp_nastr_rest
	where link_col = @LC

	-- остаток на конец периода
	insert into @tTempRes
	select	DEP_NAME = isnull(D.FULL_NAME, 'корреспондент_не_указан'), -- Наименование контрагента
			INN = isnull(D.INN, ''),
			PPP = case when R.Mask_KBK like '%АДМ%' then isnull(VED.CODE, '') else '' end, -- ППП
			OKTMO = case when R.Mask_KBK like '%ОКТМО%' then isnull(replace(D.OKTMO,' ',''), '') else '' end, -- ОКАТО
			EL_BUDG = case when R.Mask_KBK like '%ЭЛЕМЕНТ%' then isnull(BUDG.CODE_EL, '') else '' end, -- Элемент бюджета
			KBK = isnull(replace(K.CODE,'.',''),''), --KBK
			ACC_CODE = isnull(left(replace(SA.CODE,'.',''),6),'') + '000',
			SUMMA_DB = case when R.LINK_COL = @iLinkColDt and (SA.S_PASSIVE = 1 and [sign] = 1 OR SA.S_ACTIVE = 1 and [sign] = 2) then isnull(k_summa - d_summa,'') 
							when R.LINK_COL = @iLinkColDt and (SA.S_PASSIVE = 2 and [sign] = 2 OR SA.S_ACTIVE = 1 and [sign] = 1) then isnull(d_summa - k_summa,'') 
							else 0 end, -- сумма дебет
			
			SUMMA_KR = case when R.LINK_COL <> @iLinkColDt and (SA.S_PASSIVE = 1 and [sign] = 1 OR SA.S_ACTIVE = 1 and [sign] = 2) then isnull(d_summa - k_summa,'') 
							when R.LINK_COL <> @iLinkColDt and (SA.S_PASSIVE = 2 and [sign] = 2 OR SA.S_ACTIVE = 1 and [sign] = 1) then isnull(k_summa - d_summa,'') 
							else 0 end, -- сумма кредит
			korr_acc = '000000000',
			DEP_K_NAME = '',
			INN_K = '',
			PPP_K = '', 
			OKTMO_K = '', 
			D_ND = case when R.Mask_KBK like '%ДЕН%' then 1 else 0 end-- Признак платежа ,
			--R.Calc_Order
	from dbo.ARestTableByDateAccounts(@dEndDate, @bid) A
	INNER JOIN @temp_nastr_rest R on R.link_account = account and R.Link_Col = @LC and R.[Type] = 3
	LEFT JOIN dbo.KL_KBK K on K.Link = A.KBK and (R.TYPE_KBK & (case K.[TYPE] when 3 then 4 when 4 then 8 else K.[TYPE] end) > 0)
	left join dbo.S_ACCOUNTS SA on SA.Link = A.ACCOUNT
	LEFT JOIN dbo.DEPARTMENTS D ON D.LINK = A.DEP
	left join dbo.KL_ADMIN_BS VED WITH (NOLOCK) on VED.LINK = D.VED_LINK
	left join dbo.KL_BUDG_TYPE BUDG WITH (NOLOCK) on VED.Link_Budg = BUDG.LINK
	LEFT JOIN @filter_kbk F on K.Code = F.kbk
	where dep_link = @iThisDep
			and not exists(select top 1 * from @temp_nastr_rest_xor R1 where [type] = 2 and R1.link_account = A.account and r1.link = r.link)
		AND (F.kbk IS NOT NULL OR isnull(@nabor_filter, '') = '')
		AND (R.TYPE_KBK = 0 OR (R.TYPE_KBK & K.[TYPE]) / K.[TYPE] = 1)
		



-- select * from #tTemp
	
	delete @temp_nastr_rest where Link_Col = @LC

	exec dbo.BufferClear @bid	
end


insert into @tTempRes2 (DEP_NAME,INN, PPP, OKTMO, EL_BUDG, ACC_CODE, KBK, summa_db, summa_kr, KORR_ACC,DEP_K_NAME,INN_K,PPP_K,OKTMO_K, D_ND)
select DEP_NAME,INN, PPP, OKTMO, EL_BUDG, ACC_CODE, KBK, SUM(summa_db), SUM(summa_kr), KORR_ACC,DEP_K_NAME,INN_K,PPP_K,OKTMO_K, D_ND
from @tTempRes 
where DEP_NAME <> 'корреспондент_не_указан'
group by DEP_NAME,INN, PPP, OKTMO, EL_BUDG, ACC_CODE, KBK, KORR_ACC,DEP_K_NAME,INN_K,PPP_K,OKTMO_K, D_ND
union
select DEP_NAME,INN, PPP, OKTMO, EL_BUDG, ACC_CODE, KBK, SUM(summa_db), SUM(summa_kr), KORR_ACC,DEP_K_NAME,INN_K,PPP_K,OKTMO_K, D_ND
from @tTempRes 
where DEP_NAME = 'корреспондент_не_указан'
group by DEP_NAME,INN, PPP, OKTMO, EL_BUDG, ACC_CODE, KBK, KORR_ACC,DEP_K_NAME,INN_K,PPP_K,OKTMO_K, D_ND



if @table in (1,3) 
	SELECT 
--	[CODE] = LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKATO)+'00000000000',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
--	[CODE] = LEFT(RTRIM(PPP)+'   ',3) + LEFT(RTRIM(OKATO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '  ',2) + LEFT(rtrim(KBK) + '                 ',17) + LEFT(RTRIM(KORR_ACC) + '         ',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[CODE] = LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKTMO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[COL1] = DEP_NAME, -- Наименование контрагента
	[COL2] = INN,
	[COL3] = PPP, -- ППП
	[COL4] = OKTMO, -- ОКАТО
	[COL5] = EL_BUDG, -- Элемент бюджета
	[COL6] = substring(rtrim(KBK),1,3), -- АДМ
	[COL7] = substring(rtrim(KBK),4,14), -- КБК
	[COL8] = SUMMA_DB, -- сумма дебет
	[COL9] = SUMMA_KR, -- сумма кредит
	[COL10] = KORR_ACC, -- Код корреспондирующего счёта бюджетного учета
	[COL11] = DEP_K_NAME,
	[COL12] = INN_K,
	[COL13] = PPP_K,
	[COL14] = OKTMO_K,
	[COL15] = cast (isnull(d_nd,'') as varchar), -- Признак платежа
	[COL16]= LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKTMO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[COL17]= RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8)
	FROM @tTempRes2
	where  summa_db <> 0 or summa_kr <> 0
	ORDER BY NUM_PP

else 
	SELECT 
	--[CODE] = LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKATO)+'00000000000',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	--[CODE] = LEFT(RTRIM(PPP)+'   ',3) + LEFT(RTRIM(OKATO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '  ',2) + LEFT(rtrim(KBK) + '                 ',17) + LEFT(RTRIM(KORR_ACC) + '         ',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[CODE] = LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKTMO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[COL1] = DEP_NAME, -- Наименование контрагента
	[COL2] = INN,
	[COL3] = PPP, -- ППП
	[COL4] = OKTMO, -- ОКАТО
	[COL5] = EL_BUDG, -- Элемент бюджета
	[COL6] = substring(rtrim(KBK),1,3), -- АДМ
	[COL7] = substring(rtrim(KBK),4,4), -- РзПр
	[COL8] = substring(rtrim(KBK),8,7), -- ЦСР
	[COL9] = substring(rtrim(KBK),15,3),-- ВР
	[COL10] = SUMMA_DB, -- сумма дебет
	[COL11] = SUMMA_KR, -- сумма кредит
	[COL12] = KORR_ACC, -- Код корреспондирующего счёта бюджетного учета
	[COL13] = DEP_K_NAME,
	[COL14] = INN_K,
	[COL15] = PPP_K,
	[COL16] = OKTMO_K,
	[COL17] = cast (isnull(d_nd,'') as varchar), -- Признак платежа
	[COL18] = LEFT(RTRIM(PPP)+'000',3) + LEFT(RTRIM(OKTMO)+'           ',11) + LEFT(RTRIM(EL_BUDG) + '00',2) + LEFT(rtrim(KBK) + '00000000000000000',17) + LEFT(RTRIM(KORR_ACC) + '000000000',9) + RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8), -- Код строки.
	[COL19] = RIGHT('00000000' + LTRIM(CAST(ISNULL(NUM_PP,0) as VARCHAR(8))),8)
	FROM @tTempRes2
	where  summa_db <> 0 or summa_kr <> 0
	ORDER BY NUM_PP




GO


GRANT EXECUTE ON dbo.[RB_CALC_0503125G_15_NEW] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_AO_FILL_AVANSE_TABLE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_AO_FILL_AVANSE_TABLE]

GO
CREATE PROCEDURE dbo.BK_AO_FILL_AVANSE_TABLE
	@BUFFER	VARCHAR (100),
	@EMP	INT,
	@DEP_LINK INT,
	@KBK	INT,
	@cACCOUNT VARCHAR (20),
	@DOC_DATE DATETIME
AS
BEGIN
	DECLARE
		@ACCOUNT	INT
	
	SELECT
		@EMP =	ISNULL (@EMP, 0),
		@KBK =	ISNULL (@KBK, 0)
	
	IF ISNULL (@cACCOUNT, '') = '' 
		SET @cACCOUNT =	'208'

	DECLARE @T_REST1 TABLE
		(
		LINK	INT IDENTITY (1, 1),
		DEP_LINK	INT,
		ACCOUNT	INT,
		KBK	INT,
		EMP	INT,
		EKR	INT,
		SUMMA	NUMERIC (28,4)
		)

	SELECT TOP 1
		@ACCOUNT = LINK
	FROM dbo.S_ACCOUNTS
	WHERE CODE = @cACCOUNT

	SET @DOC_DATE = DATEADD (DAY, 1, @DOC_DATE)
	
	INSERT INTO @T_REST1 
		(
		DEP_LINK,
		ACCOUNT,
		KBK,
		EMP,
		EKR,
		SUMMA
		)

	-- По остаткам --	
	SELECT
		T1.DEP_LINK,
		T1.ACCOUNT,
		T1.KBK, 
		T1.EMP,
		T1.EKR,
		SUM (T1.D_SUMMA) + SUM (T1.K_SUMMA)
	FROM dbo.ARestTableByDate (@DOC_DATE, @ACCOUNT) T1
	WHERE @BUFFER = 'REST'
		AND T1.DEP_LINK = @DEP_LINK
		AND (@EMP = 0 OR T1.EMP = @EMP)
		AND (@KBK = 0 OR T1.KBK= @KBK)
	GROUP BY
		T1.DEP_LINK,
		T1.ACCOUNT,
		T1.KBK,
		T1.EMP,
		T1.EKR

	UNION ALL
	
	-- По документам --
	SELECT
		G.DEP,
		GAP.ACCOUNT,
		GAP.KBK, 
		GAP.EMP,
		GAP.EKR,
		SUM (G2.SUMMA)
	FROM (
		SELECT
			OSN.LINK_G_PROV
		FROM dbo.BufferGetTableByID (@BUFFER) BUF
		INNER JOIN dbo.OSNOV OSN ON (OSN.LINK = BUF.LINK)
		WHERE @BUFFER <> 'REST'
		GROUP BY
			OSN.LINK_G_PROV
		) AS T1
	INNER JOIN dbo.G_PROV G ON (G.LINK = T1.LINK_G_PROV)
	INNER JOIN dbo.G_PROV1 G1 ON (G1.LINK_UP = G.LINK)
	INNER JOIN dbo.G_PROV2 G2 ON (G2.LINK_UP = G1.LINK)	
	INNER JOIN dbo.G_PROV_AP GAP ON (GAP.LINK_UP = G2.LINK)
	INNER JOIN dbo.AccountsSubtreeByRoot (@ACCOUNT) SA0 ON (SA0.LINK = GAP.ACCOUNT)
	WHERE	
		G.DEP = @DEP_LINK
		AND (@EMP = 0 OR GAP.EMP = @EMP)
		AND (@KBK = 0 OR GAP.KBK= @KBK)
	GROUP BY
		G.DEP,
		GAP.ACCOUNT,
		GAP.KBK, 
		GAP.EMP,
		GAP.EKR

	SELECT
		T1.*,
		SA.CODE AS SA_CODE,
		SGU.CODE	AS EKR_CODE
	FROM @T_REST1 T1
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = T1.ACCOUNT)
	LEFT JOIN dbo.KOSGU SGU ON (SGU.LINK = T1.EKR)
	
	EXEC dbo.BufferClear @BUFFER

END

GO


GRANT EXECUTE ON dbo.[BK_AO_FILL_AVANSE_TABLE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[XK_NASTR_NEW_PLAN_ACCOUNTS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[XK_NASTR_NEW_PLAN_ACCOUNTS]

GO
CREATE PROCEDURE dbo.XK_NASTR_NEW_PLAN_ACCOUNTS
		(@BUF_NAME		VARCHAR (254) = '')
AS
BEGIN

	Declare @kassa int,
		@BB datetime,
		@BE datetime,

		@BB_old datetime,
		@BE_old datetime

	SELECT @BB_old = BEGINDATE,
		@BE_old = ENDDATE
	FROM dbo.ADMIN_INFO

	Select @kassa = LINK from dbo.S_OBJECTS Where CODE = 'KASSA'
	SELECT @BB = convert(datetime, '19000101', 112), @BE = convert(datetime, '21000101', 112)
	EXECUTE dbo.I_SET_ADMIN_DATE @kassa, @BB, @BB, @BE

	SET @BUF_NAME = ISNULL (@BUF_NAME, '')

	-- НАСТРОЙКИ ПЛАНА СЧЕТОВ --- 
	DECLARE 
		@KVD varchar (1),
		@KBK VARCHAR (30),  
		@ZABALANCE tinyint,
		@VKR tinyint,
		@KD tinyint,
		@KIVF tinyint,
		@KIVNF tinyint,
		@SINTH CHAR (3),
		@ANALIT CHAR (2),
		@AP TINYINT,
		@KSU TINYINT, @P_KASSA TINYINT, @EKR_ANALIT char (3), @EKR TINYINT, @NOMEN TINYINT,
		@INV TINYINT, @EMP TINYINT, @DEP TINYINT, @DOP TINYINT,
		@ACCT TINYINT, @OSNOV TINYINT, @SUB TINYINT,
		@cJO CHAR (2), @P_CONTROL TINYINT,
		@DEP_ACC TINYINT,
		@intJO	INT,
		@TMC INT,
		@intKBK_TYPE	TINYINT,
		@intP_EKR	TINYINT,
		@int_EKR0	INT,
		@S_ACCTIVE	TINYINT,
		@S_PASSIVE	TINYINT,
		@KAU		TINYINT,
		@MZ 		tinyint,
		@INDATE 	tinyint,
		@P_DATE 	TINYINT,
		@NOMEN_TYPE	TINYINT,

		@intROW_COUNT	INT,
		@intLINK_SELF	INT,
		@strName_Acct	VARCHAR (254),
		@strSGU CHAR (3),
		@intBUH_TYPE TINYINT,

		@intKVD	TINYINT, 
		@intMAX_KVD	TINYINT,
		@intBUH_TYPE_SOURCE	TINYINT,
		@iADDED_500		TINYINT,
		@iLOOP_COUNT	TINYINT
		

-- Тип КБК биты: 0  - ФКР, 1 - КД, 2 - КИВФ, 3 - КИВнФ
		
	/* --- НАСТРОЙКИ СФОРМИРОВАННОГО ПЛАНА СЧЕТОВ --- */
	DECLARE #ACCT_NASTR CURSOR STATIC LOCAL 
		FOR SELECT T1.SINTH, T1.ANALITH, T1.S_ACTIVE, T1.ZABALANCE,
				T1.KBK, T1.KSU,
				T1.P_KASSA, T1.EKR0, T1.AP_EKR,
				T1.AP_NOMEN, T1.AP_INV,
				T1.AP_EMP, AP_DEP, T1.AP_DOP,
				T1.AP_DEP_ACC, T1.AP_DOC,
				T1.AP_SUB, T1.P_NOCONTROL,
				T1.AP_TMC, T1.AP_INDATE,
				T1.AP_KAU, T1.JONUM,
				T1.[NAME],
				T1.P_DATE, T1.NOMEN_TYPE,
				T1.BUH_TYPE
			FROM dbo.S_ACCOUNTS_NASTR T1
			INNER JOIN dbo.S_ACCOUNTS_NEW_CONV T2 ON
				(
				(@BUF_NAME = ''
					OR @BUF_NAME <> '' AND T2.BUF_NAME = @BUF_NAME)
				AND T2.SINTH_NEW = T1.SINTH
				AND T2.ANALITH_NEW = T1.ANALITH
				AND T2.ZABALANCE = T1.ZABALANCE
				)
			ORDER BY T1.ZABALANCE, T1.SINTH, T1.ANALITH 
	--
	OPEN #ACCT_NASTR
	--
	FETCH #ACCT_NASTR
		INTO @SINTH, @ANALIT, @AP, @ZABALANCE,
			@KBK, @KSU, 
			@P_KASSA, @EKR_ANALIT, @EKR, 
			@NOMEN, @INV,  
			@EMP, @DEP, @DOP,
			@DEP_ACC, @OSNOV,
			@SUB, @P_CONTROL,
			@TMC, @INDATE,
			@KAU, @cJO,
			@strName_Acct,
			@P_DATE, @NOMEN_TYPE,
			@intBUH_TYPE

	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @intKBK_TYPE = CASE
					WHEN CHARINDEX ('КРБ', @KBK) > 0 THEN 1
					ELSE 0
				END
				+ CASE
					WHEN CHARINDEX ('КД', @KBK) > 0 THEN 2
					ELSE 0
				END
				+ CASE
					WHEN CHARINDEX ('КИФ', @KBK) > 0 THEN 12
					ELSE 0
				END

	
		IF @AP = 0	-- Пассивный счет --
		BEGIN
			SET @S_ACCTIVE	= 0
			SET @S_PASSIVE	= 1
		END
		ELSE
		BEGIN
			SET @S_ACCTIVE	= 1
			SET @S_PASSIVE	= 0
		END
	
--		SET @P_KASSA = 0
		SET @int_EKR0 = (SELECT LINK FROM dbo.KOSGU WHERE CODE = @EKR_ANALIT)
		IF @int_EKR0 IS NOT NULL
		BEGIN
			SET @EKR = 1
			SET @intP_EKR = 1
		END
		ELSE
			SET @intP_EKR = 0

		--- Источники финансирования ---
		IF @SINTH = '108' OR @SINTH = '104' AND LEFT (@ANALIT, 1) = '5'
			SET @intMAX_KVD = 1
		ELSE
			SET @intMAX_KVD = 7
			
		-- Для настройки 500 раздела ПС --
		IF @ZABALANCE = 0 AND @SINTH LIKE '50%' AND @ANALIT <> '00' AND @ANALIT <> ''
			SELECT
				@iADDED_500	=	1,
				@iLOOP_COUNT	=	1
		ELSE
			SELECT
				@iADDED_500	=	0,
				@iLOOP_COUNT	=	4

		WHILE @iLOOP_COUNT < 5
		BEGIN
			SET @intKVD = 0
			
			IF @iADDED_500 = 1
				SET @ANALIT = CONVERT (VARCHAR (2), @iLOOP_COUNT) + RIGHT (@ANALIT, 1)

			WHILE @intKVD <= @intMAX_KVD
			BEGIN 
				IF @intKVD = 3
					SET @intKVD = @intKVD + 1
					
				IF @intKVD = 1 OR @intKVD = 3
					SET @intBUH_TYPE = 1

				IF @intKVD = 2 OR @intKVD > 3
					SET @intBUH_TYPE = 6
					
				SET @KVD = CASE
								WHEN @intKVD = 0 THEN ''
								ELSE CONVERT (VARCHAR (1), @intKVD)
							END
										
				/* ---!!!Настройка аналитики у существующих счетов!!!--- */
				UPDATE dbo.S_ACCOUNTS SET [NAME] = CASE
									WHEN ISNULL (@strName_Acct, '') = '' THEN [NAME]
									ELSE LTRIM (@strName_Acct)
							END,
							KBK_TYPE = ISNULL (@intKBK_TYPE, KBK_TYPE),
							p_EKR = @intP_EKR,
							ANALIT_EKR = @int_EKR0,
							p_KASSA = @P_KASSA,
							KSU = @KSU, 
							p_NOCONTROL = @P_CONTROL,
							S_ACTIVE = ISNULL (@S_ACCTIVE, S_ACTIVE),
							S_PASSIVE = ISNULL (@S_PASSIVE, S_PASSIVE),
			
							/* --- АНАЛИТИКА --- */
							AP_KBK = 1,
							ap_NOMEN = CASE
									WHEN @NOMEN = 0 AND ap_NOMEN = 1 
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND NOMEN IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND NOMEN IS NOT NULL)
										THEN 1
									ELSE @NOMEN
								END,
							NOMEN_TYPE = CASE
									WHEN @NOMEN = 0 AND ap_NOMEN = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND NOMEN IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND NOMEN IS NOT NULL)
										THEN 1
									ELSE @NOMEN_TYPE
								END,
							ap_INV = CASE
									WHEN @INV = 0 AND ap_INV = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND INV IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND INV IS NOT NULL)
										THEN 1
									ELSE @INV
								END,
							ap_TMC = CASE
									WHEN @TMC = 0 AND ap_TMC = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND TMC IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND TMC IS NOT NULL)
										THEN 1
									ELSE @TMC
								END,
							ap_DEP = CASE
									WHEN @DEP = 0 AND ap_DEP = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND DEP IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND DEP IS NOT NULL)
										THEN 1
									ELSE @DEP
								END,
							ap_EKR = CASE
									WHEN @EKR = 0 AND ap_EKR = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND EKR IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND EKR IS NOT NULL)
										THEN 1
									ELSE @EKR
								END,
							ap_KAU = CASE
									WHEN @KAU = 0 AND ap_KAU = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND KAU IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND KAU IS NOT NULL)
										THEN 1
									ELSE @KAU
								END,
							ap_EMP = CASE
									WHEN @EMP = 0 AND ap_EMP = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND EMP IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND EMP IS NOT NULL)
										THEN 1
									ELSE @EMP
								END,
							ap_AP1 = CASE
									WHEN @OSNOV = 0 AND ap_AP1 = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND AP1 IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND AP1 IS NOT NULL)
										THEN 1
									ELSE @OSNOV
								END,
							ap_AP2 = CASE
									WHEN @DOP = 0 AND ap_AP2 = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND AP2 IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND AP2 IS NOT NULL)
										THEN 1
									ELSE @DOP
								END,
							ap_DEP_ACC = CASE
									WHEN @DEP_ACC = 0 AND ap_DEP_ACC = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND DEP_ACC IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND DEP_ACC IS NOT NULL)
										THEN 1
									ELSE @DEP_ACC
								END,
							ap_SUB = CASE
									WHEN @SUB = 0 AND ap_SUB = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND SUB IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND SUB IS NOT NULL)
										THEN 1
									ELSE @SUB
								END,
							ap_INDATE = CASE
									WHEN @INDATE = 0 AND ap_INDATE = 1
										AND EXISTS (SELECT * FROM dbo.G_PROV_AP WHERE ACCOUNT = SA.LINK AND INDATE IS NOT NULL)
										AND EXISTS (SELECT * FROM dbo.SALDO WHERE ACCOUNT = SA.LINK AND INDATE IS NOT NULL)
										THEN 1
									ELSE @INDATE
								END,
							BUH_TYPE = CASE
									WHEN SA.cSOURCE = '0' THEN 4
									ELSE @intBUH_TYPE
								END	
				FROM dbo.S_ACCOUNTS SA
				WHERE cSINTH = @SINTH
					AND cANALIT = @ANALIT
					AND cSOURCE = @KVD
					AND ZABALANS = @ZABALANCE
			
				/* ---!!!Добавление отсутсвующих счетов!!!--- */
				SELECT @intROW_COUNT = @@ROWCOUNT
				IF @intROW_COUNT = 0	
				BEGIN
					SET @S_ACCTIVE = ISNULL (@S_ACCTIVE, 0)
					SET @S_PASSIVE = ISNULL (@S_PASSIVE, 0)
		
					IF ISNULL (@strName_Acct, '') = ''
						SET @strName_Acct = 'Счет ' + @SINTH
		
					IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS WHERE cSINTH = @SINTH	/* -- Отсутвует раздел -- */	
									AND cANALIT = ''
									AND cSOURCE = ''
									AND cUSER = ''
									AND ZABALANS = @ZABALANCE)
					BEGIN
						SET @intLINK_SELF = NULL
						EXECUTE dbo.[X_PLAN_ACCOUNTS_GET_PARENT_LINK] @intLINK_SELF OUTPUT, 
																			@SINTH, 
																			'', 
																			'', 
																			'', 
																			@ZABALANCE
		
						IF @intLINK_SELF IS NOT NULL
							INSERT INTO dbo.S_ACCOUNTS ([NAME], cSINTH, cANALIT, cSOURCE, cUSER, LINK_SELF,
										KBK_TYPE, p_EKR, ANALIT_EKR,
										p_KASSA, KSU, p_NOCONTROL, S_ACTIVE, S_PASSIVE, 
										ap_EKR, ap_NOMEN, NOMEN_TYPE, ap_INV, ap_EMP, ap_DEP, ap_AP2,
										ap_DEP_ACC, ap_AP1, ap_SUB, ap_KAU, ZABALANS, AP_KBK,
										BUH_TYPE)
							VALUES (@strName_Acct, @SINTH, @ANALIT, @KVD, '',
									@intLINK_SELF, @intKBK_TYPE, @intP_EKR, @int_EKR0,
									@P_KASSA, @KSU, 0, @S_ACCTIVE, @S_PASSIVE,
									@EKR, @NOMEN, @NOMEN, @INV, @EMP, @DEP, @DOP, 0,
									@DEP_ACC, @OSNOV, @KAU, @ZABALANCE, 1,
									@intBUH_TYPE)
					END		/* -- Отсутвует раздел -- */
		
					IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS WHERE cSINTH = @SINTH	/* -- Отсутвует аналитический счет -- */	
									AND cANALIT = @ANALIT
									AND cSOURCE = ''
									AND cUSER = ''
									AND ZABALANS = @ZABALANCE)
					BEGIN
						SET @intLINK_SELF = NULL
						EXECUTE dbo.[X_PLAN_ACCOUNTS_GET_PARENT_LINK] @intLINK_SELF OUTPUT, 
																			@SINTH, 
																			'', 
																			@ANALIT, 
																			'', 
																			@ZABALANCE
		
						IF @intLINK_SELF IS NOT NULL
							INSERT INTO dbo.S_ACCOUNTS ([NAME], cSINTH, cANALIT, cSOURCE, cUSER, LINK_SELF,
									KBK_TYPE, p_EKR, ANALIT_EKR,
									p_KASSA, KSU, p_NOCONTROL, S_ACTIVE, S_PASSIVE, 
									ap_EKR, ap_NOMEN, NOMEN_TYPE, ap_INV, ap_EMP, ap_DEP, ap_AP2,
									ap_DEP_ACC, ap_AP1, ap_SUB, ap_KAU, ZABALANS, ap_kbk,
									BUH_TYPE)
							VALUES (@strName_Acct, @SINTH, @ANALIT, '', '',
									@intLINK_SELF, @intKBK_TYPE, 0, NULL,
									0, @KSU, 0, @S_ACCTIVE, @S_PASSIVE,
									@EKR, @NOMEN, @NOMEN, @INV, 0, @DEP, 0, 0,
									0, 0, @KAU, @ZABALANCE, 1,
									@intBUH_TYPE)
					END		/* -- Отсутвует аналитический счет -- */
		
					IF NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS WHERE cSINTH = @SINTH	/* -- Отсутвует счет C ИФ -- */	
									AND cANALIT = @ANALIT
									AND cSOURCE = @KVD
									AND cUSER = ''
									AND ZABALANS = @ZABALANCE)
					BEGIN
						SET @intLINK_SELF = NULL
						EXECUTE dbo.[X_PLAN_ACCOUNTS_GET_PARENT_LINK] @intLINK_SELF OUTPUT, 
																			@SINTH, 
																			@KVD, 
																			@ANALIT, 
																			'', 
																			@ZABALANCE

						IF @KVD = '0'
							SET @intBUH_TYPE_SOURCE = 4
						ELSE
							SET @intBUH_TYPE_SOURCE = @intBUH_TYPE
		
						IF @intLINK_SELF IS NOT NULL
							INSERT INTO dbo.S_ACCOUNTS ([NAME], cSINTH, cANALIT, cSOURCE, cUSER, LINK_SELF,
									KBK_TYPE, p_EKR, ANALIT_EKR,
									p_KASSA, KSU, p_NOCONTROL, S_ACTIVE, S_PASSIVE, 
									ap_EKR, ap_NOMEN, NOMEN_TYPE, ap_INV, ap_EMP, ap_DEP, ap_AP2,
									ap_DEP_ACC, ap_AP1, ap_SUB, ap_KAU, ZABALANS, AP_KBK,
									BUH_TYPE)
							VALUES (@strName_Acct, @SINTH, @ANALIT, @KVD, '',
									@intLINK_SELF, @intKBK_TYPE, @intP_EKR, @int_EKR0,
									@P_KASSA, @KSU, 0, @S_ACCTIVE, @S_PASSIVE,
									@EKR, @NOMEN, @NOMEN, @INV, @EMP, @DEP, @DOP, 0,
									@DEP_ACC, @OSNOV, @KAU, @ZABALANCE, 1,
									@intBUH_TYPE_SOURCE)
					END		 -- Отсутвует аналитический счет -- 
				END			---!!!Добавление отсутсвующих счетов!!!--- 
		
				---!!!Настройка ЖО!!!--- 
				SET @intJO = (SELECT LINK FROM dbo.JOURNAL_OPERATION WHERE CODE = @cJO)
				IF @intJO IS NOT NULL
					INSERT INTO dbo.JOURNAL_OPERATION_ACCOUNTS
					SELECT [JURN_LINK] = @intJO, 
						[ACCOUNT] = SA.LINK,
						[GK] = CONVERT (BIT, 0)
					FROM dbo.S_ACCOUNTS SA
					WHERE SA.cSINTH = @SINTH
						AND SA.cANALIT = @ANALIT
						AND SA.ZABALANS = @ZABALANCE
						AND NOT EXISTS (SELECT * FROM dbo.JOURNAL_OPERATION_ACCOUNTS T
									WHERE T.JURN_LINK = @intJO
										AND T.ACCOUNT = SA.LINK)

				SET @intKVD = @intKVD + 1
			END
			
			SET @iLOOP_COUNT = @iLOOP_COUNT + 1
		END		--	WHILE @iLOOP_COUNT > 0
			

		FETCH NEXT FROM #ACCT_NASTR
		INTO @SINTH, @ANALIT, @AP, @ZABALANCE,
			@KBK, @KSU, 
			@P_KASSA, @EKR_ANALIT, @EKR, 
			@NOMEN, @INV,  
			@EMP, @DEP, @DOP,
			@DEP_ACC, @OSNOV,
			@SUB, @P_CONTROL,
			@TMC, @INDATE,
			@KAU, @cJO,
			@strName_Acct,
			@P_DATE, @NOMEN_TYPE,
			@intBUH_TYPE
	END
	
	CLOSE #ACCT_NASTR
	DEALLOCATE #ACCT_NASTR

	UPDATE dbo.S_ACCOUNTS SET BUH_TYPE = 7 WHERE LINK_SELF IS NULL

	UPDATE SA SET BUH_TYPE = ISNULL (SAN.BUH_TYPE, 7)
	FROM dbo.S_ACCOUNTS SA
	LEFT JOIN dbo.S_ACCOUNTS_NASTR SAN ON (SAN.SINTH = SA.cSINTH
		AND SAN.ANALITH = SA.cANALIT)
	WHERE SA.BUH_TYPE = 0

	EXECUTE I_SET_ADMIN_DATE @kassa, @BB_OLD, @BB_OLD, @BE_OLD 

/*
	EXEC dbo.SA_152N_NASTR_PAYS

	EXEC dbo.XK_152N_INS_CORRECT_PROV
*/
	EXEC dbo.X_SET_OPTION 'XK_CONV_NASTR_SA_157N', 0, '1'

	RETURN 0
END



GO


GRANT EXECUTE ON dbo.[XK_NASTR_NEW_PLAN_ACCOUNTS] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_REP_T54]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_REP_T54]

GO

/*
© Кейсистемс (Keysystems), 2005
*/
CREATE  PROCEDURE dbo.SD_REP_T54
	@varKScYear VARCHAR(4),
	@varKSnMode SMALLINT,
	@varKSnLinkEmpl INT, 
	@varKSnVivodZP int
AS BEGIN

	DECLARE @varKSnYear 	   INT,
            @varKSnLinkPers INT

	SET @varKSnYear = CAST(@varKScYear AS INT)
	SELECT @varKSnLinkPers = PERS_LINK FROM EMPL WHERE LINK = @varKSnLinkEmpl

	DECLARE @varKSstart_date DATETIME, @varKSEND_DATE DATETIME
	SELECT @varKSstart_date = dbo.ConvertDMY2Date(1,1,@varKSnYear)
	SELECT @varKSEND_DATE  = dbo.DateEndOfYear(@varKSstart_date)

	declare @DEP_LINK int
	exec dbo.xd_whats_zb @DEP_LINK output

	CREATE TABLE #PART1 (SUBDIV VARCHAR(254), 
		DOC_BEGIN DATETIME, DOC_END DATETIME,
		TAB_NUM VARCHAR(15), CATEG VARCHAR(254), 
		INN VARCHAR(20), CODE_SPU VARCHAR(20), 
		KLADR VARCHAR(20), 
		SEMPOL VARCHAR(254), children int, 
		START_DATE DATETIME, DISCH_DATE DATETIME, 
		FIO VARCHAR(254), BIRTH_DATE DATETIME
	)

	INSERT INTO #PART1
	SELECT 
		TOP 1 
		[SUBDIV] 	= EP.SUBDIV_NAME,
		[DOC_BEGIN] = @varKSstart_date,
		[DOC_END] 	= @varKSEND_DATE,
		[tab_num]	= EP.TAB,
		[KATEG] 	= EP.STATUS_NAME,
		[INN] 		= P.INN,
		[CODE_SPU] 	= P.INSUR_NUM,
		[KLADR] 	= '',
		[SEMPOL] 	= (SELECT NAME FROM MARRIAGE WHERE LINK = P.MAR_LINK),
		[CHILDREN] = (SELECT COUNT(*) FROM KU_PERS_FAMILY 
					WHERE PERS_LINK = @varKSnLinkPers
				AND FAMILY_NAME IN ('Сын', 'Дочь', 'Пасынок', 'Падчерица')
				and datediff(yy, BIRTHDATE, dbo.ConvertDMY2Date(1,1,@varKSnYear)) <18),
		[START_DATE] = convert(DATETIME, E.DATE_BEGIN, 104),
		[DISCH_DATE] = CONVERT(DATETIME, E.DATE_END, 104),
		[FIO] = RTRIM(P.FM) + ' ' + RTRIM(P.IM) + ' ' + RTRIM(P.OT),
		[BIRTH_DATE] = P.BIRTHDATE
	FROM dbo.KU_EMPL_PLACING EP  
		INNER JOIN dbo.PERSON P ON (EP.PERS_LINK = P.LINK)
		INNER JOIN dbo.SD_EMPL E ON EP.LINK = E.LINK
	WHERE EP.LINK = @varKSnLinkEmpl 

	CREATE TABLE #TMP2 ( ORDER_DATE datetime, ORDER_NUM VARCHAR(30), 
		SUBDIV VARCHAR(254), POST VARCHAR(254), CONDITION VARCHAR(40), 
		KATEG VARCHAR(254), OKLAD NUMERIC(20,2), ADD_PAY NUMERIC(20,2), REAL_REC BIT
	)
	INSERT INTO #TMP2 (ORDER_DATE, ORDER_NUM, SUBDIV, POST, CONDITION, KATEG,
		REAL_REC)
	SELECT TOP 1 DATE, NUMBER, SUBDIVISION_PD, POST_PD, '', '', 1
	FROM DICTIONARY_PURP_DISP_FACES 
	WHERE EMPL_LINK = @varKSnLinkEmpl AND YEAR(DATE_PD) = @varKSnYear
	ORDER BY DATE_PD DESC
	
	INSERT INTO #TMP2 (ORDER_DATE, ORDER_NUM, SUBDIV, POST, CONDITION, KATEG,
		REAL_REC)
	SELECT DATE, NUMBER, SUBDIVISION_PD, POST_PD, '', '', 1
	FROM DICTIONARY_PURP_DISP_FACES 
	WHERE EMPL_LINK = @varKSnLinkEmpl AND YEAR(DATE_PD) = @varKSnYear	
	ORDER BY DATE_PD DESC

	CREATE TABLE #TMP_3 ( 
		ORD_DATE DATETIME,	ORD_NUM VARCHAR(30),
		VAC_TYPE VARCHAR(254),
		PERIOD_B DATETIME,	PERIOD_E DATETIME,
		VAC_BEG DATETIME,	VAC_END DATETIME,
		DAYS VARCHAR(254),
		REAL_REC BIT
		)

	INSERT INTO #TMP_3
	(
		ORD_DATE, ORD_NUM, 
		VAC_TYPE,
		PERIOD_B, PERIOD_E,
		VAC_BEG, VAC_END,
		DAYS, REAL_REC
	)
	SELECT 
		DATE, NUMBER,
		TYPE_NAME,
		PERIOD_BEGIN, PERIOD_END,
		DATE_BEGIN, DATE_END,
		dbo.W_DAYS(7, DATE_BEGIN, DATE_END),
		1
	FROM VACATION
	WHERE EMPL_LINK = @varKSnLinkEmpl AND YEAR([DATE_BEGIN]) = @varKSnYear
	
	CREATE TABLE #TMP_DED (ID INT IDENTITY, link_tax int, NAME_TAX VARCHAR(254), DATE1 DATETIME, DATE2 DATETIME, 
		SUMMA_PROC NUMERIC(20,2), SUMMA NUMERIC(20, 2), REAL_REC BIT )

	INSERT INTO #TMP_DED (link_tax, NAME_TAX, DATE1, DATE2, SUMMA_PROC, SUMMA, REAL_REC)
		SELECT link_tax, NAME_TAX, DATE1, DATE2, SUMMA, 0, 1
		FROM SD_EMPL_TAX ET
		WHERE ET.LINK_EMPL = @varKSnLinkEmpl AND (DATE2 IS NULL OR DATE2 >= @varKSstart_date) AND (DATE1 <= @varKSEND_DATE)


	CREATE TABLE #VICHETS (
		LINK INT, CODE VARCHAR(3), SUMMA NUMERIC(20,2), 
		DATE1 DATETIME, DATE2 DATETIME, REAL_REC BIT )
	INSERT INTO #VICHETS
	SELECT DTD.LINK, DTD.SNAME, DTD.SUMMA, DATE1, DATE2, 1 
	FROM SD_EMPL_DED ED, DICTIONARY_TYP_DEDUCTION DTD
	WHERE ED.LINK = @varKSnLinkEmpl 	AND DTD.LINK = ED.LINK_DED 
		AND (DATE2 IS NULL OR DATE2 >= @varKSstart_date)
		AND (DATE1 <= @varKSEND_DATE)



	DECLARE @varKSCOUNT_1 INT, @varKSTMP_INT INT, 
		@varKSCOUNT_2 INT, @varKSCOUNT_3 INT, @varKSCOUNT_4 INT, @varKSCOUNT_MAX INT, @varKSDELTA INT
	SET @varKSCOUNT_1 = (SELECT COUNT(*) FROM #TMP2)
	SET @varKSCOUNT_MAX = @varKSCOUNT_1
	SET @varKSCOUNT_2 = (SELECT COUNT(*) FROM #TMP_3)
	IF @varKSCOUNT_MAX < @varKSCOUNT_2 SET @varKSCOUNT_MAX = @varKSCOUNT_2
	SET @varKSCOUNT_3 = (SELECT COUNT(*) FROM #TMP_DED)
	IF @varKSCOUNT_MAX < @varKSCOUNT_3 SET @varKSCOUNT_MAX = @varKSCOUNT_3
	SET @varKSCOUNT_4 = (SELECT COUNT(*) FROM #VICHETS)
	IF @varKSCOUNT_MAX =0 SET @varKSCOUNT_MAX = 1
	IF @varKSCOUNT_MAX < @varKSCOUNT_4 SET @varKSCOUNT_MAX = @varKSCOUNT_4
	SET @varKSDELTA=@varKSCOUNT_MAX-@varKSCOUNT_1
	SET @varKSTMP_INT=1
	WHILE @varKSTMP_INT<=@varKSDELTA BEGIN
		INSERT INTO #TMP2 (REAL_REC) VALUES(0)
		SET @varKSTMP_INT=@varKSTMP_INT+1
	END
	SET @varKSDELTA=@varKSCOUNT_MAX-@varKSCOUNT_2
	SET @varKSTMP_INT=1
	WHILE @varKSTMP_INT<=@varKSDELTA BEGIN
		INSERT INTO #TMP_3(REAL_REC) VALUES(0)
		SET @varKSTMP_INT=@varKSTMP_INT+1
	END

	IF @varKSnMode=1 BEGIN  
		SET @varKSDELTA=@varKSCOUNT_MAX-@varKSCOUNT_3
		SET @varKSTMP_INT=1
		WHILE @varKSTMP_INT<=@varKSDELTA BEGIN
			INSERT INTO #TMP_DED (REAL_REC) VALUES(0)
			SET @varKSTMP_INT=@varKSTMP_INT+1
		END
	END
	SET @varKSDELTA=@varKSCOUNT_MAX-@varKSCOUNT_4
	SET @varKSTMP_INT=1
	WHILE @varKSTMP_INT<=@varKSDELTA BEGIN
		INSERT INTO #VICHETS (REAL_REC) VALUES(0)
		SET @varKSTMP_INT=@varKSTMP_INT+1
	END


	IF @varKSnMode=1 BEGIN	
	--- begin #3700 13.12.2011	Шорков И.А.  Изменение алгоритма выборки отработанных дней и часов	
		CREATE TABLE #DAYSHOURS(MONTH0 INT, C VARCHAR(3), D INT, H NUMERIC(8,2) )
		INSERT INTO #DAYSHOURS
		SELECT MONTH(T.PERIOD), 
			   TD.SYMB, 
			   (dbo.SA_GET_EMPL_WD (T.LINK_EMPL, 0, DEFAULT, dbo.ConvertDMY2Date(1,MONTH(T.PERIOD),year(T.PERIOD)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH(T.PERIOD),year(T.PERIOD))), DEFAULT, 0)) as DAYS, 
			   (dbo.SA_GET_EMPL_WH (T.LINK_EMPL, 0, DEFAULT,  dbo.ConvertDMY2Date(1,MONTH(T.PERIOD),year(T.PERIOD)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH(T.PERIOD),year(T.PERIOD))), DEFAULT, 0)) AS HOURS
		FROM DBO.TABELS T , DBO.TYP_DAYS TD ,DBO.TABELS_W W left join (
				Select DISTINCT G.LINK, GT.TYPE_DAY from dbo.GRAPH G inner join dbo.GRAPH_VID_TABLE GT on G.VID_LINK = GT.LINK_UP
			) EG on (SELECT GRAPH_LINK FROM DBO.EMPL E WHERE e.LINK = @varKSnYear) = EG.LINK and EG.TYPE_DAY = W.link_day
		WHERE 
			T.LINK_EMPL =  @varKSnLinkEmpl
			AND T.LINK = W.LINK_UP 
			AND  td.link = W.link_day
			AND TD.WORK_D < 4
			and TD.DOP_TAB = 1
			AND YEAR(T.PERIOD) = @varKSnYear
			AND
			(
				EG.TYPE_DAY is not null
				OR
				W.link_day in (Select LINK from dbo.TYP_DAYS WHERE DOP_TAB = 1)
			)
		GROUP BY T.PERIOD, T.LINK_EMPL , TD.SYMB
	--- end #3700 

		CREATE TABLE #TMP_N1 (MONTH1 INT, CN VARCHAR(10), NN VARCHAR(254), SM NUMERIC(20,2), SM_ALL NUMERIC(20,2))
	
		INSERT INTO #TMP_N1
		SELECT MONTH_BEGIN, CODE_PAYS, NAME_PAYS, SUMMA, 0
		FROM S_J_C_Short SJC 
		WHERE 
			SJC.LINK_EMPL = @varKSnLinkEmpl
			AND YEAR_BEGIN = @varKSnYear
			AND TYP_OPER = 1 AND WAY_CALC NOT IN(13, 14)
			AND SJC.LINK_DEP = @DEP_LINK 
		

----- begin #3695 Шорков И.А. 13.12.2011  исправление алгоритма для выборки пособий по уходу за ребенком
		/* #3696 исправление отображения количества дней нетрудоспособности*/

		CREATE TABLE #TAB2 (REF_ARHE INT, MAX_LINK INT)

		--Последний расчёт каждого больничного, чтобы выйти на больничный
		INSERT INTO #TAB2(REF_ARHE, MAX_LINK)
		SELECT SD.REF_DOC, MAX(S.LINK)
		FROM
			dbo.SDOC S 
			INNER JOIN dbo.SDOC_ADIS SD ON S.LINK = SD.LINK_UP
		WHERE
			 S.FLAG_JC = 1 AND SD.LINK_EMPL = @varKSnLinkEmpl		
		GROUP BY
			SD.REF_DOC			 

		--Для последнего расчёта каждого больничного, количество дней из больничного
		CREATE TABLE #ST2 (LINK_UP INT, [DAYS] NUMERIC(18,2))
		INSERT INTO #ST2 (LINK_UP, [DAYS])
		SELECT T1.LINK_UP, [DAYS] = sum(T1.[DAYS]) 
		FROM 
			[dbo].[SDOC] D 
			INNER JOIN dbo.SDOC_ADIS A ON D.LINK = A.LINK_UP
			INNER JOIN dbo.SDOC_ADIS_TABLE1 T1 ON D.LINK = T1.LINK_UP 
		WHERE 
			A.LINK_EMPL = @varKSnLinkEmpl
		GROUP BY 
			T1.LINK_UP
			
		--
		CREATE TABLE #TAB3 (LINK INT, [DAYS] NUMERIC(18,2))
		INSERT INTO #TAB3 (LINK, [DAYS])
		SELECT S.LINK, SUM(ST2.[DAYS])
		FROM
			dbo.SDOC S 
			INNER JOIN dbo.SDOC_ADIS SD ON S.LINK = SD.LINK_UP
			INNER JOIN #TAB2 DA3 ON DA3.REF_ARHE = SD.REF_DOC
			INNER JOIN #ST2 ST2 ON S.LINK = ST2.LINK_UP
		WHERE
			S.FLAG_JC = 1 AND SD.LINK_EMPL = @varKSnLinkEmpl		 
		GROUP BY 
			S.LINK

		CREATE TABLE #TMP_N2 (MONTH2 INT, CN2 VARCHAR(10), NN2 VARCHAR(254), SM2 NUMERIC(20,2), DAY2 INT, SM_ALL2 NUMERIC(20,2) )
		INSERT INTO #TMP_N2
		SELECT SJC.MONTH_BEGIN, SJC.CODE_PAYS, SJC.NAME_PAYS, SUM(SJC.SUMMA) ,
			[days] = SUM(SJC.[DAYS]),
			0
		FROM 
			dbo.S_J_C_Short SJC
			LEFT JOIN #TAB3 T3 ON SJC.LINK_DOC = T3.LINK --Дни больничного определяем по последнему расчёту
		WHERE 
			 SJC.LINK_EMPL = @varKSnLinkEmpl
			AND SJC.YEAR_BEGIN = @varKSnYear
			AND SJC.TYP_OPER = 1
			AND SJC.WAY_CALC IN(13, 14)
			AND SJC.LINK_DEP = @DEP_LINK 
		GROUP BY 
			SJC.MONTH_BEGIN, SJC.LINK_DOC, SJC.CODE_PAYS, SJC.NAME_PAYS , SJC.WAY_CALC

----- end #3695


		CREATE TABLE #TMP_U (MONTH3 INT, CU VARCHAR(10), NU VARCHAR(254), SU NUMERIC(20,2),  SM_ALL3 NUMERIC(20,2) )
		INSERT INTO #TMP_U
		SELECT MONTH_BEGIN, CODE_PAYS, NAME_PAYS, SUMMA, 0
		FROM S_J_C_Short SJC 
		WHERE 
			SJC.LINK_EMPL = @varKSnLinkEmpl
			AND YEAR_BEGIN = @varKSnYear
			AND TYP_OPER = 2
			AND SJC.LINK_DEP = @DEP_LINK 
			
		if @varKSnVivodZP = 1
		--- по настройке з/п удаляем из удержаний ,она переносится в задолженность за предприятнием , 
		--	и расчитывается в итого к оплате 	
		delete   from #TMP_U
			where 	MONTH3 in (SELECT max(MONTH3)	
									FROM #TMP_U) 
					and NU like ('%з/п%') or NU like ('%зар%пл%')
	
		------------------------------------
	
		DECLARE @varKSTMP_TABLE VARCHAR(100)
		EXEC X_GET_TABLE_NAME @varKSTMP_TABLE OUTPUT
		DECLARE @varKSTABLE_NAME_N1 VARCHAR(120), @varKSTABLE_NAME_N2 VARCHAR(120), @varKSTABLE_NAME_U1 VARCHAR(120),
			@varKSDAYSHOURS VARCHAR(120)
		SET @varKSTABLE_NAME_N1 = @varKSTMP_TABLE + '_N1'
		SET @varKSTABLE_NAME_N2 = @varKSTMP_TABLE + '_N2'
		SET @varKSTABLE_NAME_U1 = @varKSTMP_TABLE + '_U1'
		SET @varKSDAYSHOURS = @varKSTMP_TABLE + '_D'
		
		EXEC M_CROSS_TABLE 'MONTH1, SM_ALL', 'NN,CN', 'VARCHAR(254)#VARCHAR(10)', 'SM', 'NUMERIC(20,2)', 'SUM(SM)  AS SM', '#TMP_N1', @varKSTABLE_NAME_N1 
		EXEC M_CROSS_TABLE 'MONTH2, SM_ALL2', 'CN2', 'VARCHAR(10)', 'SM2,DAY2', 'NUMERIC(20,2)#INT', 'SUM(SM2)  AS SM2,SUM(DAY2) AS DAY2', '#TMP_N2', @varKSTABLE_NAME_N2 
		EXEC M_CROSS_TABLE 'MONTH3, SM_ALL3', 'NU,CU', 'VARCHAR(254)#VARCHAR(10)', 'SU', 'NUMERIC(20,2)', 'SUM(SU)  AS SU', '#TMP_U', @varKSTABLE_NAME_U1 
		EXEC M_CROSS_TABLE 'MONTH0', 'C', 'VARCHAR(3)', 'D,H', 'INT#NUMERIC(8,2)', 'SUM(D) AS D,SUM(H) AS H', '#DAYSHOURS', @varKSDAYSHOURS
		
			
		EXEC  ( 'UPDATE ' + @varKSTABLE_NAME_N1 + '  SET SM_ALL = (SELECT SUM(SM) FROM #TMP_N1 WHERE MONTH1 = T1.MONTH1) FROM ' + @varKSTABLE_NAME_N1 + '  T1 ' )
		EXEC  ( 'UPDATE ' + @varKSTABLE_NAME_N2 + '  SET SM_ALL2 = (SELECT SUM(SM2) FROM #TMP_N2 WHERE MONTH2 = T1.MONTH2) FROM ' + @varKSTABLE_NAME_N2 + '  T1 ' )
		EXEC  ( 'UPDATE ' + @varKSTABLE_NAME_U1 + '  SET SM_ALL3 = (SELECT SUM(SU) FROM #TMP_U WHERE MONTH3 = T1.MONTH3) FROM ' + @varKSTABLE_NAME_U1 + '  T1 ' )




		DECLARE @varKSTABLE_NAME_R1 VARCHAR(120)
		SET @varKSTABLE_NAME_R1 = @varKSTMP_TABLE + '_R1'
		EXEC ( '
			SELECT M1.*, T1.*, T2.*, T3.*, T4.* 
			INTO ' + @varKSTABLE_NAME_R1 + '
			FROM MONTHS M1 FULL OUTER JOIN ' + @varKSDAYSHOURS + ' T1 ON M1.NUM = MONTH0
			FULL OUTER JOIN ' + @varKSTABLE_NAME_N1 + '  T2 ON M1.NUM = MONTH1
			FULL OUTER JOIN ' + @varKSTABLE_NAME_N2 + '  T3 ON M1.NUM = MONTH2
			FULL OUTER JOIN ' + @varKSTABLE_NAME_U1 + '  T4 ON M1.NUM = MONTH3 ' )


			
		DECLARE @varKSCOUNT_N1 INT, @varKSCOUNT_N2 INT, @varKSCOUNT_U INT, @varKSCOUNT_D INT, @varKSSQL_STR VARCHAR(8000)
		DECLARE @varKSFIELD_NAME VARCHAR(100)
		SELECT @varKSCOUNT_N1=COUNT(DISTINCT(CN)) FROM #TMP_N1
		SELECT @varKSCOUNT_N2=COUNT(DISTINCT(CN2)) FROM #TMP_N2
		SELECT @varKSCOUNT_U=COUNT(DISTINCT(NU)) FROM #TMP_U
		SELECT @varKSCOUNT_D=COUNT(DISTINCT(C)) FROM #DAYSHOURS

		SET @varKSTMP_INT=1
		WHILE @varKSTMP_INT <= @varKSCOUNT_N1 BEGIN
			SET @varKSFIELD_NAME= 'NN_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) 
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_NAME_N1 + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSFIELD_NAME= 'CN_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) +'_'+RTRIM(LTRIM(STR(@varKSTMP_INT)))
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_NAME_N1 + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSTMP_INT=@varKSTMP_INT+1
		END
		SET @varKSTMP_INT=1
		WHILE @varKSTMP_INT<=@varKSCOUNT_N2 BEGIN
			SET @varKSFIELD_NAME= 'CN2_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) 
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_NAME_N2 + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSTMP_INT=@varKSTMP_INT+1
		END
		SET @varKSTMP_INT=1
		WHILE @varKSTMP_INT<=@varKSCOUNT_U BEGIN
			SET @varKSFIELD_NAME= 'NU_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) 
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_NAME_U1 + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSFIELD_NAME= 'CU_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) +'_'+RTRIM(LTRIM(STR(@varKSTMP_INT)))
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_NAME_U1 + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSTMP_INT=@varKSTMP_INT+1
		END
		SET @varKSTMP_INT=1
		WHILE @varKSTMP_INT <= @varKSCOUNT_D BEGIN
			SET @varKSFIELD_NAME= 'C_' + RTRIM(LTRIM(STR(@varKSTMP_INT))) 
			SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_NAME_R1+'  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSDAYSHOURS + ' WHERE '+
				@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
			EXEC (@varKSSQL_STR)
			SET @varKSTMP_INT=@varKSTMP_INT+1
		END


		
		IF @varKSCOUNT_N1=0 BEGIN
			EXEC (' ALTER TABLE '+@varKSTABLE_NAME_R1+' ADD CN_0_0 VARCHAR(10), NN_0 VARCHAR(254), SM_0_0 MONEY ')
		END
		IF @varKSCOUNT_N2=0 BEGIN
			EXEC (' ALTER TABLE '+@varKSTABLE_NAME_R1+' ADD CN2_0 VARCHAR(10),  SM2_0 MONEY, DAY2_0 INT ')
		END	
		IF @varKSCOUNT_U=0 BEGIN
			EXEC (' ALTER TABLE '+@varKSTABLE_NAME_R1+' ADD NU_0 VARCHAR(10), CU_0_0 VARCHAR(254), SU_0_0 MONEY ')
		END
		IF @varKSCOUNT_D=0 BEGIN
			EXEC (' ALTER TABLE '+@varKSTABLE_NAME_R1+' ADD C_0 VARCHAR(3), D_0 INT, H_0 NUMERIC(8,2) ')
		END
		IF @varKSCOUNT_N1 = 0 AND @varKSCOUNT_N2 = 0 AND @varKSCOUNT_U = 0 BEGIN
			EXEC('INSERT INTO ' + @varKSTABLE_NAME_R1 + ' (SM_0_0 ) VALUES (0) ' )
		END

		EXEC ('DROP TABLE ' +	@varKSTABLE_NAME_N1)
		EXEC ('DROP TABLE ' +	@varKSTABLE_NAME_N2)
		EXEC ('DROP TABLE ' +	@varKSTABLE_NAME_U1)
		EXEC ('DROP TABLE ' +	@varKSDAYSHOURS)
	END



	SELECT * FROM #PART1
	SELECT * FROM #TMP2 ORDER BY REAL_REC DESC, ORDER_DATE ASC
	SELECT * FROM #TMP_3 ORDER BY REAL_REC DESC, ORD_DATE
	IF @varKSnMode=1
		SELECT * FROM #TMP_DED ORDER BY REAL_REC DESC

	ELSE BEGIN
		IF @varKSCOUNT_3 <=3 BEGIN
			SELECT * FROM #TMP_DED ORDER BY REAL_REC DESC
			SELECT * FROM #TMP_DED WHERE 1<0
		END
		ELSE BEGIN
			SELECT * FROM #TMP_DED WHERE ID <=@varKSCOUNT_3/2 ORDER BY REAL_REC DESC
			SELECT * FROM #TMP_DED WHERE ID >@varKSCOUNT_3/2   ORDER BY REAL_REC DESC
		END
	END

	SELECT MONTH(DATE1), *, 
		'Вычет: ' + rtrim(code) + char(10) 
		+ convert(varchar(10), date1, 104) + ' - ' + convert(varchar(10), date2, 104)
		+ char(10) + cast(summa as varchar(15) ) as sum_ded
	FROM #VICHETS ORDER BY REAL_REC DESC, 1, date2

	IF @varKSnMode=1 BEGIN
		EXEC ( 'SELECT * FROM '  + @varKSTABLE_NAME_R1 + ' ORDER BY NUM ')

		EXEC ('DROP TABLE ' +	@varKSTABLE_NAME_R1)
	END
	
	if object_id('tempdb..#TAB2') is NOT NULL
		EXECUTE ('DROP TABLE #TAB2')

	if object_id('tempdb..#TAB3') is NOT NULL
		EXECUTE ('DROP TABLE #TAB3')

END











GO


GRANT EXECUTE ON dbo.[SD_REP_T54] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RB_CALC_FORM_0503128G]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RB_CALC_FORM_0503128G]

GO


/*******************************************************************************

	c Кейсистемс (Keysystems), 2007

*******************************************************************************/
CREATE PROCEDURE dbo.[RB_CALC_FORM_0503128G]
	@LSF		INT,
	@tTable	   TINYINT  = 1
AS

DECLARE @ldEnd		  DATETIME,
		@ldBegin      DATETIME,
		@liYear       INT,
		@ADM_CODE	  CHAR(3),
		@dCALC_DATE	  DATETIME,
		@iDEP_LINK	  INT

select 	@iDEP_LINK 	= Link_Organization, 
		@ldEnd		= Begin_Date + 1,
		@dCALC_DATE = Begin_Date, 
		@liYear		= YEAR(Begin_Date),
		@ldBegin	= dbo.DateBeginOfYear(Begin_Date)
from dbo.REPORT_SAVED_FORMS
where Link_Saved_Form = @LSF

SET @ADM_CODE = Null
SELECT @ADM_CODE = LEFT(LTRIM(dbo.rn_get_atr_value(@LSF, 'REPORTS_ATR_ADM')),3)

IF @ADM_CODE = '' OR @ADM_CODE = '000'
	SET @ADM_CODE = Null

DECLARE @tTemp TABLE (	KBK		INT,
						EKR		INT,
						SUMMA	FLOAT,
						TYPE	tinyint)


DECLARE @AdmFilter table (LINK int)
insert into @AdmFilter
Select LINK FROM rn_get_filter(@LSF,'REPORTS_FILTER_KBK')


--Ассигнования



INSERT @tTemp
SELECT	R.VKR, R.EKR, SUM(R.P1), 4
FROM dbo.FB_REST_FINANS(@liYear,@dCALC_DATE,1,1,0,'FINANS_ASSIGN',11,'1',1) R
inner join dbo.DEPARTMENT_ACCOUNTS DA on DA.LINK = R.DEP_ACC and DA.LINK_UP = @iDEP_LINK 
left join dbo.KL_KBK KBK on KBK.LINK = R.VKR
WHERE (@ADM_CODE IS Null OR @ADM_CODE is not null and @ADM_CODE = LEFT(LTRIM(KBK.CODE),3)) 
GROUP BY R.VKR, R.EKR 

INSERT @tTemp
SELECT	R.VKR, R.EKR, SUM(R.P1), 4
FROM dbo.FB_REST_FINANS(@liYear,@dCALC_DATE,1,1,0,'FINANS_ASSIGN_SVOD',11,'1',2) R
inner join dbo.DEPARTMENT_ACCOUNTS DA on DA.LINK = R.DEP_ACC and DA.LINK_UP = @iDEP_LINK 
left join dbo.KL_KBK KBK on KBK.LINK = R.VKR
left join @tTemp T on T.KBK = R.VKR and T.EKR = R.EKR and T.TYPE = 4
WHERE (@ADM_CODE IS Null OR @ADM_CODE is not null and @ADM_CODE = LEFT(LTRIM(KBK.CODE),3)) and
	T.KBK is null and T.EKR is null 
GROUP BY R.VKR, R.EKR

--Лимиты
INSERT @tTemp
SELECT S.VKR, S.EKR, SUM(S.P1), 5 
FROM dbo.FB_REST_FINANS(@liYear,@dCALC_DATE,1,1,0,'FINANS_LIMIT',11,'1',1) S
inner join dbo.DEPARTMENT_ACCOUNTS DA on DA.LINK = S.DEP_ACC and DA.LINK_UP = @iDEP_LINK  
GROUP BY VKR, EKR

--Бюджетные обязательства
EXEC dbo.[BufferClear] 'BO' 

INSERT dbo.BUFFER(LINK, [ID])
SELECT [LINK], 'BO' 
FROM dbo.S_ACCOUNTS 
WHERE ZABALANS = 0  AND cSource = '1'  AND cSinth = '502' AND cAnalit = '11' 

INSERT @tTemp
select KT_VKR AS KBK, KT_SGU as SGU, SUM(ISNULL(SUMMA, 0)), 6 
from dbo.AProvByBufferConditionsShort(@ldBegin, @dCALC_DATE, null, 'BO')
where DEP_LINK = @iDEP_LINK
GROUP BY KT_VKR,KT_SGU

EXEC dbo.[BufferClear] 'BO' 
	

--Денежные обязательства
--Бюджетные обязательства
EXEC dbo.[BufferClear] 'DO' 

INSERT dbo.BUFFER(LINK, [ID])
SELECT [LINK], 'DO' 
FROM dbo.S_ACCOUNTS 
WHERE ZABALANS = 0  AND cSource = '1'  AND cSinth = '502' AND cAnalit = '12' 

INSERT @tTemp
select KT_VKR AS KBK, KT_SGU as SGU, SUM(ISNULL(SUMMA, 0)), 7 
from dbo.AProvByBufferConditionsShort(@ldBegin, @dCALC_DATE, null, 'DO')
where DEP_LINK = @iDEP_LINK
GROUP BY KT_VKR,KT_SGU

EXEC dbo.[BufferClear] 'DO' 

--Исполнено
EXEC dbo.[BufferClear] 'ISP'
EXEC dbo.[BufferClear] 'NOT_30404'

INSERT dbo.BUFFER(LINK, [ID])
SELECT [LINK], 'ISP' 
FROM dbo.S_ACCOUNTS 
WHERE ZABALANS = 0  AND cSource = '1'  AND (cSinth = '304' AND cAnalit = '05' or cSinth = '201' AND (cAnalit = '01' or cAnalit = '07'))

INSERT dbo.BUFFER(LINK, [ID])
SELECT [LINK], 'NOT_30404'
	FROM dbo.S_ACCOUNTS
	WHERE ZABALANS = 0  AND NOT (cSinth = '304' and cAnalit = '04' AND cSource = '1') 


INSERT @tTemp
SELECT	S.KBK, S.SGU, SUM(ISNULL(S.SUMMA, 0)), 10
FROM (select DEP_LINK, KT_VKR AS KBK, KT_SGU as SGU, SUMMA from dbo.AProvByBufferConditionsShort(@ldBegin, @dCALC_DATE, 'NOT_30404', 'ISP') union all
		select DEP_LINK, DT_VKR, DT_SGU as SGU, -SUMMA from dbo.AProvByBufferConditionsShort(@ldBegin, @dCALC_DATE, 'ISP', 'NOT_30404')) S
where DEP_LINK = @iDEP_LINK
GROUP BY S.KBK, S.SGU

EXEC dbo.[BufferClear] 'ISP'
EXEC dbo.[BufferClear] 'NOT_30404'

--select * from @tTemp
--select * from @tTemp where [TYPE] = 6
--Результат
IF @tTable = 1
BEGIN 
	SELECT	CODE  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE,
			COL1  = SGU.NAME,
			COL2  = '200',
			COL3  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,4),
			COL4  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),8,7),
			COL5  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),15,3),
			COL6  = SGU.CODE,
			COL7  = isnull(T4.SUMMA,0),
			COL8  = isnull(T5.SUMMA,0),
			COL9  = isnull(T6.SUMMA,0),
			COL10  = 0,
			COL11 = isnull(T8.SUMMA,0),
			COL12 = 0,
			COL13 = isnull(T10.SUMMA,0),
			COL14 = 0,
			COL15 = 0,
			COL16 = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
	FROM (select KBK, EKR from @tTemp where SUMMA <> 0 GROUP BY KBK, EKR) T	
	INNER JOIN dbo.KL_KBK KBK ON T.KBK = KBK.LINK and KBK.TYPE = 1 and (@ADM_CODE is null or @ADM_CODE = left(ltrim(KBK.CODE),3))
	INNER JOIN dbo.KOSGU SGU ON T.EKR = SGU.LINK
	LEFT JOIN @tTemp T4 ON T4.KBK = T.KBK AND T4.EKR = T.EKR and T4.[TYPE] = 4
	LEFT JOIN @tTemp T5 ON T5.KBK = T.KBK AND T5.EKR = T.EKR and T5.[TYPE] = 5
	LEFT JOIN @tTemp T6 ON T6.KBK = T.KBK AND T6.EKR = T.EKR and T6.[TYPE] = 6
	LEFT JOIN @tTemp T8 ON T8.KBK = T.KBK AND T8.EKR = T.EKR and T8.[TYPE] = 8
	LEFT JOIN @tTemp T10 ON T10.KBK = T.KBK AND T10.EKR = T.EKR and T10.[TYPE] = 10
	--where @lbKBK_FILTER = 1 and (T.KBK in (select LINK from @AdmFilter)) 
	ORDER BY SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
END
IF @tTable = 3
BEGIN 
		SELECT	CODE  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE,
			COL1  = SGU.NAME,
			COL2  = '900',
			COL3  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,4),
			COL4  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),8,7),
			COL5  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),15,3),
			COL6  = SGU.CODE,
			COL7  = isnull(T4.SUMMA,0),
			COL8  = isnull(T5.SUMMA,0),
			COL9  = isnull(T6.SUMMA,0),
			COL10  = 0,
			COL11 = isnull(T8.SUMMA,0),
			COL12 = 0,
			COL13 = isnull(T10.SUMMA,0),
			COL14 = 0,
			COL15 = 0,
			COL16 = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
	FROM (select KBK, EKR from @tTemp where SUMMA <> 0 GROUP BY KBK, EKR) T	
	INNER JOIN dbo.KL_KBK KBK ON T.KBK = KBK.LINK and KBK.TYPE = 1 and (@ADM_CODE is null or @ADM_CODE = left(ltrim(KBK.CODE),3))
	INNER JOIN dbo.KOSGU SGU ON T.EKR = SGU.LINK
	LEFT JOIN @tTemp T4 ON T4.KBK = T.KBK AND T4.EKR = T.EKR and T4.[TYPE] = 4
	LEFT JOIN @tTemp T5 ON T5.KBK = T.KBK AND T5.EKR = T.EKR and T5.[TYPE] = 5
	LEFT JOIN @tTemp T6 ON T6.KBK = T.KBK AND T6.EKR = T.EKR and T6.[TYPE] = 6
	LEFT JOIN @tTemp T8 ON T8.KBK = T.KBK AND T8.EKR = T.EKR and T8.[TYPE] = 8
	LEFT JOIN @tTemp T10 ON T10.KBK = T.KBK AND T10.EKR = T.EKR and T10.[TYPE] = 10
	--where @lbKBK_FILTER = 1 and (T.KBK in (select LINK from @AdmFilter)) 
	ORDER BY SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
END 
ELSE BEGIN 
	SELECT	CODE  = isnull(IST.CODE_STR,'000') + SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE,
			COL1  = IST.NAME,
			COL2  = IST.CODE_STR,
			COL3  = SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE,
			COL4  = isnull(T4.SUMMA,0),
			COL5  = isnull(T5.SUMMA,0),
			COL6  = isnull(T6.SUMMA,0),
			COL7  = 0,
			COL8 = isnull(T8.SUMMA,0),
			COL9 = 0,
			COL10 = - isnull(T10.SUMMA,0),
			COL11 = 0,
			COL12 = 0,
			COL13 = isnull(IST.CODE_STR,'000') + SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
	FROM (select KBK, EKR from @tTemp where SUMMA <> 0 GROUP BY KBK, EKR) T	
	INNER JOIN dbo.KL_KBK KBK ON T.KBK = KBK.LINK and KBK.[TYPE] > 2 and (@ADM_CODE is null or @ADM_CODE = left(ltrim(KBK.CODE),3))
	INNER JOIN dbo.KOSGU SGU ON T.EKR = SGU.LINK
	left join dbo.RN_VIEW_IST_117M_2010 IST on IST.CODE = case when KBK.TYPE = 8 then '620' else '520' end + SUBSTRING(rtrim(LTRIM(REPLACE(KBK.CODE,'.',''))),4,14) + SGU.CODE
	LEFT JOIN @tTemp T4 ON T4.KBK = T.KBK AND T4.EKR = T.EKR and T4.[TYPE] = 4
	LEFT JOIN @tTemp T5 ON T5.KBK = T.KBK AND T5.EKR = T.EKR and T5.[TYPE] = 5
	LEFT JOIN @tTemp T6 ON T6.KBK = T.KBK AND T6.EKR = T.EKR and T6.[TYPE] = 6
	LEFT JOIN @tTemp T8 ON T8.KBK = T.KBK AND T8.EKR = T.EKR and T8.[TYPE] = 8
	LEFT JOIN @tTemp T10 ON T10.KBK = T.KBK AND T10.EKR = T.EKR and T10.[TYPE] = 10
	where IST.CODE_IST is not null 
	ORDER BY SUBSTRING(LTRIM(REPLACE(KBK.CODE,'.','')),4,14) + SGU.CODE
END 



GO


GRANT EXECUTE ON dbo.[RB_CALC_FORM_0503128G] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_UPDATE_DOC_NASTR_SA]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_UPDATE_DOC_NASTR_SA]

GO
-- BK_UPDATE_DOC_NASTR_SA --
CREATE PROCEDURE dbo.BK_UPDATE_DOC_NASTR_SA
	@intLINK	INT OUTPUT,
	@LINK_UP	INT,
	@ACCOUNT	INT,
	@DB_KR		TINYINT	=	255
AS
BEGIN
	DECLARE
		@trancount	INT,
		@ERROR		INT,
		@ROWCOUNT	INT
	
	IF EXISTS (SELECT * FROM dbo.DOC_NASTR WHERE LINK = @LINK_UP)
	BEGIN
		SET @ACCOUNT = (SELECT LINK FROM dbo.S_ACCOUNTS WHERE LINK = @ACCOUNT)
	
		SET @trancount = @@TRANCOUNT
		SET IMPLICIT_TRANSACTIONS ON

		IF @intLINK IS NULL OR @intLINK = 0
		BEGIN
			INSERT INTO dbo.DOC_NASTR_S_ACCOUNTS (LINK_UP, ACCOUNT, DB_KR)
			VALUES (@LINK_UP, @ACCOUNT, @DB_KR)

			SELECT @ERROR = @@ERROR, @intLINK = @@IDENTITY
			IF @ERROR <> 0
			BEGIN
				ROLLBACK
				RETURN 7
			END
		END			--	IF @intLINK IS NULL OR @intLINK = 0
		ELSE
		BEGIN
			UPDATE dbo.DOC_NASTR_S_ACCOUNTS
			SET
				LINK_UP = @LINK_UP,
				ACCOUNT =  @ACCOUNT, 
				DB_KR = @DB_KR
			WHERE LINK = @intLINK
			
			SELECT
				@ERROR = @@ERROR,
				@ROWCOUNT = @@ROWCOUNT
				
			IF @ERROR <> 0
			BEGIN
				ROLLBACK
				RETURN 7
			END
			
			IF @ROWCOUNT = 0
			BEGIN
				ROLLBACK
				RETURN 2
			END
		END	--	ELSE IF @intLINK IS NULL OR @intLINK = 0
		
		IF @@TRANCOUNT > @trancount
			COMMIT TRAN
	END
	
	RETURN 0
END

GO

GRANT EXECUTE ON dbo.[BK_UPDATE_DOC_NASTR_SA] TO PUBLIC

GO

--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[X_SAVE_BV_DOC_AVANSE_REP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[X_SAVE_BV_DOC_AVANSE_REP]

GO


CREATE PROCEDURE dbo.X_SAVE_BV_DOC_AVANSE_REP
	@varKSpLINK		int	OUTPUT,
	@varKSpNUMBER	char(25) = null,
	@varKSpDATE		datetime = null,
	@varKSpDATE_PROV	datetime = null,
	@varKSpSumma		numeric(19,2) = 0,
	@varKSpComment		varchar(254) = null,
	@varKSpDEP_LINK       INT = null,
	@varKSpKBK_LINK       INT = null,
	@varKSpOTDEL_LINK     INT = null,
	@varKSpEMP_LINK       INT = null,
	@varKSpTARGET         VARCHAR(100) = null,
	@varKSpPREVSUMMA      NUMERIC(13,2) = null,
	@varKSpAVANSESUMMA    NUMERIC(13,2) = null,
	@varKSpITOG_SUM       NUMERIC(13,2) = null,
	@varKSpKTACCOUNT      VARCHAR(13) = null,
	@varKSpRASHOD_SUM     NUMERIC(13,2) = null,
	@varKSpREST_SUM       NUMERIC(13,2) = null,
	@varKSpDOC            INT = null,
	@varKSpPAGES          INT = null,
	@varKSpKOSUMMA        NUMERIC(13,2) = null,
	@varKSpKONUM          VARCHAR(8) = null,
	@varKSpKODATE         DATETIME = null,
	@intOPTION	INT = NULL

AS
SET LOCK_TIMEOUT 30000
SET IMPLICIT_TRANSACTIONS ON
DECLARE @varKSERROR	tinyint,
		@varKSstrVALUE	varchar(7000),
		@varKSEventText	varchar(254),
		@varKStrancount	int,
		@varKSLinkObj	int,
		@varKS_param	int

SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN

	--Проверка рабочего периода
	IF @varKSpDATE_PROV is not null and not exists(Select * from admin_info Where @varKSpDATE_PROV BETWEEN BEGINDATE AND ENDDATE)
	BEGIN
		ROLLBACK
		RETURN 15
	END

	--Проверка обязательных реквизитов
	IF @varKSpEMP_LINK IS NULL OR @varKSpEMP_LINK = 0
	BEGIN
		ROLLBACK
		RETURN 5
	END


	SELECT @varKSLinkObj = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AVANSE_REP'


	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV @varKSpLINK OUTPUT, @varKSpNUMBER, @varKSpDATE, 
											  @varKSLinkObj,@varKSpDATE_PROV, @varKSpSumma, @varKSpComment,0,@varKSpDEP_LINK

	IF @varKSERROR <> 0
		RETURN @varKSERROR	


	
	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_TARGET'
	--Назначение аванса
	EXEC @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSpTARGET
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_PREVSUMMA'
	--Предыдущий аванс
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpPREVSUMMA)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_AVANSESUMMA'
	--Получен аванс
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpAVANSESUMMA)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_ITOG_SUM'
	--Итого получено
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpITOG_SUM)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_KTACCOUNT'
	--кредит счета
	EXEC @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSpKTACCOUNT
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_RASHOD_SUM'
	--Израсходовано
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpRASHOD_SUM)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_REST_SUM'
	--Остаток/перерасход
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpREST_SUM)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_DOC'
	--Приложено документов
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpDOC)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_PAGES'
	--На листах
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpPAGES)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_KOSUMMA'
	--Сумма по ордеру
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpKOSUMMA)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_KONUM'
	--Номер ордера
	EXEC @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSpKONUM
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_KODATE'
	--Дата ордера
	SET @varKSstrVALUE = Convert(varchar(7000), @varKSpKODATE,104)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR



	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_OTDEL_LINK'
	--Ссылка на отдел
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_SUBDIV @varKSpLINK, @varKS_param, @varKSpOTDEL_LINK
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	IF @intOPTION = 1 BEGIN
		SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_EMP_LINK'
		--Ссылка на сотрудника
		EXECUTE @varKSERROR = dbo.BK_UPDATE_G_PROV_EMPL @varKSpLINK, @varKS_param, @varKSpEMP_LINK
		IF @varKSERROR <> 0
			RETURN @varKSERROR
	END
	ELSE BEGIN
		SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_PERS_LINK'
		SET @varKSstrVALUE = CONVERT (VARCHAR (7000), @varKSpEMP_LINK)
		EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
		IF @varKSERROR <> 0
			RETURN @varKSERROR
	END

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_KBK_LINK'
	--Ссылка на КБК
	EXECUTE @varKSERROR = dbo.BK_UPDATE_G_PROV_KBK @varKSpLINK, @varKS_param, @varKSpKBK_LINK
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	SELECT @varKS_param = LINK FROM S_OBJECTS WHERE CODE = 'BV_DOC_AO_OPTION'
	SET @varKSstrVALUE = CONVERT (VARCHAR (7000), @intOPTION)
	EXECUTE @varKSERROR = dbo.X_UPDATE_G_PROV_VALUE @varKSpLINK, @varKS_param, @varKSstrVALUE
	IF @varKSERROR <> 0
		RETURN @varKSERROR

	--Событие системного журнала
	SET @varKSEventText = 'Авансовый отчет' + ' №' + RTRIM(@varKSpNUMBER) + ' от ' + convert(varchar, @varKSpDATE, 104)
	EXECUTE WF_GENERATEEVENT 'Сохранение документа', @varKSEventText, @varKSLinkObj, 'G_PROV', @varKSpLINK
IF @@TRANCOUNT > @varKStrancount
	COMMIT TRAN
RETURN 0



GO


GRANT EXECUTE ON dbo.[X_SAVE_BV_DOC_AVANSE_REP] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[PV_SAVE_G_PROV1_MENU_REQ]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[PV_SAVE_G_PROV1_MENU_REQ]

GO

CREATE	PROCEDURE dbo.PV_SAVE_G_PROV1_MENU_REQ
	@varKSnLINK_DOC INT,
	@varKSnDEL	TINYINT = 0	

AS

DECLARE
	@varKSnTYP_LINK INT,			
	@varKScNAME_OPER VARCHAR(250),
	@varKScNAME_OPER_OS VARCHAR(250),
	@varKSnLINK_OS INT, 
	@varKScCODE_OS VARCHAR(100),
	@varKSnSUMMA1 NUMERIC(28,2),
	@varKSnSUMMA2 NUMERIC(28,2),
	@varKSnQTY NUMERIC(19,4),
	@varKSnLINK_GP1 INT,
	@varKSnORDERS INT,
	@varKSdCALC_DATE DATETIME,
	@varKSxRet	INT,
	@varKScSOU_CODE CHAR(1),
	@varKCcTYPE_INV VARCHAR(30),
	@varKScErrTxt VARCHAR(60), 
	@varKSnEmpLink INT

DECLARE GRID_CUR CURSOR LOCAL STATIC READ_ONLY FOR
--	SELECT NOMEN_LINK, NOMEN_CODE, SUM(QTY_BREAKFAST) + SUM(QTY_DINNER) + SUM(QTY_AFTERNOON) + SUM(QTY_SUPPER) AS QTY
	SELECT NOMEN_LINK, NOMEN_CODE, SUM (QTY_ALL) AS QTY
	FROM dbo.PV_MENU_FEEDING_AMOUNT_TAB 
	WHERE LINK_UP = @varKSnLINK_DOC 
	GROUP BY NOMEN_LINK, NOMEN_CODE

IF @varKSnLINK_DOC IS NULL OR @varKSnLINK_DOC <= 0
	RETURN -1	

IF @varKSnDEL = 1
  BEGIN
	PRINT 'Удаление существующих проводок'
	DELETE FROM G_PROV1 WHERE LINK_UP = @varKSnLINK_DOC
  END

SELECT TOP 1 @varKSnTYP_LINK = LINK_OPER
FROM dbo.XD_DOC_NASTR_T1 T1, S_OBJECTS SO 
WHERE SO.CODE = 'PV_MENU_REQUIREMENT' AND SO.LINK = T1.LINK_UP
ORDER BY OSN DESC


SELECT @varKScNAME_OPER = NAME_OPER FROM G_PROV1 WHERE LINK = @varKSnTYP_LINK
SELECT @varKSdCALC_DATE = DATE + 1 , @varKSnEmpLink = LINK_MOL FROM PV_MENU_REQUIREMENT WHERE LINK = @varKSnLINK_DOC

SET @varKSnORDERS = 0

OPEN GRID_CUR
FETCH NEXT FROM GRID_CUR INTO @varKSnLINK_OS, @varKScCODE_OS, @varKSnQTY
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @varKSnORDERS = @varKSnORDERS + 1

	SET @varKScNAME_OPER_OS = RTRIM(ISNULL(@varKScNAME_OPER,'Операция')) + ' Номен.№ "' + RTRIM(@varKScCODE_OS) + '"'

	SET @varKSnLINK_GP1 = NULL
	EXEC dbo.X_UPDATE_G_PROV1 @varKSnLINK_GP1 OUTPUT, @varKSnLINK_DOC, @varKSnTYP_LINK,
			@varKScNAME_OPER_OS, @varKSnORDERS

	IF @varKSnLINK_GP1 IS NULL
		RETURN -3	

	EXEC @varKSxRet = dbo.PV_SAVE_G_PROV2_MENU_REQ @varKSnLINK_GP1, @varKSnTYP_LINK, @varKSnLINK_OS, @varKSnQTY, @varKSnEmpLink, @varKSdCALC_DATE --, '1'
	
	IF NOT EXISTS (SELECT * FROM dbo.G_PROV2 WHERE LINK_UP = @varKSnLINK_GP1)
		DELETE FROM dbo.G_PROV1 WHERE LINK = @varKSnLINK_GP1

	IF @varKSxRet <> 0
	  BEGIN
	    SET @varKScErrTxt = CASE @varKSxRet
				WHEN -1 THEN '"Не задан линк операции"'
				WHEN -2 THEN '"Не найден остаток по данному материалу"'
			   END
	    PRINT 'Ошибка при записи проводки по материалу: "'+ RTRIM(@varKScCODE_OS)+ '" ' + RTRIM(@varKScErrTxt)
	    IF @varKSxRet = -2
		RETURN -5	
	    ELSE
		RETURN -4	
	  END
	FETCH NEXT FROM GRID_CUR INTO @varKSnLINK_OS, @varKScCODE_OS, @varKSnQTY
END

CLOSE GRID_CUR
DEALLOCATE GRID_CUR

EXEC dbo.X_SALDO_COMMITCHANGES	

RETURN 0

GO

GRANT EXECUTE ON dbo.[PV_SAVE_G_PROV1_MENU_REQ] TO PUBLIC

GO

--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_PRINT_RL_XML]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_PRINT_RL_XML]

GO

CREATE PROCEDURE [dbo].SA_PRINT_RL_XML

@cYear1 VARCHAR(4)	/* Расчетный год */,
@nMonth1 int	/* Расчетный месяц */,
@nOption1 int = 1	/* Порядок сортировки */,
@nCheck1 int = 0	/* Печатать только по одному  Р/Л на сотрудника */,
@nCheck2 int = 0	/* Не печатать должность сотрудника */,
@nCheck3 int = 0	/* Разделять Б/Л за счет ФСС и работодателя */,
@nCheck4 int = 0	/* Отображать источник финансирования */,
@nCheck5 int = 0	/* Формировать пустые р/л */,
@nOption2 int = 1	/* Создание отчёта */,
@nCombo1 int = 3 /* Количество листочков на листе */,
@nCheck6 int = 0	/* Детализировать остаток */,
@nCheck7 int = 0 /* Отображать разряд */,
@nCheck8 int = 0 /* ФИО полностью */,
@nCheck9 int = 0 /*Выводить наименование отдела вместо кода*/,
@nCheck10 int	/* Формировать р/л за каждый месяц с начала года по выбранный месяц */,
@nFilterLink int	/* Фильтр */

AS

IF COALESCE(@nCombo1,0) = 0
	SET @nCombo1 = 3

IF @nCombo1 = 1
	SET @nCombo1 = 999999
ELSE
	SET @nCombo1 = @nCombo1 - 1

DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор сотрудников */
SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE='OTBOR_QUERY_SQL_EMPL'))
SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE='QUERY_OTBOR_CHECK'))

DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор групп сотрудников */
SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE='OTBOR_QUERY_SQL_GROUPS_EMPL'))
SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE='QUERY_OTBOR_CHECK'))

CREATE TABLE #DATA (
		[ID] INT,
		LINK_EMPL1 INT, FIO VARCHAR(254), TN VARCHAR(15), MON TINYINT, SUBDIV VARCHAR(254),POST VARCHAR(50),
		OKLAD NUMERIC(20,2), FWT INT,
		REST_BEG NUMERIC(20,2), REST_D NUMERIC(20,2),
		
		SUM_TOTAL NUMERIC(20,2), 
		DEDUCT NUMERIC(20,2), 	
		NDFL NUMERIC(20,2),	
		
		INSUR NUMERIC(20,2), 	
		GAIN NUMERIC(20,2),	
		NUM INT,

		LINK_EMPL INT,
		DAYS NUMERIC(15,2), PERC NUMERIC(15,2),
		CODE_PAY VARCHAR(20), NAME_PAY VARCHAR(254), SUM_PAY NUMERIC(20,2),
		CODE_TAX VARCHAR(20), NAME_TAX VARCHAR(254), SUM_TAX NUMERIC(20,2),
		ORDERS TINYINT,VKR_CODE VARCHAR(20),VKR_NAME VARCHAR(400),
		VKR_ALL VARCHAR(400), NAME VARCHAR(254)
)

DECLARE @DATE_BEG DATETIME, @DATE_01 DATETIME, @END_DATE DATETIME, @START_YEAR DATETIME
SET @DATE_BEG = dbo.ConvertDMY2Date(1, @nMonth1, CONVERT(INT,@cYear1))
SET @DATE_01 = DATEADD(DAY, -1, @DATE_BEG)
SET @END_DATE = dbo.DateEndOfMonth(@DATE_BEG)
SET @START_YEAR = dbo.DateBeginOfYear(@DATE_BEG)


INSERT INTO #DATA
exec DBO.SD_REP_RL @cYear1, @nMonth1, @cVal1, @nOtborLink1,
@nOption1	/* Порядок сортировки */,
@nCheck3	/* Разделять Б/Л за счет ФСС и работодателя */,
0, --nLinkEmpl
@nCheck4	/* Отображать источник финансирования */,
@nCheck5	/* Формировать пустые р/л */,
@nCheck7	/* Отображать разряд */,
@cVal2, @nOtborLink2, 
@nCheck8, --ФИО полностью
@nCheck9, --Выводить наименование отдела вместо кода
@nCheck10 --Формировать р/л за каждый месяц с начала года по выбранный месяц

DECLARE @lcFNAME varchar(254)
SET @lcFNAME = 'RL.XML'

CREATE TABLE #OUTPUT (ID int identity(1,1), F_NAME VARCHAR(254), OUT_TEXT TEXT)

INSERT INTO #OUTPUT (F_NAME, OUT_TEXT)
SELECT @lcFNAME, 'OEM' --Имя файла
UNION ALL SELECT @lcFNAME, SPACE(0) + '<?xml  version="1.0"  encoding = "windows-1251"?>'
UNION ALL SELECT @lcFNAME, SPACE(0) + '<!--Отчет xmlns="http://tempuri.org/XMLSchema.xsd"-->'
UNION ALL SELECT @lcFNAME, SPACE(0) + '<Отчет xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XMLSchema.xsd">'
	UNION ALL SELECT @lcFNAME, SPACE(1) + '<ПарамЧасть>'
		UNION ALL SELECT @lcFNAME, SPACE(2) + '<ИстПарам>' + CONVERT(VARCHAR(10),@nCheck4) + '</ИстПарам>'
		UNION ALL SELECT @lcFNAME, SPACE(2) + '<ШабПарам>' + CONVERT(VARCHAR(10),@nCheck1) + '</ШабПарам>'
		UNION ALL SELECT @lcFNAME, SPACE(2) + '<ДолжПарам>' + CONVERT(VARCHAR(10),@nCheck2) + '</ДолжПарам>'
		UNION ALL SELECT @lcFNAME, SPACE(2) + '<КолЛисточков>' + CONVERT(VARCHAR(10),@nCombo1) + '</КолЛисточков>'
		UNION ALL SELECT @lcFNAME, SPACE(2) + '<ДеталОст>' + CONVERT(VARCHAR(10),@nCheck6) + '</ДеталОст>'
	UNION ALL SELECT @lcFNAME, SPACE(1) + '</ПарамЧасть>'

	DECLARE @Cur1 CURSOR, @ID INT, @BEFORE VARCHAR(2000), @AFTER VARCHAR(2000), @LINK_EMPL INT
	SET @Cur1 = CURSOR FORWARD_ONLY

	FOR SELECT DISTINCT
		ID,
		B = 
	SPACE(1) + '<ИнфЧасть>'	+ CHAR(13) + CHAR(10)	
	+ SPACE(2) + '<ФизЛицо>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Таб>' + LTRIM(RTRIM(COALESCE(TN,''))) + '</Таб>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Отдел>' + LTRIM(RTRIM(COALESCE(SUBDIV,''))) + '</Отдел>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Должность>' + LTRIM(RTRIM(COALESCE(POST,''))) + '</Должность>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Оклад>' + RTRIM(LTRIM(STR(COALESCE(OKLAD,0),15,2))) + '</Оклад>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<ФИО>' + LTRIM(RTRIM(COALESCE(FIO,'')))  + '</ФИО>' + CHAR(13) + CHAR(10)
	+ SPACE(2) + '</ФизЛицо>' + CHAR(13) + CHAR(10)

	+ SPACE(2) + '<Период>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Год>' + LTRIM(RTRIM(@cYear1)) + '</Год>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Месяц>' + RTRIM(LTRIM(STR(COALESCE(MON,0),15))) + '</Месяц>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<ФРабВрем>' + RTRIM(LTRIM(STR(COALESCE(FWT,0),15,2))) + '</ФРабВрем>' + CHAR(13) + CHAR(10)
	+ SPACE(2) + '</Период>' + CHAR(13) + CHAR(10)

	+ SPACE(2) + '<Остаток>' + RTRIM(LTRIM(STR(COALESCE(REST_BEG,0),15,2))) + '</Остаток>' + CHAR(13) + CHAR(10),

	A = 
	  SPACE(2) + '<ДолгОрг>' + RTRIM(LTRIM(STR(COALESCE(REST_D,0),15,2))) + '</ДолгОрг>' + CHAR(13) + CHAR(10)

	+ SPACE(2) + '<НДФЛ>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<СовДох>' + RTRIM(LTRIM(STR(COALESCE(SUM_TOTAL,0),15,2))) + '</СовДох>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Налог>' + RTRIM(LTRIM(STR(COALESCE(NDFL,0),15,2))) + '</Налог>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Вычеты>' + RTRIM(LTRIM(STR(COALESCE(DEDUCT,0),15,2))) + '</Вычеты>' + CHAR(13) + CHAR(10)
	+ SPACE(2) + '</НДФЛ>' + CHAR(13) + CHAR(10)

	+ SPACE(2) + '<ПенСтрах>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<СтрахЧасть>' + RTRIM(LTRIM(STR(COALESCE(INSUR,0),15,2))) + '</СтрахЧасть>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<НакопЧасть>' + RTRIM(LTRIM(STR(COALESCE(GAIN,0),15,2))) + '</НакопЧасть>' + CHAR(13) + CHAR(10)
	+ SPACE(2) + '</ПенСтрах>' + CHAR(13) + CHAR(10)

	+ SPACE(2) + '<ИстФин>' + CHAR(13) + CHAR(10)
		+ SPACE(3) + '<Комментарий>' + LTRIM(RTRIM(COALESCE(VKR_ALL,''))) + '</Комментарий>' + CHAR(13) + CHAR(10)
	+ SPACE(2) + '</ИстФин>' + CHAR(13) + CHAR(10)
	+ SPACE(1) + '</ИнфЧасть>',
	
	LINK_EMPL1

 	FROM 
		#DATA

	OPEN @Cur1
	FETCH NEXT FROM @Cur1 INTO @ID, @BEFORE, @AFTER, @LINK_EMPL
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN

			INSERT INTO #OUTPUT (F_NAME, OUT_TEXT)
			SELECT @lcFNAME, @BEFORE

			INSERT INTO #OUTPUT (F_NAME, OUT_TEXT)
			SELECT @lcFNAME, 
				SPACE(2) + '<НачУд>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Источник>' + RTRIM(LTRIM(COALESCE(VKR_CODE,''))) + '</Источник>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Код>' 
					+ CASE WHEN RTRIM(LTRIM(COALESCE(CODE_PAY,''))) <> '' 
						THEN RTRIM(LTRIM(COALESCE(CODE_PAY,''))) 
						ELSE RTRIM(LTRIM(COALESCE(CODE_TAX,''))) 
					  END
					+ '</Код>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Дни>' + RTRIM(LTRIM(STR(COALESCE(DAYS,0),15,2))) + '</Дни>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Часы>' + RTRIM(LTRIM(STR(COALESCE(PERC,0),15,2))) + '</Часы>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Наименование>' 
					+ CASE WHEN RTRIM(LTRIM(COALESCE(NAME_PAY,''))) <> ''
						THEN RTRIM(LTRIM(COALESCE(NAME_PAY,'')))
						ELSE RTRIM(LTRIM(COALESCE(NAME_TAX,'')))
					  END
					+ '</Наименование>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Начисл>' + RTRIM(LTRIM(STR(COALESCE(SUM_PAY,0),15,2))) + '</Начисл>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<Удерж>' + RTRIM(LTRIM(STR(COALESCE(SUM_TAX,0),15,2))) + '</Удерж>' + CHAR(13) + CHAR(10)
			+	SPACE(2) + '</НачУд>' + CHAR(13) + CHAR(10)
			FROM 
				#DATA
			WHERE
				ID = @ID

			INSERT INTO #OUTPUT (F_NAME, OUT_TEXT)
			SELECT @lcFNAME, 
				SPACE(2) + '<ОстК>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<ОстКИсточник>' + RTRIM(LTRIM(COALESCE(F.CODE,''))) + '/'+ RTRIM(LTRIM(ISNULL(E.CODE,''))) + '</ОстКИсточник>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<ОстКСумНМ>' + RTRIM(LTRIM(STR(COALESCE(SUMMA1,0),15,2))) + '</ОстКСумНМ>' + CHAR(13) + CHAR(10)		
				+	SPACE(3) + '<ОстКСумН>' + RTRIM(LTRIM(STR(COALESCE(SUMMA2,0),15,2))) + '</ОстКСумН>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<ОстКСумУ>' + RTRIM(LTRIM(STR(COALESCE(SUMMA3,0),15,2))) + '</ОстКСумУ>' + CHAR(13) + CHAR(10)
				+	SPACE(3) + '<ОстКСум>' + RTRIM(LTRIM(STR(COALESCE(SUMMA4,0),15,2))) + '</ОстКСум>' + CHAR(13) + CHAR(10)
			+	SPACE(2) + '</ОстК>' + CHAR(13) + CHAR(10)
			FROM 
				DBO.SA_BALANCE_DECODING(@START_YEAR,@END_DATE,1,1) T 
				LEFT JOIN DBO.SAL_SFIN F ON F.LINK = T.LINK_VKR
				LEFT JOIN dbo.KOSGU E ON E.LINK = T.LINK_EKR
			WHERE 
				LINK_EMPL = @LINK_EMPL
				AND
				@nCheck6 = 1

			INSERT INTO #OUTPUT (F_NAME, OUT_TEXT)
			SELECT @lcFNAME, @AFTER

		END
	
		FETCH NEXT FROM @Cur1 INTO @ID, @BEFORE, @AFTER, @LINK_EMPL
	END
	
	CLOSE @Cur1
	DEALLOCATE @Cur1

INSERT INTO #OUTPUT (F_NAME, OUT_TEXT) SELECT @lcFNAME, SPACE(0) + '</Отчет>'

SELECT * FROM #OUTPUT
DROP TABLE #OUTPUT

GO


GRANT EXECUTE ON dbo.[SA_PRINT_RL_XML] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_REP_RL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_REP_RL]

GO

CREATE PROCEDURE dbo.SD_REP_RL 
	@cYear VARCHAR(4),
	@nMonth INT,
	@cVal1 CHAR(1), @nOtborLink1 int,	
	@nOption1 int,
	@nCheck3 int, /* Разделять Б/Л за счет ФСС и работодателя */
	@nLinkEmpl int = 0,
	@nCheck4 int = 0, /* Отображать источник при печати*/
	@nCheck5 int = 0, /* Печатать пустые р/л*/
	@nCheck7 int = 0, /* Отображать разряд */
	@cVal2 CHAR(1) = '', @nOtborLink2 int = 0,
	@nCheck8 int = 0 /* Выводить Ф.И.О. полностью */,
	@nCheck9 int = 0 /*Выводить наименование отдела вместо кода*/,
	@ALL_MONTH INT = 0	

AS BEGIN

	DECLARE @Month INT, @Year INT, @nYear INT, @ldDate DATETIME
	SET @ldDate = DBO.SalaryCalcPeriod()
	set @nYear = @cYear
	
	SELECT @Month = DATEPART(MONTH, @ldDate), @Year = DATEPART(YEAR, @ldDate)

	IF (@nMonth=0)
		set @nMonth = @Month
	
	IF (@nYear=0)
		set @nYear = @Year

	DECLARE @EDate datetime
	Set @EDate = dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@nMonth,convert(int,@nYear)))

	declare @DEP_LINK int
	exec dbo.xd_whats_zb @DEP_LINK output
	
	DECLARE @start_date DATETIME, @END_DATE DATETIME, @START_YEAR DATETIME
	SELECT @start_date = dbo.ConvertDMY2Date(1, @nMonth, @nYear)
	SELECT @END_DATE = dbo.DateEndOfMonth(@start_date)
	SELECT @START_YEAR = dbo.DateBeginOfYear(@start_date)

	CREATE TABLE #RES (
		LINK_EMPL INT, FIO VARCHAR(254), TN VARCHAR(15), MON TINYINT,
		OKLAD NUMERIC(20,2), FWT INT,
		CODE_PAY VARCHAR(10), NAME_PAY VARCHAR(254), SUM_PAY NUMERIC(20,2),
		CODE_TAX VARCHAR(10), NAME_TAX VARCHAR(254), SUM_TAX NUMERIC(20,2),
		REST_BEG NUMERIC(20,2), REST_END NUMERIC(20,2),
		
		SUM_TOTAL NUMERIC(20,2), DEDUCCT NUMERIC(20,2), NDFL NUMERIC(20,2),
		
		INSUR NUMERIC(20,2), 	
		GAIN NUMERIC(20,2),	
		ORDERS TINYINT
	)

	CREATE TABLE #EMPLS0 (LINK_EMPL INT)
	CREATE TABLE #EMPLS (LINK_EMPL INT)
	CREATE TABLE #EMPLS1 (LINK_EMPL INT, MON TINYINT)
	CREATE TABLE #EMPLS2 (LINK_EMPL INT, MON TINYINT)

	CREATE TABLE #GE (LINK INT)

	IF @nLinkEmpl = 0
	BEGIN

		IF LEN(@cVal1) <> 0 
			INSERT INTO #EMPLS0
			SELECT RECORD FROM dbo.OBJECT_VAR_EMPL WHERE LINK_UP = @nOtborLink1
		ELSE BEGIN
				INSERT INTO #EMPLS0
				SELECT LINK
				FROM dbo.EMPL
				WHERE 
					DEP_LINK = @DEP_LINK
			END
	END
	
	IF @nLinkEmpl > 0
	BEGIN
			INSERT INTO #EMPLS0 
			SELECT @nLinkEmpl
	END
	
	IF @cVal2 = '1' --Сотрудники из групп
	BEGIN
		INSERT INTO #GE (LINK)
		SELECT GE.LINK_EMPL 
		FROM 
			dbo.GROUPS_EMPL G
			INNER JOIN dbo.OBJECT_VAR_GROUPS_EMPL O ON G.LINK = O.RECORD
			INNER JOIN dbo.GROUPS_EMPL_REF GE ON GE.[LINK_GROUP] = G.LINK
		WHERE
			O.LINK_UP = @nOtborLink2
			
		INSERT INTO #EMPLS (LINK_EMPL)
		SELECT LINK_EMPL
		FROM #EMPLS0 E INNER JOIN #GE G ON E.LINK_EMPL = G.LINK
	END	
	ELSE
		INSERT INTO #EMPLS (LINK_EMPL)
		SELECT LINK_EMPL
		FROM #EMPLS0 E

	CREATE TABLE #T1( Link_Empl INT, MON TINYINT, TYP_OPER INT, WAY_CALC INT, summa NUMERIC(20,2) )
	CREATE TABLE #T2( Link_Empl INT, MON TINYINT, TYP_OPER INT, WAY_CALC INT, summa NUMERIC(20,2) )
	CREATE TABLE #T3(LINK_EMPL INT, MON TINYINT, SUMMA NUMERIC(20,2))

	CREATE TABLE #RES1 (
		LINK_EMPL INT, MON TINYINT,
		[DAYS] NUMERIC(15,2), PERC NUMERIC(15,2),
		CODE_PAY VARCHAR(20), NAME_PAY VARCHAR(254), SUM_PAY NUMERIC(20,2),
		CODE_TAX VARCHAR(20), NAME_TAX VARCHAR(254), SUM_TAX NUMERIC(20,2),
		ORDERS TINYINT,VKR_CODE VARCHAR(20),VKR_NAME VARCHAR(400))

	CREATE TABLE #SALARY_JURNAL_CALCULAT (
		[LINK_EMPL] int,
		[MON] TINYINT,
		[LINK_PAYS] int,
		[CODE_PAYS] varchar(20),
		[NAME_PAYS] varchar(254),
		[SNAME_PAYS] varchar(254),
		[WAY_CALC] tinyint,
		[MONTH_BEGIN] int,
		[YEAR_BEGIN] int,
		[MONTH_END] int,
		[YEAR_END] int,
		[PERIOD_BEGIN] datetime,
		[PERIOD_END] datetime,
		[PERC] numeric(15, 2),
		[DAYS] numeric(38, 2),
		[summa] numeric(38, 2),
		[LINK_DOC] int NULL,
		[CODE_DOC] varchar(30),
		[DATE1] datetime,
		[DATE2] datetime,
		[TYP_OPER] tinyint,
		[LINK_EKR] int,
		[CODE_EKR] char(3),
		[VKR_CODE] varchar(20),
		[VKR_NAME] varchar(400))

	CREATE TABLE #REST_B1(LINK_EMPL INT, [MON] TINYINT,
		BEG_PAY NUMERIC(20,2), BEG_TAX NUMERIC(20,2), BEG_R NUMERIC(20,2), 
		END_PAY NUMERIC(20,2), END_TAX NUMERIC(20,2),	
	)
	CREATE TABLE #REST_B(LINK_EMPL INT, [MON] TINYINT, REST_BEG NUMERIC(20,2), REST_D NUMERIC(20,2))		

	CREATE TABLE #SD_EMPL (
		[LINK] int,
		[MON] TINYINT,
		[FIO] varchar(254),
		[TAB] varchar(10),
		[SUBDIV_CODE] varchar(254),
		[post_name] varchar(254),
		[DATE_BEGIN] datetime,
		[DATE_END] datetime,
		[SACK] int,
		[NUM_STAKE] numeric(3, 2))	

	DECLARE @BUF_ID VARCHAR(20), @LINK_EMPL2 INT
	DECLARE @SQL VARCHAR(1000)
	CREATE TABLE #OKLAD (LINK_EMPL INT, MON TINYINT, LINK_SOVM INT, SUMMA NUMERIC(18,2) )		

	CREATE TABLE #NORM_DAYS_TABLE (LINK_EMPL INT, MON TINYINT, DAY_NORM INT)

	---
	DECLARE @PAR1 INT
	SET @PAR1 = CASE WHEN @nLinkEmpl = 0 THEN -1 ELSE @nLinkEmpl END
		
	
	----
	SELECT DISTINCT
		[LINK] = SD.LINK_UP,
		[TYP_PAYMENT] = SD.TYP_PAYMENT
	INTO #DOCUMENTS_DED_PR
	FROM dbo.SDOC_VEDOM SD

	---
	set @nCheck3 = Coalesce(@nCheck3,0)

	CREATE TABLE #SA_EMPLS_W (LINK INT, LINK_EMPL INT, MON TINYINT, RAZR INT, SYST_PAY TINYINT, FOT TINYINT)	

	DECLARE @DATE_01 DATETIME
	DECLARE @Cur1 CURSOR, @NUM TINYINT
	SET @Cur1 = CURSOR FORWARD_ONLY
	FOR select NUM from dbo.MONTHS WHERE NUM <= @nMonth AND NUM >= (CASE WHEN @ALL_MONTH = 1 THEN 1 ELSE @nMonth END) order by NUM
	
	OPEN @Cur1
	FETCH NEXT FROM @Cur1 INTO @NUM
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN

			SET @DATE_01 = DATEADD(DAY, -1, dbo.ConvertDMY2Date(1,@NUM,convert(int,@nYear)))

			INSERT INTO #T1
			SELECT T.LinkEmpl, @NUM, T.TYP_OPER, T.WAY_CALC, T.summa
			FROM #EMPLS E INNER JOIN dbo.SALARY_TAX_DED_Sum_ALL_TABLE(
											@START_YEAR, 
											@DATE_01, 
											DEFAULT ) T on E.LINK_EMPL = T.LinkEmpl
			
			SET @DATE_01 = dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@NUM,convert(int,@nYear)))

			INSERT INTO #T2 (Link_Empl, MON, TYP_OPER, WAY_CALC, summa)
			SELECT T.LinkEmpl, @NUM, T.TYP_OPER, T.WAY_CALC, T.summa
			FROM 
				#EMPLS E INNER JOIN dbo.SALARY_TAX_DED_Sum_ALL_TABLE(
											@START_YEAR, 
											@DATE_01, 
											DEFAULT) T on E.LINK_EMPL = T.LinkEmpl

			INSERT INTO #T3
			SELECT 
				SJ.LINK_EMPL, @NUM, SUM(SJ.summa) 
			FROM
				#EMPLS E 
				INNER JOIN dbo.CALCULATE_JURNAL SJ on E.LINK_EMPL = SJ.LINK_EMPL
				INNER JOIN (SELECT LINK_PAYS FROM dbo.NDFL_GroupTax() ) T ON T.LINK_PAYS = SJ.LINK_PAYS
			WHERE   
				SJ.LINK_DEP = @DEP_LINK
				AND SJ.PERIOD_BEGIN >= @START_YEAR AND SJ.PERIOD_END <= @DATE_01
			GROUP BY 
				SJ.LINK_EMPL
	
			SET @DATE_01 = dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@NUM,convert(int,@nYear)))

			INSERT INTO #SA_EMPLS_W (link, link_empl, MON, RAZR, SYST_PAY, FOT)
			select link, link_empl, @NUM, RAZR, SYST_PAY, FOT 
			from [dbo].[SA_EMPLS_W_FN](DEFAULT,@DATE_01,DEFAULT,@DEP_LINK)
			
			
			INSERT INTO #SALARY_JURNAL_CALCULAT(
				LINK_EMPL, MON, LINK_PAYS, CODE_PAYS, NAME_PAYS, SNAME_PAYS, WAY_CALC, 
				MONTH_BEGIN, YEAR_BEGIN, MONTH_END, YEAR_END, PERIOD_BEGIN, PERIOD_END, 
				PERC, [DAYS], summa, LINK_DOC, CODE_DOC, DATE1, DATE2, TYP_OPER, LINK_EKR, CODE_EKR, VKR_CODE, VKR_NAME)

			SELECT 
				SJC.LINK_EMPL,
				MON = @NUM,	
				SJC.[LINK_PAYS],
				[CODE_PAYS] = P.CODE,
				[NAME_PAYS] = P.NAME,
				[SNAME_PAYS] = P.[SNAME] + CASE WHEN ISNULL(@nCheck7,0) = 1 AND COALESCE(EP.FOT,0) = 2 AND COALESCE(EP.RAZR,0) > 0 THEN ' ' + CONVERT(VARCHAR(3),EP.RAZR) + 'р.' ELSE '' END,
				P.[WAY_CALC],
				[MONTH_BEGIN] = MONTH(SJC.PERIOD_BEGIN),
				[YEAR_BEGIN] = YEAR(SJC.PERIOD_BEGIN),
				[MONTH_END] = MONTH(SJC.PERIOD_END),
				[YEAR_END] = YEAR(SJC.PERIOD_END),
				[PERIOD_BEGIN] = dbo.DateBeginOfMonth(SJC.PERIOD_BEGIN),
				[PERIOD_END] = dbo.DateEndOfMonth(SJC.PERIOD_END),
				[PERC] = SJC.PROCENT,
				[DAYS] = CASE WHEN P.RL_TIME = 1 THEN SUM(case when COALESCE(EP.SYST_PAY,1) = 1 OR P.RL_DAYS = 1 then SJC.[DAYS] else SJC.[HOURS] end) ELSE NULL END,
				summa = sum(SJC.[SUMMA]),
 				[LINK_DOC] = (CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN LINK_DOC ELSE 0 END),
 				[CODE_DOC] = (CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN doc.so_code ELSE '' END),
				[DATE1] = (CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN SJC.DATE_BEGIN ELSE dbo.DateBeginOfMonth(SJC.DATE_BEGIN) END),
				[DATE2] = (CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN SJC.DATE_END ELSE dbo.DateEndOfMonth(SJC.DATE_END) END),
				[TYP_OPER] = P.OBJECT,
				[LINK_EKR] = (case when P.OBJECT = 1 AND @nCheck3 = 1 THEN COALESCE(SJC.LINK_EKR,P.LINK_EKR) ELSE null end),
				[CODE_EKR] = (case when P.OBJECT = 1 AND @nCheck3 = 1 THEN EKR.CODE ELSE '' end),
				[VKR_CODE] = (case when @nCheck4 = 1 THEN FIN.[CODE] ELSE '' end),
				[VKR_NAME] = (case when @nCheck4 = 1 THEN FIN.[NAME] ELSE '' end)
			FROM 
				#EMPLS E 
				INNER JOIN dbo.CALCULATE_JURNAL SJC ON SJC.LINK_EMPL = E.LINK_EMPL
				INNER JOIN dbo.PAYS P ON SJC.LINK_PAYS = P.LINK	
				LEFT JOIN #SA_EMPLS_W EP ON EP.MON = @NUM AND EP.link_empl = SJC.LINK_EMPL AND EP.link = COALESCE(SJC.LINK_SOVM,0)
				LEFT JOIN (Select distinct doc_link = d.link, so_link = so.link, so_code = rtrim(SO.CODE) from dbo.sdoc d inner join dbo.s_objects so on d.object = so.link) DOC
					on DOC.doc_link = SJC.LINK_DOC
				LEFT JOIN dbo.SAL_SFIN FIN on SJC.LINK_VKR = FIN.LINK
				LEFT JOIN dbo.KOSGU EKR on COALESCE(SJC.LINK_EKR,P.LINK_EKR) = EKR.LINK
			WHERE 
				P.OBJECT <> 3 
				AND MONTH(SJC.PERIOD_BEGIN) = @NUM 
				AND YEAR(SJC.PERIOD_BEGIN) = @nYear 
				AND SJC.LINK_DEP = @DEP_LINK
				AND (SJC.LINK_EMPL = @nLinkEmpl OR @nLinkEmpl = 0)
			group by 
				SJC.LINK_EMPL,COALESCE(EP.SYST_PAY,0), SJC.[LINK_PAYS], P.CODE, P.[SNAME], [RAZR], P.NAME, FOT,
				MONTH(SJC.PERIOD_BEGIN),YEAR(SJC.PERIOD_BEGIN),MONTH(SJC.PERIOD_END),YEAR(SJC.PERIOD_END),
				dbo.DateBeginOfMonth(SJC.PERIOD_BEGIN), dbo.DateEndOfMonth(SJC.PERIOD_END), 
				(CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN SJC.DATE_BEGIN ELSE dbo.DateBeginOfMonth(SJC.DATE_BEGIN) END),
				(CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN SJC.DATE_END ELSE dbo.DateEndOfMonth(SJC.DATE_END) END),
				SJC.PROCENT, 
				P.OBJECT, [WAY_CALC], 
				(case when P.OBJECT = 1 AND @nCheck3 = 1 THEN EKR.CODE ELSE '' end), 
				(case when P.OBJECT = 1 AND @nCheck3 = 1 THEN COALESCE(SJC.LINK_EKR,P.LINK_EKR) ELSE null end), 
				(CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN LINK_DOC ELSE 0 END),
				(CASE WHEN doc.so_code IN ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG','DOCUMENTS_DED_PAYROLL') THEN doc.so_code ELSE '' END),
				(case when @nCheck4 = 1 THEN FIN.[CODE] ELSE '' end),
				(case when @nCheck4 = 1 THEN FIN.[NAME] ELSE '' end),
				P.RL_TIME

	
			--
			IF @nCheck3 = 1
			UPDATE #SALARY_JURNAL_CALCULAT
				Set 
					CODE_PAYS = rtrim(ltrim(CODE_PAYS)) + (case rtrim(ltrim(CODE_EKR)) when '211' then 'Р' when '213' then 'Ф' else '' end)
				where link_ekr is not null and way_calc in (13,20) and 	TYP_OPER = 1
				

			INSERT INTO #RES1
			SELECT 
				SJC.LINK_EMPL,
				@NUM,
				SJC.[DAYS], 
				SJC.PERC,
				CASE WHEN TYP_OPER = 1 THEN LTRIM(RTRIM(CODE_PAYS)) ELSE '' END,
				CASE WHEN TYP_OPER = 1 THEN 
						LTRIM(RTRIM(SNAME_PAYS)) + SPACE(1) +
						case when code_doc in ('DOCUMENTS_ADD_ARCHE', 'DOCUMENTS_ADD_FURLOUGH','DOCUMENTS_CALC_TRAVEL','DOCUMENTS_CALC_AVG') then
								'(' + convert(varchar(5),date1,104) + '-' + convert(varchar(5),date2,104) + ')'
						else
							case  when date1 <> period_begin then
									'(за ' + dbo.PrintRLGetMonthYear(date1) 
									+ case when (year(date1) * 100 + Month(date1)) = (year(date2) * 100 + Month(date2)) then '' 
										else '-' + dbo.PrintRLGetMonthYear(date2) end+ ')' 
							else '' 
							end --when date1 <> period_begin then
						end
				ELSE '' 
				END,
				CASE WHEN TYP_OPER = 1 THEN SUMMA ELSE 0 END,
				CASE WHEN TYP_OPER = 2 THEN LTRIM(RTRIM(CODE_PAYS)) ELSE '' END,
				CASE WHEN 
					TYP_OPER = 2 THEN 
						LTRIM(RTRIM(SNAME_PAYS)) + SPACE(1) 
						+ case 
							when date1 <> period_begin 
								then '(за ' + dbo.PrintRLGetMonthYear(date1) + ')' 
							else '' 
						end			
					ELSE '' 
				END,
				CASE WHEN TYP_OPER = 2 THEN SUMMA ELSE 0 END,
				CASE 
					WHEN TYP_OPER = 1 THEN 1
					WHEN TYP_OPER = 2 AND CODE_DOC <> 'DOCUMENTS_DED_PAYROLL'  THEN 2
					WHEN TYP_OPER = 2 AND CODE_DOC = 'DOCUMENTS_DED_PAYROLL' AND (SELECT TYP_PAYMENT FROM #DOCUMENTS_DED_PR DDP WHERE DDP.LINK =  LINK_DOC) = 2  THEN 3
					WHEN TYP_OPER = 2 AND CODE_DOC = 'DOCUMENTS_DED_PAYROLL' AND (SELECT TYP_PAYMENT FROM #DOCUMENTS_DED_PR DDP WHERE DDP.LINK =  LINK_DOC) = 3  THEN 4
					WHEN TYP_OPER = 2 AND CODE_DOC = 'DOCUMENTS_DED_PAYROLL' AND (SELECT TYP_PAYMENT FROM #DOCUMENTS_DED_PR DDP WHERE DDP.LINK =  LINK_DOC) = 1  THEN 5

					ELSE 7  
				END,
				SJC.VKR_CODE,
				SJC.VKR_NAME
			FROM 
				#SALARY_JURNAL_CALCULAT SJC
			WHERE 
				TYP_OPER <> 3
				AND MONTH_BEGIN = @NUM
				AND YEAR_BEGIN = @nYear 				

			INSERT INTO #RES1
			SELECT 
				LINK_EMPL, @NUM, 0, 0, 
				'', 'Итого', SUM(CASE WHEN ORDERS = 1 THEN SUM_PAY ELSE 0 END),
				'', '', SUM(CASE WHEN ORDERS between 2 and 5 THEN SUM_TAX ELSE 0 END),
				6,'',''
			FROM #RES1
			WHERE MON = @NUM
			GROUP BY LINK_EMPL				

			INSERT INTO #EMPLS1
			SELECT LINK_EMPL, @NUM FROM #T1 WHERE MON = @NUM AND WAY_CALC = 0
			UNION
			SELECT LINK_EMPL, @NUM FROM #T2 WHERE MON = @NUM AND WAY_CALC = 0 
			UNION
			SELECT s.LINK_EMPL, @NUM FROM #EMPLS E left join SAL_REMAIN s on s.LINK_EMPL = E.LINK_EMPL WHERE YEAR_SAL = @nYear
			UNION
			SELECT LINK_EMPL, @NUM FROM #RES1 WHERE MON = @NUM 
			
			INSERT INTO #REST_B1
			SELECT LINK_EMPL, @NUM,
				[BEG_PAY] = ISNULL((SELECT SUMMA FROM #T1 T1 WHERE MON = @NUM AND DF.LINK_EMPL = T1.LINK_EMPL AND T1.TYP_OPER = 1 AND T1.WAY_CALC = 0), 0.00),
				[BEG_TAX] = ISNULL((SELECT SUMMA FROM #T1 T1 WHERE MON = @NUM AND  DF.LINK_EMPL = T1.LINK_EMPL AND T1.TYP_OPER = 2 AND T1.WAY_CALC = 0), 0.00),
				[BEG_R] = ISNULL( (SELECT SUM(SUMMA) FROM SAL_REMAIN DSR WHERE YEAR_SAL = @nYear AND DSR.LINK_EMPL = DF.LINK_EMPL), 0.0),
				[END_PAY] = ISNULL((SELECT SUMMA FROM #T2 T1 WHERE MON = @NUM AND  DF.LINK_EMPL = T1.LINK_EMPL AND T1.TYP_OPER = 1 AND T1.WAY_CALC = 0), 0.00),
				[END_TAX] = ISNULL((SELECT SUMMA FROM #T2 T1 WHERE MON = @NUM AND  DF.LINK_EMPL = T1.LINK_EMPL AND T1.TYP_OPER = 2 AND T1.WAY_CALC = 0), 0.00)
			FROM #EMPLS1 DF
			WHERE MON = @NUM

			INSERT INTO #REST_B
			SELECT 
				LINK_EMPL, @NUM,
				BEG_PAY - BEG_TAX + BEG_R AS REST_BEG,
				END_PAY - END_TAX + BEG_R AS REST_D
			FROM #REST_B1
			WHERE MON = @NUM

			INSERT INTO #EMPLS2
			SELECT LINK_EMPL, @NUM FROM #REST_B WHERE MON = @NUM AND REST_BEG <> 0.00
			UNION
			SELECT LINK_EMPL, @NUM FROM #RES1 WHERE MON = @NUM

			INSERT INTO #SD_EMPL ([LINK], [MON], [FIO], [TAB], [SUBDIV_CODE], [post_name], [DATE_BEGIN], [DATE_END], [SACK], [NUM_STAKE])	
			SELECT LINK, @NUM,
					FIO = CASE WHEN ISNULL(@nCheck8,0) = 0 THEN FIO ELSE LEFT(LTRIM(RTRIM(ISNULL(LTRIM(RTRIM(E.FM)) + ' ' + LTRIM(RTRIM(E.IM)) + ' ' + LTRIM(RTRIM(E.OT)),'Не заполнено'))),100) END, 
					TAB, 
					SUBDIV_CODE = CASE WHEN ISNULL(@nCheck9,0) = 0 THEN SUBDIV_CODE ELSE LTRIM(RTRIM(SUBDIV_NAME)) END,
					post_name, DATE_BEGIN, DATE_END, SACK, NUM_STAKE = STAKE
			FROM dbo.SD_EMPL_FN(@PAR1,@DATE_01, DEFAULT, @DEP_LINK) E
						
			---
			INSERT INTO #EMPLS2
			SELECT LINK, @NUM
			FROM #SD_EMPL E 
				INNER JOIN #EMPLS O ON O.LINK_EMPL = E.LINK --Уже отобранные сотрудники
			WHERE 
				@nCheck5 = 1 
				AND (@Year * 100 + @NUM) BETWEEN (YEAR(DATE_BEGIN)*100 + MONTH(DATE_BEGIN)) AND COALESCE((YEAR(DATE_END)*100 + MONTH(DATE_END)), (@Year * 100 + @NUM))
				AND LINK NOT IN (SELECT LINK_EMPL FROM #EMPLS2)
				AND E.SACK = 0 --Не выводить уволенных	
			
			----
			EXEC DBO.GETRANDSTR 20, @BUF_ID OUT

			SET @SQL = '
			INSERT INTO DBO.BUFFER (ID, LINK)
			SELECT DISTINCT ''' + @BUF_ID + ''', LINK_EMPL FROM #EMPLS2'

			EXEC (@SQL)
			
			INSERT INTO #OKLAD (LINK_EMPL, MON, LINK_SOVM, SUMMA)
			SELECT LINK_EMPL, @NUM, LINK_SOVM, SUMMA FROM DBO.SA_OKLAD_EMPL_FN(@DATE_01,DEFAULT,0,@BUF_ID,@DEP_LINK)	

			SET @SQL = '
				DELETE FROM DBO.BUFFER WHERE ID = ''' + @BUF_ID + ''''
			EXEC (@SQL)

			----
			INSERT INTO #NORM_DAYS_TABLE (LINK_EMPL, MON, DAY_NORM)
			SELECT LINK_EMPL, @NUM, DAY_NORM FROM dbo.NORM_DAYS_TABLE(@NUM, @nYear)							
					
		END
	
		FETCH NEXT FROM @Cur1 INTO @NUM
	END
	
	CLOSE @Cur1
	DEALLOCATE @Cur1
	
	---
	SET @LINK_EMPL2 = CASE WHEN @nLinkEmpl > 0 THEN @nLinkEmpl ELSE -1 END

	CREATE TABLE #RES0 (
		[ID] INT IDENTITY,
		LINK_EMPL1 INT, FIO VARCHAR(254), TN VARCHAR(15), MON TINYINT, SUBDIV VARCHAR(254),POST VARCHAR(50),
		OKLAD NUMERIC(20,2), FWT INT,
		REST_BEG NUMERIC(20,2), REST_D NUMERIC(20,2),
		
		SUM_TOTAL NUMERIC(20,2), 
		DEDUCT NUMERIC(20,2), 	
		NDFL NUMERIC(20,2),	
		
		INSUR NUMERIC(20,2), 	
		GAIN NUMERIC(20,2),	
		NUM INT
	)

	----
	INSERT INTO #RES0(
		LINK_EMPL1, FIO, TN, MON, SUBDIV, POST,
		OKLAD, FWT,
		REST_BEG, REST_D,
		
		SUM_TOTAL, 
		DEDUCT, 	
		NDFL,	
		
		INSUR, 	
		GAIN,	
		NUM
	)
	SELECT 
		[LINK_EMPL] = EP.LINK,
		[FIO] = LTRIM(RTRIM(FIO)),
		[TN] = EP.TAB,
		EP.MON,
		[SUBDIV] =EP.subdiv_code,
		[POST] = convert(varchar(50),EP.post_name),
		[OKLAD] = O.SUMMA * EP.NUM_STAKE, --OKL.OKLAD,
		[FWT] = ND.DAY_NORM,
		[REST_BEG] = ISNULL(RB.REST_BEG, 0.00),
		[REST_D] = ISNULL(RB.REST_D, 0.00),
		[SUM_TOTAL] = ISNULL(T3.SUMMA, 0),
		[DEDUCT] = ISNULL((SELECT SUM(SUMMA) 
					FROM dbo.SAL_DED_MONTH 
					WHERE LINK_EMPL = EP.LINK AND YEAR(DATE_DED) = YEAR(@END_DATE)
					AND DATE_DED <= dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,EP.MON,convert(int,@nYear))) AND TYPE IN (1, 2)),0),
		[NDFL] = 
			ISNULL((SELECT SUM(SUMMA) FROM #T2 T1 WHERE EP.MON = T1.MON AND EP.LINK = T1.LINK_EMPL AND T1.TYP_OPER = 2 AND T1.WAY_CALC IN(4, 5, 6)), 0.00),
		[INSUR] = 
			ISNULL((SELECT SUM(SUMMA) FROM #T2 T1 WHERE EP.MON = T1.MON AND EP.LINK = T1.LINK_EMPL AND T1.TYP_OPER = 3 AND T1.WAY_CALC = 6), 0.00),
		[GAIN]  = 
			ISNULL((SELECT SUM(SUMMA) FROM #T2 T1 WHERE EP.MON = T1.MON AND EP.LINK = T1.LINK_EMPL AND T1.TYP_OPER = 3 AND T1.WAY_CALC = 7), 0.00),
		0
	FROM 
		#EMPLS2 E --отбор сотрудников
		INNER JOIN #SD_EMPL EP ON EP.LINK = E.LINK_EMPL AND EP.MON = E.MON	--сотрудники
		LEFT OUTER JOIN #REST_B RB ON EP.LINK = RB.LINK_EMPL AND EP.MON = RB.MON --Входящие остатки
		LEFT OUTER JOIN #T3 T3 ON EP.LINK = T3.LINK_EMPL AND EP.MON = T3.MON --доход с начала года
		LEFT JOIN #OKLAD O ON O.LINK_EMPL = EP.LINK AND EP.MON = O.MON
		LEFT JOIN #NORM_DAYS_TABLE ND ON EP.LINK = ND.LINK_EMPL AND EP.MON = ND.MON
	order by 
		 (CASE @nOption1 
			WHEN 1 THEN COALESCE(EP.TAB,'яяяяя') 
			WHEN 2 THEN COALESCE(EP.subdiv_code,'яяяяя') 
			WHEN 3 THEN COALESCE(EP.subdiv_code,'яяяяя')
			ELSE COALESCE(EP.FIO,'яяяяя')  
		END),
		 (CASE @nOption1 
			WHEN 2 THEN COALESCE(EP.TAB,'яяяяя') 
			WHEN 3 THEN COALESCE(EP.FIO,'яяяяя') 
			ELSE 'яяяяя'  
		END),
		EP.MON
		
	---
	UPDATE #RES0 SET NUM = CEILING(CAST([ID] AS FLOAT ) / 2.0)
	---

	IF @nCheck4  = 1
	BEGIN

		CREATE TABLE #VKR_EMPL_CUR (EMPL_LINK INT, MON TINYINT, VKR_ALL VARCHAR(400))
		DECLARE @EMPL_CUR CURSOR, @vkr_empl_link INT, @vkr_empl_MON INT

		SET @EMPL_CUR = CURSOR FAST_FORWARD FOR
			SELECT DISTINCT LINK_EMPL, MON FROM #RES1
		
		OPEN @EMPL_CUR
		FETCH NEXT FROM @EMPL_CUR INTO @vkr_empl_link, @vkr_empl_MON
		WHILE (@@FETCH_STATUS = 0)	
		BEGIN
			DECLARE @VKR_EMPL_CUR CURSOR
			SET @VKR_EMPL_CUR = CURSOR FAST_FORWARD FOR
				SELECT DISTINCT VKR_CODE, VKR_NAME FROM #RES1 WHERE LINK_EMPL = @vkr_empl_link AND MON = @vkr_empl_MON AND RTRIM(VKR_CODE)<>'' AND VKR_CODE IS NOT NULL
			
			DECLARE @VKR_ALL VARCHAR(400), @VKR_CODE VARCHAR(20), @VKR_NAME VARCHAR(120)
			SET @VKR_ALL = ''
			OPEN @VKR_EMPL_CUR
			FETCH NEXT FROM @VKR_EMPL_CUR INTO @VKR_CODE, @VKR_NAME
			WHILE (@@FETCH_STATUS = 0)
			BEGIN
				SET @VKR_ALL = @VKR_ALL + RTRIM(@VKR_CODE) + ' - '  + RTRIM(SUBSTRING(@VKR_NAME,1,30)) + ', ' + CHAR(10)
				FETCH NEXT FROM @VKR_EMPL_CUR INTO @VKR_CODE, @VKR_NAME
			END
			CLOSE @VKR_EMPL_CUR
			DEALLOCATE @VKR_EMPL_CUR

			IF LTRIM(RTRIM(COALESCE(@VKR_ALL,''))) <> ''
				SET @VKR_ALL = SUBSTRING(@VKR_ALL, 1, LEN(@VKR_ALL)-3)
			ELSE
				SET @VKR_ALL = ''
				
			INSERT #VKR_EMPL_CUR VALUES (@vkr_empl_link, @vkr_empl_MON, @VKR_ALL)
			FETCH NEXT FROM @EMPL_CUR INTO @vkr_empl_link, @vkr_empl_MON
		END
		CLOSE @EMPL_CUR
		DEALLOCATE @EMPL_CUR

		select 
			R0.ID, R0.LINK_EMPL1, R0.FIO, R0.TN, R0.MON, R0.SUBDIV, R0.POST, R0.OKLAD, R0.FWT, R0.REST_BEG, R0.REST_D, R0.SUM_TOTAL, R0.DEDUCT, R0.NDFL, R0.INSUR, R0.GAIN, R0.NUM,
			R1.LINK_EMPL, R1.DAYS, R1.PERC, R1.CODE_PAY, R1.NAME_PAY, R1.SUM_PAY, R1.CODE_TAX, R1.NAME_TAX, R1.SUM_TAX, R1.ORDERS, R1.VKR_CODE, R1.VKR_NAME,
			CONVERT(VARCHAR(300),VEC.VKR_ALL) AS VKR_ALL,
			CASE 
				WHEN ORDERS = 1 THEN NAME_PAY
				WHEN ORDERS = 2 THEN NAME_TAX
				WHEN ORDERS = 3 THEN Rtrim(NAME_TAX) + ' (Аванс)'
				WHEN ORDERS = 4 THEN Rtrim(NAME_TAX) + ' (Межрасч. выплаты)'
				WHEN ORDERS = 5 THEN Rtrim(NAME_TAX) + ' (Зарплата)'
				WHEN ORDERS = 6 THEN 'Итого'
				ELSE NAME_TAX
			END AS [NAME]
		from #RES0 R0 LEFT OUTER JOIN #RES1 R1 ON R0.MON = R1.MON AND R0.LINK_EMPL1 = R1.LINK_EMPL 
			LEFT JOIN #VKR_EMPL_CUR VEC ON R1.MON = VEC.MON AND R1.LINK_EMPL = VEC.EMPL_LINK
		ORDER BY
		 (CASE @nOption1 
			WHEN 1 THEN COALESCE(TN,'яяяяя') 
			WHEN 2 THEN COALESCE(subdiv,'яяяяя') 
			WHEN 3 THEN COALESCE(subdiv,'яяяяя')
			ELSE COALESCE(FIO,'яяяяя')  
		END),
		 (CASE @nOption1 
			WHEN 2 THEN COALESCE(TN,'яяяяя') 
			WHEN 3 THEN COALESCE(FIO,'яяяяя') 
			ELSE 'яяяяя'  
		END),
		R0.ID, R0.LINK_EMPL1, ORDERS, CODE_PAY, CODE_TAX

	END
	ELSE
	BEGIN
		select 
			R0.ID, R0.LINK_EMPL1, R0.FIO, R0.TN, R0.MON, R0.SUBDIV, R0.POST, R0.OKLAD, R0.FWT, R0.REST_BEG, R0.REST_D, R0.SUM_TOTAL, R0.DEDUCT, R0.NDFL, R0.INSUR, R0.GAIN, R0.NUM,
			R1.LINK_EMPL, R1.DAYS, R1.PERC, R1.CODE_PAY, R1.NAME_PAY, R1.SUM_PAY, R1.CODE_TAX, R1.NAME_TAX, R1.SUM_TAX, R1.ORDERS, R1.VKR_CODE, R1.VKR_NAME,
			'' as VKR_ALL,
			CASE 
				WHEN ORDERS = 1 THEN NAME_PAY
				WHEN ORDERS = 2 THEN NAME_TAX
				WHEN ORDERS = 3 THEN Rtrim(NAME_TAX) + ' (Аванс)'
				WHEN ORDERS = 4 THEN Rtrim(NAME_TAX) + ' (Межрасч. выплаты)'
				WHEN ORDERS = 5 THEN Rtrim(NAME_TAX) + ' (Зарплата)'
				WHEN ORDERS = 6 THEN 'Итого'
				ELSE NAME_TAX
			END AS [NAME]
		from #RES0 R0 LEFT OUTER JOIN #RES1 R1 ON R0.MON = R1.MON AND R0.LINK_EMPL1 = R1.LINK_EMPL
		ORDER BY
		 (CASE @nOption1 
			WHEN 1 THEN COALESCE(TN,'яяяяя') 
			WHEN 2 THEN COALESCE(subdiv,'яяяяя') 
			WHEN 3 THEN COALESCE(subdiv,'яяяяя')
			ELSE COALESCE(FIO,'яяяяя')  
		END),
		 (CASE @nOption1 
			WHEN 2 THEN COALESCE(TN,'яяяяя') 
			WHEN 3 THEN COALESCE(FIO,'яяяяя') 
			ELSE 'яяяяя'  
		END),
		R0.ID, R0.LINK_EMPL1, ORDERS, CODE_PAY, CODE_TAX

	END
END

GO


GRANT EXECUTE ON dbo.[SD_REP_RL] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_REP_RL_ONE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_REP_RL_ONE]

GO

CREATE     PROCEDURE dbo.SA_REP_RL_ONE
	@varKScYear VARCHAR(4),
	@varKSnMonth INT,
	@varKScVal1 CHAR(1), @varKSnOtborLink1 int,	
	@varKSnOption1 int,
	@nCheck3 int,	/* Разделять Б/Л за счет ФСС и работодателя */
	@nLinkEmpl int = 0,
	@nCheckIST INT = 0,
	@nCheck5 int = 0, /* Печатать пустые р/л*/
	@nCheck7 int = 0, /* Отображать разряд */
	@varKScVal2 CHAR(1) = '', @varKSnOtborLink2 int = 0,
	@nCheck8 int = 0 /* Выводить Ф.И.О. полностью */,
	@nCheck9 int = 0 , /* Выводить наименование отдела вместо кода */
	@nCheck10 int = 0  /* Формировать р/л за каждый месяц с начала года по выбранный месяц */
as

create table #date (
ID int, 
LINK_EMPL1 int, 
FIO  VARCHAR(254), 
TN VARCHAR(15), 
MON TINYINT,
SUBDIV VARCHAR(254), 
POST VARCHAR(50), 
OKLAD NUMERIC(20,2), 
FWT INT, 
REST_BEG NUMERIC(20,2), 
REST_D NUMERIC(20,2), 
SUM_TOTAL NUMERIC(20,2), 
DEDUCT NUMERIC(20,2), 
NDFL NUMERIC(20,2), 
INSUR NUMERIC(20,2), 
GAIN NUMERIC(20,2), 
NUM int, 
LINK_EMPL int, 
DAYS numeric (15,2), 
PERC numeric (15,2),
CODE_PAY VARCHAR(20), 
NAME_PAY VARCHAR(254), 
SUM_PAY NUMERIC(20,2), 
CODE_TAX VARCHAR(20), 
NAME_TAX VARCHAR(254), 
SUM_TAX NUMERIC(20,2), 
ORDERS TINYINT, 
VKR_CODE VARCHAR(20),
VKR_NAME VARCHAR(120),
VKR_ALL VARCHAR(300),
NAME  VARCHAR(254)
)

set nocount on

insert into #date
EXEC dbo.SD_REP_RL
	@varKScYear,
	@varKSnMonth,
	@varKScVal1, 
	@varKSnOtborLink1,
	@varKSnOption1,
	@nCheck3,
 	@nLinkEmpl,
	@nCheckIST,
	@nCheck5,
	@nCheck7,
	@varKScVal2, @varKSnOtborLink2,
	@nCheck8,
	@nCheck9, /* Выводить наименование отдела вместо кода */
	@nCheck10 /* Формировать р/л за каждый месяц с начала года по выбранный месяц */

update #date
Set num = CEILING(CAST([ID] AS FLOAT ) / 4.0) /*4 штуки на листке*/

/*Условно разделим на 2 части и подравняем длинну двух соседних листочков*/

declare @Cursor Cursor
Set @cursor = cursor forward_only
for 
	Select distinct 
	lid= D.id,
	lcnt= (select count(id) from  #date D1 where d1.id = d.id),
	rid = D.id + 1 ,
	rcnt= (select count(id) from  #date D1 where d1.id = d.id + 1)
from #date D where id % 2 = 1

declare @lid int, @lcnt int, @rid int, @rcnt int, @i int

open @cursor
fetch next  from @Cursor  into @lid, @lcnt, @rid, @rcnt
while (@@fetch_status <> -1)
begin
	if (@@fetch_status <> 2)
	begin	
		Set @i = abs (@lcnt - @rcnt)
		while @i > 0
		begin	
			insert into #date (id, LINK_EMPL1, FIO, TN,  MON, SUBDIV, POST, OKLAD, FWT, REST_BEG, REST_D, SUM_TOTAL, DEDUCT, NDFL, INSUR, GAIN, NUM, ORDERS, VKR_ALL)
			Select top 1 id, LINK_EMPL1, FIO, TN, MON, SUBDIV, POST, OKLAD, FWT, REST_BEG, REST_D, SUM_TOTAL, DEDUCT, NDFL, INSUR, GAIN, NUM,  21, VKR_ALL
				from #date where id = (case when @lcnt < @rcnt then @lid else @rid end)

			Set @i = @i - 1
		end
	end
	fetch next  from @Cursor  into @lid, @lcnt, @rid, @rcnt
end
close @cursor
deallocate @cursor

/*Листочек на левой стороне*/
Select link = identity(int,1,1), *
into #left
from #date D where id % 2 = 1
order by id, ORDERS, CODE_PAY

/*Листочек на правой стороне*/
Select link = identity(int,1,1), 
	rID= ID, rLINK_EMPL1 = LINK_EMPL1, rFIO = FIO, rTN = TN, rMON = MON, rSUBDIV = SUBDIV, 
	rPOST = POST, rOKLAD = OKLAD, rFWT = FWT, rREST_BEG = REST_BEG, rREST_D = REST_D, 
	rSUM_TOTAL = SUM_TOTAL, rDEDUCT = DEDUCT, rNDFL = NDFL, rINSUR = INSUR, rGAIN = GAIN, 
	rNUM = NUM, rLINK_EMPL = LINK_EMPL, rDAYS = DAYS, rPERC = PERC, rCODE_PAY = CODE_PAY, 
	rNAME_PAY = NAME_PAY, rSUM_PAY = SUM_PAY, rCODE_TAX = CODE_TAX, rNAME_TAX = NAME_TAX, 
	rSUM_TAX = SUM_TAX, rORDERS = ORDERS, rVKR_CODE = VKR_CODE, rVKR_NAME = VKR_NAME, rVKR_ALL = VKR_ALL, rNAME = NAME
into #right
from #date D where id % 2 = 0
order by id, ORDERS, CODE_PAY

set nocount off

select * 
from #left L left join #right R on L.link = R.link
order by id, ORDERS, CODE_PAY


return 0

GO

GRANT EXECUTE ON dbo.[SA_REP_RL_ONE] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_EMPL_INCOM_VKR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_EMPL_INCOM_VKR]

GO

CREATE  PROCEDURE dbo.SA_EMPL_INCOM_VKR

	@varKSnMode	smallint	= 0, 
	@varKSnMonth 	int		= 0,
	@varKSnYear	int		= 0,
	@DEP_LINK INT = NULL,
	@REF_PAY INT = NULL
AS

/*
&& Процедура выводит сотрудников имеющих доход в заданном периоде
&& nMode	smallint,  0 - в заданном периоде, 1 - с начала года до заданного периода
&& nMONTH	int,
&& nYEAR	int
*/

IF @DEP_LINK IS NULL
	exec dbo.xd_whats_zb @DEP_LINK output


DECLARE @RESIDENT TINYINT

IF EXISTS (SELECT * FROM dbo.PAYS WHERE LINK = @REF_PAY AND WAY_CALC = 5)
	SET @RESIDENT = 1
ELSE
	IF EXISTS (SELECT * FROM dbo.PAYS WHERE LINK = @REF_PAY AND WAY_CALC = 4)
		SET @RESIDENT = 2
	ELSE
		SET @RESIDENT = NULL	

declare @date datetime
if coalesce(@varKSnMonth,0) = 0 or Coalesce(@varKSnYear,0) = 0
	set @date = dbo.salarycalcperiod()
else
	set @date = dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@varKSnMonth,@varKSnYear))

select distinct 
	LINK= e.PERS_LINK,
	LINK_EMPL= e.link,
	TAB_NUM= e.tab,
	[NAME_EMPL]= LTRIM(RTRIM(e.FM)) + ' ' + SUBSTRING(LTRIM(RTRIM(e.IM)),1,1) + '.' + SUBSTRING(LTRIM(RTRIM(e.OT)),1,1),
	sj.LINK_VKR, KBK.CODE AS NAME_VKR,
	sj.link_ekr, EKR.CODE as NAME_EKR,
	Status= e.status_empl		
from
	dbo.sd_empl_fn(default,@date,DEFAULT,@DEP_LINK) e 
		inner join dbo.S_J_C_Short SJ on e.link = SJ.link_empl 
		inner join dbo.SAL_SFIN KBK on KBK.link = SJ.LINK_VKR
		inner join dbo.DICTIONARY_ITEM EKR on EKR.link = SJ.link_ekr
where
	(@RESIDENT IS NULL OR @RESIDENT = 2 AND E.RESIDENT = 2 OR @RESIDENT = 1 AND E.RESIDENT <> 2)
	AND SJ.TYP_OPER = 1 
	and year_begin = @varKSnYear 
	and (
		(month_begin <= @varKSnMonth and @varKSnMode = 1) 
		or 
		(month_begin = @varKSnMonth and @varKSnMode = 0)
	)
	AND E.DEP_LINK = @DEP_LINK
ORDER BY
	NAME_EMPL, KBK.CODE, EKR.CODE

GO


GRANT EXECUTE ON dbo.[SA_EMPL_INCOM_VKR] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_VM1]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_VM1]

GO

--	ВЕДОМОСТЬ ДВИЖЕНИЯ ПО СУБСЧЕТУ --
CREATE PROCEDURE dbo.BK_REPORT_VM1
	@dDateB1 datetime,	-- Начало расч. периода --
	@dDateE1 datetime,	-- Конец расч. периода --
	@intLink_Acct	INT,	-- СУБСЧЕТ --
	@intPRINT_KBK	int,	-- Отображать КБК --
	@intPRINT_SGU	int,	-- Отображать СГУ --
	@cVal_KBK char(1), @nOtborLinkKBK int,	-- Отбор КБК --
	@intSVOD_ZB INT,
	@cVal_Dep char(1), @nOtborLinkDEP int,	-- Отбор учреждений --
	@cVal_Emp char(1), @nOtborLinkEMP int,	-- Отбор сотрудников --
	@cVal_KAU char(1), @nOtborLinkKAU int,	-- Отбор КАУ --
	@cVal_DOP_CL char(1), @nOtborLinkDOP_CL int,	-- Отбор доп. кл-ции --
	@strAP_CODE	VARCHAR (60) = '',
	@grpAP	INT = 0,
	@grpKBK	INT = 0,
	@grpREST INT = 0
AS
BEGIN
	DECLARE
		@intLINK_DEP	INT,
		@cDEP_CODE	VARCHAR (20),
		@cDEP_NAME	VARCHAR (254),
		@strTITLE	VARCHAR (20),
		@dDATE_NEXT	DATETIME,
		@iKBK_REST	TINYINT,
		@iAP_REST	TINYINT

	SELECT @grpKBK = ISNULL (@grpKBK, 0)
	SELECT @grpAP = ISNULL (@grpAP, 0)

	--- ОТБОР КБК --- 
	DECLARE @T_KBK TABLE (LINK	INT)
	IF LEN (@cVal_KBK) > 0
		INSERT INTO @T_KBK
		SELECT
			OVR.RECORD
		FROM dbo.OBJECT_VAR_KBK OVR 
		WHERE OVR.LINK_UP = @nOtborLinkKBK
	ELSE
		SET @nOtborLinkKBK = 0

	--- ОТБОР ДОП. КЛ-ЦИИ --- 
	DECLARE @T_AP2 TABLE (LINK	INT)
	IF LEN (@cVal_DOP_CL) > 0
		INSERT INTO @T_AP2
		SELECT
			OVR.RECORD
		FROM dbo.OBJECT_VAR_DOP_CLASSIF OVR 
		WHERE OVR.LINK_UP = @nOtborLinkDOP_CL
	ELSE
		SET @nOtborLinkDOP_CL = 0

	--- ОТБОР ПОКАЗАТЕЛЕЙ ---
	DECLARE @T_AP0 TABLE
		(LINK [INT],
		CODE  [VARCHAR] (20),
		NAME [VARCHAR] (254))
		
	INSERT INTO @T_AP0
	SELECT
		T1.LINK_AP,
		T1.AP_CODE,
		T1.AP_NAME
	FROM dbo.BK_GetTableDictionByAP (@strAP_CODE) T1

--	SELECT * FROM @T_AP0

	--- Отбор учреждений --- 
	DECLARE @T_DEP TABLE (LINK	INT)
	
	IF LEN(@cVal_Dep)>0
		INSERT INTO @T_DEP
		SELECT
			OVR.RECORD
		FROM dbo.OBJECT_VAR_DEPARTMENT OVR
		WHERE OVR.LINK_UP = @nOtborLinkDEP
	ELSE
		SET @nOtborLinkDEP = 0

	--- Отбор сотрудников --- 
	DECLARE @T_EMP TABLE (LINK	INT)

	IF LEN (@cVal_Emp) > 0 
		INSERT INTO @T_EMP
		SELECT
			OVR.RECORD
		FROM dbo.OBJECT_VAR_EMPL OVR
		WHERE OVR.LINK_UP = @nOtborLinkEMP
	ELSE
		SET @nOtborLinkEMP = 0

	--- Отбор КАУ --- 
	DECLARE @T_KAU TABLE (LINK	INT)

	IF LEN (@cVal_KAU) > 0 
		INSERT INTO @T_KAU
		SELECT
			OVR.RECORD
		FROM dbo.OBJECT_VAR_KAU OVR
		WHERE OVR.LINK_UP = @nOtborLinkKAU
	ELSE
		SET @nOtborLinkKAU = 0

	--- Заглушка, если не выбран показатель --- 
	SET @strAP_CODE = ISNULL (@strAP_CODE, '')
	IF @strAP_CODE = '' AND NOT EXISTS (SELECT * FROM @T_AP0)
		INSERT INTO @T_AP0
		VALUES (0, '', '')

	-- Параметры организации -- 
	SET @intSVOD_ZB = ISNULL (@intSVOD_ZB, 0)
	SET @intLINK_DEP = dbo.BK_GetDepZB ()

	IF @intSVOD_ZB = 1 OR @intLINK_DEP IS NULL
		SET @intLINK_DEP = dbo.GetOwnDepLink()

	SELECT
		@intLINK_DEP = LINK,
		@cDEP_CODE = CODE,
		@cDEP_NAME = [NAME]
	FROM dbo.DICTIONARY_DEPARTMENT
	WHERE LINK = @intLINK_DEP

	IF @intSVOD_ZB = 1
		SET @cDEP_NAME = RTRIM (@cDEP_NAME) + ' (ЦБ)'

	-- Документы --
	DECLARE @T_DOCUMENTS TABLE
		(LINK	INT IDENTITY (1, 1),
		LINK_DOC INT,
		DOC_DATE DATETIME,
		DOC_NUM VARCHAR (30), DOC_NAME VARCHAR (254),
		ACCOUNT	INT,
		AP0 INT,
		KBK	INT, 
		AP2	INT, 
		ACCT_KOR VARCHAR (60),
		D_QTY NUMERIC (28,4) DEFAULT (0), D_SUMMA NUMERIC (28,4) DEFAULT (0),
		K_QTY NUMERIC (28,4) DEFAULT (0), K_SUMMA NUMERIC (28,4) DEFAULT (0),
		DIN_QTY NUMERIC (28,4) DEFAULT (0), DIN_SUM NUMERIC (28,4) DEFAULT (0),
		KIN_QTY NUMERIC (28,4) DEFAULT (0), KIN_SUM NUMERIC (28,4) DEFAULT (0),
		DOUT_QTY NUMERIC (28,4) DEFAULT (0), DOUT_SUM NUMERIC (28,4) DEFAULT (0),
		KOUT_QTY NUMERIC (28,4) DEFAULT (0), KOUT_SUM NUMERIC (28,4) DEFAULT (0),
		DEP_LINK INT
		)

	--SELECT * FROM dbo.BK_GetTableOborotByDate1 (@dDateB1, @dDateE1, DEFAULT, @intLink_Acct, DEFAULT) T1

	INSERT INTO @T_DOCUMENTS
		(
		LINK_DOC,
		DOC_DATE,
		DOC_NUM,
		DOC_NAME,
		ACCOUNT,
		AP0,
		KBK, 
		AP2, 
		ACCT_KOR,
		D_QTY, D_SUMMA,
		K_QTY, K_SUMMA,
		DEP_LINK
		)

	SELECT
		T1.LINK_DOC,
		G.[DATE],
		G.NUMBER,
		dbo.JurnalProvGetDocKind (G.LINK, G.[OBJECT]),
		T1.ACCOUNT,
		CASE
			WHEN @strAP_CODE = 'DEP' THEN ISNULL (T1.DEP, 0)
			WHEN @strAP_CODE = 'EMP' THEN ISNULL (T1.EMP, 0)
			WHEN @strAP_CODE = 'KAU' THEN ISNULL (T1.KAU, 0)
			ELSE 0
		END,
		T1.KBK,
		T1.AP2,
		dbo.BK_GetAcctFullCode1 (GAP1.ACCOUNT, GAP1.KBK, GAP1.SGU, @intPRINT_KBK, @intPRINT_SGU),
		CASE 
			WHEN T1.DB_KR = 0 AND SA1.KSU = 1 THEN T1.QTY
			ELSE 0
		END,
		CASE 
			WHEN T1.DB_KR = 0 THEN T1.SUMMA
			ELSE 0
		END,
		CASE 
			WHEN T1.DB_KR = 1 AND SA1.KSU = 1 THEN T1.QTY
			ELSE 0
		END,
		CASE 
			WHEN T1.DB_KR = 1 THEN T1.SUMMA
			ELSE 0
		END,
		T1.DEP_LINK	
	FROM dbo.BK_GetTableOborotByDate1 (@dDateB1, @dDateE1, DEFAULT, @intLink_Acct, DEFAULT) T1
	INNER JOIN dbo.G_PROV G ON (G.LINK = T1.LINK_DOC)
	LEFT JOIN dbo.G_PROV_AP GAP1 ON (GAP1.LINK_UP = T1.LINK_G2
		AND (T1.DB_KR = 0 AND GAP1.DB_KR = 1
			OR T1.DB_KR = 1 AND GAP1.DB_KR = 0))
	INNER JOIN dbo.S_ACCOUNTS SA1 ON (SA1.LINK = T1.ACCOUNT)
	WHERE (@intSVOD_ZB = 1 
			OR @intSVOD_ZB = 0 AND T1.DEP_LINK = @intLINK_DEP)
		AND (@nOtborLinkKBK = 0
			OR @nOtborLinkKBK > 0 AND EXISTS (SELECT * FROM @T_KBK TTT WHERE TTT.LINK = T1.KBK))
		AND (@nOtborLinkDOP_CL = 0
			OR @nOtborLinkDOP_CL > 0 AND EXISTS (SELECT * FROM @T_AP2 TTT WHERE TTT.LINK = T1.AP2))
		AND (@nOtborLinkDEP = 0
			OR @nOtborLinkDEP > 0 AND EXISTS (SELECT * FROM @T_DEP TTT WHERE TTT.LINK = T1.DEP))
		AND (@nOtborLinkEMP = 0
			OR @nOtborLinkEMP > 0 AND EXISTS (SELECT * FROM @T_EMP TTT WHERE TTT.LINK = T1.EMP))
		AND (@nOtborLinkKAU = 0
			OR @nOtborLinkKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = T1.KAU))

	SELECT @strTITLE = CASE
							WHEN @strAP_CODE = 'EMP' THEN 'Сотрудник: '
							WHEN @strAP_CODE = 'DEP' THEN 'Учр.: '
							WHEN @strAP_CODE = 'KAU' THEN 'КАУ: '
							ELSE ''
						END

	-- Остатки --
	SET @dDATE_NEXT = DATEADD (DAY, 1, @dDateE1)
		
	DECLARE @T_REST TABLE
		(
		ACCOUNT	INT,
		AP0 INT,
		KBK	INT, 
		AP2	INT, 
		DIN_QTY NUMERIC (28,4), DIN_SUM NUMERIC (28,4),
		KIN_QTY NUMERIC (28,4), KIN_SUM NUMERIC (28,4),
		DOUT_QTY NUMERIC (28,4), DOUT_SUM NUMERIC (28,4),
		KOUT_QTY NUMERIC (28,4), KOUT_SUM NUMERIC (28,4),
		DEP_LINK INT
		)

	INSERT INTO @T_DOCUMENTS
		(LINK_DOC,
		ACCOUNT,
		AP0,
		KBK,
		AP2,
		DEP_LINK,
		DIN_QTY, DIN_SUM,
		KIN_QTY, KIN_SUM,
		DOUT_QTY, DOUT_SUM,
		KOUT_QTY, KOUT_SUM
		)

	SELECT
		0,
		T1.ACCOUNT,
		T1.AP0,
		T1.KBK,
		T1.AP2,
		T1.DEP_LINK,
		SUM (ISNULL (R1.D_QTY, 0)), SUM (ISNULL (R1.D_SUMMA, 0)),
		SUM (ISNULL (R1.K_QTY, 0)), SUM (ISNULL (R1.K_SUMMA, 0)),
		SUM (ISNULL (R2.D_QTY, 0)), SUM (ISNULL (R2.D_SUMMA, 0)),
		SUM (ISNULL (R2.K_QTY, 0)), SUM (ISNULL (R2.K_SUMMA, 0))
	FROM (
		SELECT 
			TTT.ACCOUNT,
			TTT.AP0,
			TTT.KBK,
			TTT.AP2,
			TTT.DEP_LINK
		FROM @T_DOCUMENTS TTT
		GROUP BY
			TTT.ACCOUNT,
			TTT.AP0,
			TTT.KBK,
			TTT.AP2,
			TTT.DEP_LINK
		)	AS T1
	LEFT JOIN (
		SELECT
			R.ACCOUNT,
			CASE
				WHEN @strAP_CODE = 'DEP' THEN ISNULL (R.DEP, 0)
				WHEN @strAP_CODE = 'EMP' THEN ISNULL (R.EMP, 0)
				WHEN @strAP_CODE = 'KAU' THEN ISNULL (R.KAU, 0)
				ELSE 0
			END AS AP0,
			ISNULL (R.KBK, 0) AS KBK,
			ISNULL (R.AP2, 0) AS AP2,
			R.D_QUANTITY AS D_QTY,
			R.K_QUANTITY AS K_QTY,
			R.D_SUMMA,
			R.K_SUMMA,
			R.DEP_LINK
		FROM dbo.ARestTableByDate (@dDateB1, @intLink_Acct) R) AS R1 ON
				(
				R1.ACCOUNT = T1.ACCOUNT
				AND R1.AP0 = T1.AP0
				AND R1.KBK = T1.KBK
				AND R1.AP2 = T1.AP2
				AND R1.DEP_LINK = T1.DEP_LINK
				)
	LEFT JOIN (
		SELECT
			R.ACCOUNT,
			CASE
				WHEN @strAP_CODE = 'DEP' THEN ISNULL (R.DEP, 0)
				WHEN @strAP_CODE = 'EMP' THEN ISNULL (R.EMP, 0)
				WHEN @strAP_CODE = 'KAU' THEN ISNULL (R.KAU, 0)
				ELSE 0
			END AS AP0,
			ISNULL (R.KBK, 0) AS KBK,
			ISNULL (R.AP2, 0) AS AP2,
			R.D_QUANTITY AS D_QTY,
			R.K_QUANTITY AS K_QTY,
			R.D_SUMMA,
			R.K_SUMMA,
			R.DEP_LINK
		FROM dbo.ARestTableByDate (@dDATE_NEXT, @intLink_Acct) R) AS R2 ON
				(
				R2.ACCOUNT = T1.ACCOUNT
				AND R2.AP0 = T1.AP0
				AND R2.KBK = T1.KBK
				AND R2.AP2 = T1.AP2
				AND R2.DEP_LINK = T1.DEP_LINK
				)
	GROUP BY
		T1.ACCOUNT,
		T1.AP0,
		T1.KBK,
		T1.AP2,
		T1.DEP_LINK
	HAVING
		SUM (ISNULL (R1.D_QTY, 0)) <> 0 OR SUM (ISNULL (R1.D_SUMMA, 0)) <> 0
		OR SUM (ISNULL (R1.K_QTY, 0)) <> 0 OR SUM (ISNULL (R1.K_SUMMA, 0)) <> 0
		OR SUM (ISNULL (R2.D_QTY, 0))<> 0 OR SUM (ISNULL (R2.D_SUMMA, 0)) <> 0
		OR SUM (ISNULL (R2.K_QTY, 0))<> 0 OR SUM (ISNULL (R2.K_SUMMA, 0)) <> 0

			
 -- SELECT '@T_DOCUMENTS1', * FROM @T_DOCUMENTS
	SELECT
		@iKBK_REST	=	CASE
							WHEN ISNULL (@grpKBK, 0) = 1 AND ISNULL (@grpREST, 0) = 1 THEN 1
							ELSE 0
						END,	
		@iAP_REST	=	CASE
							WHEN ISNULL (@grpAP, 0) = 1 AND ISNULL (@grpREST, 0) = 1 THEN 1
							ELSE 0
						END	

	SELECT
		T1.*,
		@strTITLE AS AP_TITLE,
		@dDATE_NEXT AS DATE_NEXT,
		@cDEP_NAME AS DEP_NAME,
		SA.CODE AS ACCT_CODE,
		KBK.CODE AS KBK_CODE,
		AP0.CODE AS AP_CODE,
		AP0.NAME AS AP_NAME,
		ISNULL (RTRIM (AP0.NAME), '') + '(' + ISNULL (RTRIM (AP0.CODE), '') + ')' AS AP_NAME1,	
		AP2.CODE AS DOP_CODE,
		@iKBK_REST AS KBK_REST,
		@iAP_REST AS AP_REST
	FROM @T_DOCUMENTS T1
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = T1.ACCOUNT)
	LEFT JOIN dbo.KL_KBK KBK ON (KBK.LINK = T1.KBK)
	LEFT JOIN dbo.DOP_CLASSIF AP2 ON (AP2.LINK = T1.AP2)
	LEFT JOIN @T_AP0 AP0 ON (AP0.LINK = T1.AP0)
	ORDER BY
		SA.CODE,
		KBK.CODE,
		T1.KBK,
		AP0.NAME,
		T1.AP0,
		T1.DOC_DATE,
		T1.DOC_NAME,
		T1.DOC_NUM

END

GO

GRANT EXECUTE ON dbo.[BK_REPORT_VM1] TO PUBLIC

GO

--Расширенные свойства--

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_BOOK_SALES_PURCHASE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_BOOK_SALES_PURCHASE]

GO


/*
© Кейсистемс (Keysystems), 2005
*/
CREATE  PROCEDURE dbo.BK_REPORT_BOOK_SALES_PURCHASE
	@varKSdDate_1 datetime,
	@varKSdDate_2 DATETIME,
	@varKSnOption1 int,	-- 1 - Книга покупок (Полученные счета-фактуры)
				-- 2 - Книга продаж (Выданные счета-фактуры) -- 
	@intSVOD_ZB	int,	-- Сводный отчет (ЦБ) 
	@cVal_SFIN char(1), @nOtborLinkSFIN int	-- Отбор источников финансирования --
AS
BEGIN
	DECLARE
		@intDEP_LINK	INT,
		@strHD_Org_Name VARCHAR (254),
		@strHD_PUR_INN VARCHAR (20),
		@strHD_PUR_KPP VARCHAR (20)

	-- Источник в выборе начинается с пустого значения --
	-- Отбор источников финансирования --
	DECLARE @TAB_SFIN TABLE
		(LINK	INT,
		CODE CHAR (2))

	IF LEN (@cVal_SFIN) > 0 
	BEGIN
		INSERT INTO @TAB_SFIN
		SELECT D.LINK,
			D.CODE
		FROM dbo.OBJECT_VAR_FIN_SOURCE OVR
		INNER JOIN dbo.FIN_SOURCE D ON (D.LINK = OVR.RECORD)
		WHERE OVR.LINK_UP = @nOtborLinkSFIN
	END
	ELSE
	BEGIN
		INSERT INTO @TAB_SFIN
		SELECT D.LINK,
			D.CODE
		FROM dbo.FIN_SOURCE D 

		INSERT INTO @TAB_SFIN (LINK, CODE) 
		SELECT 0, ''
	END

	-- Шапка документа --
	DECLARE @TAB1 TABLE
		(LINK_DOC INT,
		DEP1 INT,
		TOTAL_SUM NUMERIC (28,4),
		
		-- Реквизиты с\ф --
		DOC_DATE1 DATETIME,
		DOC_NUM1 VARCHAR (50),

		-- Исправление с\ф --
		DOC_DATE2 DATETIME,
		DOC_NUM2 VARCHAR (50),

		-- Реквизиты коррект. с\ф --
		COR_DATE1	DATETIME,
		COR_NUM1	VARCHAR (50),

		-- Исправление коррект. с\ф --
		COR_DATE2	DATETIME,
		COR_NUM2	VARCHAR (50),

		DATE_OPL DATETIME,
		SORT_NUM VARCHAR (50),

		IS_COR	TINYINT		-- Корректир. с\ф	0 - с\ф, 1 - получ. с\ф, 2 - выст. с\ф
		)

	-- НДС 18% --
	DECLARE @TAB2_18 TABLE
		(LINK_DOC INT,
		NALOG NUMERIC (28,4),
		SUMMA NUMERIC (28,4),
		SFIN_LINK INT)

	-- НДС 10% --
	DECLARE @TAB2_10 TABLE
		(LINK_DOC INT,
		NALOG NUMERIC (28,4),
		SUMMA NUMERIC (28,4),
		SFIN_LINK INT)

	-- НДС 0% --
	DECLARE @TAB2_0 TABLE
		(LINK_DOC INT,
		SUMMA NUMERIC (28,4),
		SFIN_LINK INT)

	-- НДС 20% --
	DECLARE @TAB2_20 TABLE
		(LINK_DOC INT,
		NALOG NUMERIC (28,4),
		SUMMA NUMERIC (28,4),
		SFIN_LINK INT)

	-- БЕЗ НДС % --
	DECLARE @TAB2_NO_NDS TABLE
		(LINK_DOC INT,
		SUMMA NUMERIC (28,4),
		SFIN_LINK INT)

	-- Итоговая сумма по документу --
	DECLARE @TAB_DOC_SUM TABLE
		(LINK_DOC INT,
		SUMMA_ALL NUMERIC (28,4))
	
	--- Сводный отчет (ЦБ) --- 
	SET @intSVOD_ZB = ISNULL (@intSVOD_ZB, 0)
	SET @intDEP_LINK = ISNULL (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())

	IF @intSVOD_ZB = 1
		SET @intDEP_LINK = dbo.GetOwnDepLink ()

	SELECT	@strHD_Org_Name = [NAME],
		@strHD_PUR_INN = INN,
		@strHD_PUR_KPP = KPP
	FROM dbo.DICTIONARY_DEPARTMENT
	WHERE LINK = @intDEP_LINK

	SELECT @strHD_Org_Name = ISNULL (@strHD_Org_Name, ''),
		@strHD_PUR_INN = ISNULL (@strHD_PUR_INN, ''),
		@strHD_PUR_KPP = ISNULL (@strHD_PUR_KPP, '')

	IF @intSVOD_ZB = 1
		SET @strHD_Org_Name = RTRIM (@strHD_Org_Name) + '(ЦБ)'

	IF @varKSnOption1 = 1		-- Книга покупок (Полученные счета-фактуры) --
		INSERT INTO @TAB1	-- Отбор всех полученных с/ф за период --
		SELECT DOC.LINK,
			DOC.SEL_LINK,	-- ПРОДАВЕЦ --
			DOC.SUMMA,
			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE,
			DOC.COR_NUM,

			NULL,
			'',
			NULL,
			'',

			DOC.DATE_BASE,
			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			0
		FROM dbo.DOCUMENTS_INVOICE_RECEIVED DOC
		INNER JOIN dbo.DEPARTMENTS DEP ON ((DEP.ZB = 1 OR DEP.[TYPE] = 4)
						AND DEP.LINK = DOC.DEP_LINK)
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND DOC.BOOK_PUR = CONVERT (BIT, 1)
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)
	

	IF @varKSnOption1 = 2		-- Книга продаж (Выданные счета-фактуры) --
		INSERT INTO @TAB1	-- Отбор всех выданных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.BUY_LINK,	-- ПОКУПАТЕЛЬ --
			DOC.SUMMA,
			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE,
			DOC.COR_NUM,

			NULL,
			'',
			NULL,
			'',

			DOC.DATE_BASE,
			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			0
		FROM dbo.DOCUMENTS_INVOICE_ISSUED DOC
		INNER JOIN dbo.DEPARTMENTS DEP ON ((DEP.ZB = 1 OR DEP.[TYPE] = 4)
						AND DEP.LINK = DOC.DEP_LINK)
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)
			AND DOC.BOOK_SALES = CONVERT (BIT, 1)

	-- НАЛОГОВЫЕ СТАВКИ --
	DECLARE @TABLE_NDS TABLE
		(LINK_UP	INT,
		SUMMA_ALL	NUMERIC (28,4),
		SUMMA_NDS	NUMERIC (28,4),
		SUMMA		NUMERIC (28,4),
		FS_LINK		INT,
		FS_CODE		VARCHAR (2),
		NO_NDS		TINYINT,
		STAVKA_NDS	NUMERIC (5,2),
		NDS_CODE	VARCHAR (3))

	INSERT INTO @TABLE_NDS
	SELECT
		T1.LINK_UP,
		T1.SUMMA_ALL,
		T1.SUMMA_NDS,
		T1.SUMMA,
		ISNULL (T1.FS_LINK, 0),
		ISNULL (T1.FS_CODE, ''),
		T1.NO_NDS, 
		T1.STAVKA_NDS,
		ISNULL (T1.TNDS_CODE, '')
	FROM dbo.BK_DOC_TABLE_MZ_NDS_FN (DEFAULT) T1
	INNER JOIN @TAB1 T0 ON (T0.LINK_DOC = T1.LINK_UP)
	INNER JOIN @TAB_SFIN T3 ON (T3.LINK = T1.FS_LINK)

	-- 18% --
	INSERT INTO @TAB2_18	 
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA_NDS),
		SUM (T1.SUMMA),
		0
	FROM @TABLE_NDS T1
--	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
--	INNER JOIN @TAB_SFIN T3 ON (T3.LINK = T1.FS_LINK)
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 18
	GROUP BY T1.LINK_UP

	-- 10% --
	INSERT INTO @TAB2_10	 
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA_NDS),
		SUM (T1.SUMMA),
		0
	FROM @TABLE_NDS T1
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 10
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_0	-- 0% 
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA),
		0
	FROM @TABLE_NDS T1
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 0
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_NO_NDS	-- --
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA),
		0
	FROM @TABLE_NDS T1
	WHERE T1.NO_NDS = 1
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_20	-- 20% 
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA_NDS),
		SUM (T1.SUMMA),
		0
	FROM @TABLE_NDS T1
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 20
	GROUP BY T1.LINK_UP

	-- Итоговая сумма по документу --
	INSERT INTO @TAB_DOC_SUM
	SELECT T1.LINK_UP,
		SUM (T1.SUMMA_ALL)
	FROM @TABLE_NDS T1
	GROUP BY T1.LINK_UP

	-- Выбираем корректировочные с\ф (полученные) --
	INSERT INTO @TAB1	
	SELECT DOC.LINK,
		DOC.SEL_LINK,	-- ПРОДАВЕЦ --
		DOC.SUMMA,
		DOC.OSN_DATE,
		DOC.OSN_NUM,

		DOC.OSN_DATE_C,
		DOC.OSN_NUM_C,

		DOC.[DATE],
		DOC.NUMBER,
		DOC.COR_DATE,
		DOC.COR_NUM,

		DOC.DATE_BASE,
		RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
		1
	FROM dbo.DOCUMENTS_INVOICE_COR_IN DOC
	INNER JOIN dbo.DEPARTMENTS DEP ON ((DEP.ZB = 1 OR DEP.[TYPE] = 4)
					AND DEP.LINK = DOC.DEP_LINK)
	WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
		AND DOC.INBOOK = 1
		AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
			OR @intSVOD_ZB = 1)

	-- Выбираем корректировочные с\ф (выданные) --
	INSERT INTO @TAB1	
	SELECT DOC.LINK,
		DOC.SEL_LINK,	-- ПРОДАВЕЦ --
		DOC.SUMMA,
		DOC.OSN_DATE,
		DOC.OSN_NUM,

		DOC.OSN_DATE_C,
		DOC.OSN_NUM_C,

		DOC.[DATE],
		DOC.NUMBER,
		DOC.COR_DATE,
		DOC.COR_NUM,

		DOC.DATE_BASE,
		RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
		2
	FROM dbo.DOCUMENTS_INVOICE_COR_OUT DOC
	INNER JOIN dbo.DEPARTMENTS DEP ON ((DEP.ZB = 1 OR DEP.[TYPE] = 4)
					AND DEP.LINK = DOC.DEP_LINK)
	WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
		AND DOC.INBOOK = 1
		AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
			OR @intSVOD_ZB = 1)

-- SELECT * FROM @TAB1

	-- Табличная часть кор. с\ф --
	DECLARE @TABLE_COR TABLE
		(LINK_UP	INT,

/*		SUMMA_ALL1	NUMERIC (28,4),
		SUMMA_NDS1	NUMERIC (28,4),
		SUMMA1		NUMERIC (28,4),

		SUMMA_ALL2	NUMERIC (28,4),
		SUMMA_NDS2	NUMERIC (28,4),
		SUMMA2		NUMERIC (28,4),
*/
		SUMMA_ALL	NUMERIC (28,4),
		SUMMA_NDS	NUMERIC (28,4),
		SUMMA		NUMERIC (28,4),

		NO_NDS		TINYINT,
		STAVKA_NDS	NUMERIC (5,2),

		FS_LINK		INT,
		FS_CODE		VARCHAR (2),
		NDS_CODE	VARCHAR (3))

	INSERT INTO @TABLE_COR
	SELECT T1.LINK_UP,

		T1.S_ALL_NEW - T1.SUMMA_ALL,
		T1.S_NDS_NEW - T1.SUMMA_NDS,
		T1.SUM_NEW - T1.SUMMA,

		T1.NO_NDS_NEW,
		T1.ST_NDS_NEW,

		T2.LINK,
		T2.CODE,
		
		ISNULL (T1.TNDS_CODE2, '')		

	FROM dbo.BK_DOC_TAB_INVOICE_COR_FN (DEFAULT) T1
	INNER JOIN @TAB_SFIN T2 ON (T2.LINK = T1.FS_LINK)

-- SELECT * FROM @TABLE_COR

	-- Обработка кор. с\ф --
	INSERT INTO @TAB2_18	 
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA_NDS)),
		ABS (SUM (T1.SUMMA)),
		0
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 18
		-- Книга покупок 
		AND (@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0))
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0))
			)
	GROUP BY T1.LINK_UP

	-- 10% --
	INSERT INTO @TAB2_10	 
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA_NDS)),
		ABS (SUM (T1.SUMMA)),
		0
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 10
		-- Книга покупок 
		AND (@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0))
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0))
			)
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_0	-- 0% 
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA)),
		0
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 0
		-- Книга покупок 
		AND (@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0))
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0))
			)
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_NO_NDS	-- --
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA)),
		0
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE T1.NO_NDS = 1
		-- Книга покупок 
		AND (@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0))
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0))
			)
	GROUP BY T1.LINK_UP

	INSERT INTO @TAB2_20	-- 20% 
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA_NDS)),
		ABS (SUM (T1.SUMMA)),
		0
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE T1.NO_NDS = 0
		AND T1.STAVKA_NDS = 20
		-- Книга покупок 
		AND (@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0))
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND (T1.SUMMA_NDS < 0 OR T1.SUMMA < 0)
				OR T2.IS_COR = 2 AND (T1.SUMMA_NDS > 0 OR T1.SUMMA > 0))
			)
	GROUP BY T1.LINK_UP

	-- Итоговая сумма по документу --
	INSERT INTO @TAB_DOC_SUM
	SELECT T1.LINK_UP,
		ABS (SUM (T1.SUMMA_ALL))
	FROM @TABLE_COR T1
	INNER JOIN @TAB1 T2 ON (T2.LINK_DOC = T1.LINK_UP)
	WHERE 
		-- Книга покупок 
		(@varKSnOption1 = 1
			AND (T2.IS_COR = 1 AND T1.SUMMA_ALL > 0 
				OR T2.IS_COR = 2 AND T1.SUMMA_ALL < 0)
		-- Книга продаж
		OR @varKSnOption1 = 2
			AND (T2.IS_COR = 1 AND T1.SUMMA_ALL < 0 
				OR T2.IS_COR = 2 AND T1.SUMMA_ALL > 0)
			)
	GROUP BY T1.LINK_UP

	-- Вычисление строки для вида НДС --

	DECLARE @RESULT TABLE (DEP_NAME VARCHAR (254), DEP_INN VARCHAR (20), DEP_KPP VARCHAR (20),
		DEP_NAME1 VARCHAR (254), DEP_INN1 VARCHAR (20), DEP_KPP1 VARCHAR (20),
		dDOC_DATE DATETIME,
		DOC_DATE1 VARCHAR (10), DOC_NUM1 VARCHAR (50),
		DOC_DATE2 VARCHAR (10), DOC_NUM2 VARCHAR (50),
		COR_DATE1 VARCHAR (10), COR_NUM1 VARCHAR (50),
		COR_DATE2 VARCHAR (10), COR_NUM2 VARCHAR (50),
		DATE_OPL VARCHAR (10), SUM_TOTAL NUMERIC (28,4),
		SUMMA18 NUMERIC (28,4), NALOG18 NUMERIC (28,4),
		SUMMA10 NUMERIC (28,4), NALOG10 NUMERIC (28,4),
		SUMMA0 NUMERIC (28,4),
		SUMMA20 NUMERIC (28,4), NALOG20 NUMERIC (28,4),
		SUM_NONDS NUMERIC (28,4),
		REP1 TINYINT, SORT_NUM VARCHAR (50),
		IS_COR	TINYINT,
		SUM_NDS NUMERIC (28,4),
		NDS_CODE VARCHAR (100))

	INSERT INTO @RESULT
	SELECT @strHD_Org_Name,
		@strHD_PUR_INN,
		@strHD_PUR_KPP,

		ISNULL (D1.NAME, ''),
		ISNULL (D1.INN, ''),
		ISNULL (D1.KPP, ''),

		CASE
			WHEN IS_COR = 0 THEN T1.DOC_DATE1
			ELSE T1.COR_DATE1
		END,

		CONVERT (VARCHAR (10), T1.DOC_DATE1, 104),
		T1.DOC_NUM1,

		CONVERT (VARCHAR (10), T1.DOC_DATE2, 104),
		T1.DOC_NUM2,

		CONVERT (VARCHAR (10), T1.COR_DATE1, 104),
		T1.COR_NUM1,

		CONVERT (VARCHAR (10), T1.COR_DATE2, 104),
		T1.COR_NUM2,

		ISNULL (CONVERT (VARCHAR (10), T1.DATE_OPL, 104), ''),
		ISNULL (DOC_SUM.SUMMA_ALL, 0),
		ISNULL (T18.SUMMA, 0),
		ISNULL (T18.NALOG, 0),
		ISNULL (T10.SUMMA, 0),
		ISNULL (T10.NALOG, 0),
		ISNULL (T0.SUMMA, 0),
		ISNULL (T20.SUMMA, 0),
		ISNULL (T20.NALOG, 0),
		ISNULL (TNO.SUMMA, 0),
		1,
		T1.SORT_NUM,
		CASE 
			WHEN T1.IS_COR = 0 THEN 0
			ELSE 1
		END,
		ISNULL (T_NDS.SUM_NDS, 0),
		ISNULL (SUBSTRING ((SELECT
							'; ' + TNDS.NDS_CODE
						FROM
							(
							SELECT
								TN1.NDS_CODE
							FROM @TABLE_NDS TN1
							WHERE TN1.LINK_UP = T1.LINK_DOC
							UNION
							SELECT
								TN1.NDS_CODE
							FROM @TABLE_COR TN1
							WHERE TN1.LINK_UP = T1.LINK_DOC
							) AS TNDS
						WHERE TNDS.NDS_CODE <> ''
						FOR XML PATH ('')),
						3,
						1000), '')
	FROM @TAB1 T1
	LEFT OUTER JOIN dbo.DICTIONARY_DEPARTMENT D1 ON (D1.LINK = T1.DEP1)
	LEFT OUTER JOIN @TAB2_18 T18 ON (T1.LINK_DOC = T18.LINK_DOC) 
	LEFT OUTER JOIN @TAB2_10 T10 ON (T1.LINK_DOC = T10.LINK_DOC) 
	LEFT OUTER JOIN @TAB2_0 T0 ON (T1.LINK_DOC = T0.LINK_DOC) 
	LEFT OUTER JOIN @TAB2_20 T20 ON (T1.LINK_DOC = T20.LINK_DOC)
	LEFT OUTER JOIN @TAB2_NO_NDS TNO ON (T1.LINK_DOC = TNO.LINK_DOC)
	LEFT OUTER JOIN @TAB_DOC_SUM DOC_SUM ON (T1.LINK_DOC = DOC_SUM.LINK_DOC)
	LEFT JOIN (SELECT
					LINK_UP,
					SUM (SUMMA_NDS) AS SUM_NDS
				FROM @TABLE_NDS
				GROUP BY
					LINK_UP) AS T_NDS ON (T1.LINK_DOC = T_NDS.LINK_UP) 

	SELECT * 
	FROM @RESULT
	WHERE IS_COR = 0
		OR IS_COR = 1 AND SUM_TOTAL > 0
	ORDER BY dDOC_DATE,
		SORT_NUM,
		IS_COR
END



GO


GRANT EXECUTE ON dbo.[BK_REPORT_BOOK_SALES_PURCHASE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_BOOK_AMORT1]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_BOOK_AMORT1]

GO


CREATE      PROCEDURE dbo.BK_REPORT_BOOK_AMORT1
	@varKSnMonth1		INT			,
	@varKScYear1		VARCHAR (4)		,
	@varKScVal1	char(1), @varKSnOtborLink1	int,
	@dDATE_BEGIN		DATETIME	= NULL,
	@dDATE_END		DATETIME	= NULL,
	@intREPORT_BY_PERIOD	TINYINT		= 0,
	@intNO_AMORT	INT,
	@intSVOD_ZB INT,
	@cVal_KBK char(1), @nOtborLinkKBK int,		-- Отбор КБК --
	@intGRP_KBK	INT = 0,
	@intAMORT_ONLY_PER	INT = 0
--
AS
BEGIN

/*
SELECT
	intNO_AMORT = @intNO_AMORT,
	intSVOD_ZB = @intSVOD_ZB,
	intGRP_KBK	= @intGRP_KBK,
	intAMORT_ONLY_PER	= @intAMORT_ONLY_PER

RETURN
*/
--select 'start', convert (varchar (100), getdate (), 121)

	DECLARE
		@varKSDATE_BEGIN	DATETIME,	
		@varKSDATE_END		DATETIME,	
		@varKSDATE_REST		DATETIME,	
		@varKSLINK_DEP		INT		,
		@varKScNEXT_PERIOD	VARCHAR (10),
		@varKScBEGIN_PERIOD	VARCHAR (10),
		@varKScOtborAccount	VARCHAR (100),

		@varKSMonth		VARCHAR (20),
		@varKSP_CODE		VARCHAR (20),
		@varKSDEP_CODE		VARCHAR (20),
		@varKSDEP_NAME		VARCHAR (254),
		@varKSDEP_OKPO		VARCHAR (20),
		@varKSEMP_CODE		VARCHAR (20),
		@strGLBUH		VARCHAR (100),
		@varKSnSel_Spr1		INT,
		@varKSEMP_NAME		VARCHAR (254),
		@strDATE_END_PERIOD	VARCHAR (10),
		@intDEP_LINK	INT

	IF @intREPORT_BY_PERIOD = 0
	BEGIN
		SET @varKSDATE_BEGIN = dbo.DateBeginOfMonth (dbo.ConvertDMY2Date (1, @varKSnMonth1, CONVERT (INT, @varKScYear1)))
		SET @varKSDATE_END = dbo.DateEndOfMonth (@varKSDATE_BEGIN)
	END
	ELSE
	BEGIN
		SET @varKSDATE_BEGIN = @dDATE_BEGIN
		SET @varKSDATE_END = @dDATE_END
	END

	SET @strDATE_END_PERIOD	= CONVERT (VARCHAR (10), @varKSDATE_END, 104)
	SET @intNO_AMORT = ISNULL (@intNO_AMORT, 0)
	SET @intDEP_LINK = dbo.BK_GetDepZB () 

	DECLARE @ACCT_BALANSE TABLE (LINK_ACCT [INT],
					cSOURCE CHAR (1),
					cSINTH CHAR (3),
					cANALIT CHAR (2),
					cUSER VARCHAR (4))

	IF LEN (@varKScVal1) > 0
		INSERT INTO @ACCT_BALANSE
		SELECT RECORD,
			SA.cSOURCE,
			SA.cSINTH,
			SA.cANALIT,
			SA.cUSER
		FROM dbo.OBJECT_VAR_ACCT OV_AC
		INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = OV_AC.RECORD)
		WHERE LINK_UP = @varKSnOtborLink1
	ELSE
		INSERT INTO @ACCT_BALANSE
		SELECT T1.LINK,
			T1.cSOURCE,
			T1.cSINTH,
			T1.cANALIT,
			T1.cUSER
		FROM dbo.BK_GetAcctTableByCode ('101', DEFAULT, DEFAULT, DEFAULT) T1
		UNION ALL
		SELECT T1.LINK,
			T1.cSOURCE,
			T1.cSINTH,
			T1.cANALIT,
			T1.cUSER
		FROM dbo.BK_GetAcctTableByCode ('102', DEFAULT, DEFAULT, DEFAULT) T1
		UNION ALL
		SELECT T1.LINK,
			T1.cSOURCE,
			T1.cSINTH,
			T1.cANALIT,
			T1.cUSER
		FROM dbo.BK_GetAcctTableByCode ('108', '01,02,03', DEFAULT, DEFAULT) T1
		UNION ALL
		SELECT T1.LINK,
			T1.cSOURCE,
			T1.cSINTH,
			T1.cANALIT,
			T1.cUSER
		FROM dbo.BK_GetAcctTableByCode ('108', '51,52,54', DEFAULT, DEFAULT) T1

	DECLARE @ACCT_AMORT TABLE (LINK_ACCT [INT],
					cSOURCE CHAR (1),
					cSINTH CHAR (3),
					cANALIT CHAR (2),
					cUSER VARCHAR (4))

	INSERT INTO @ACCT_AMORT
	SELECT
		T1.LINK,
		T1.cSOURCE,
		T1.cSINTH,
		T1.cANALIT,
		T1.cUSER
	FROM dbo.BK_GetAcctTableByCode ('104', DEFAULT, DEFAULT, DEFAULT) T1

	--- Отбор КБК --- 
	DECLARE @TAB_KBK TABLE (LINK_KBK INT, KBK_CODE VARCHAR (20))
	IF LEN (@cVal_KBK) > 0
		INSERT INTO @TAB_KBK
		SELECT AP.LINK,
			AP.CODE
		FROM dbo.KL_KBK AP 
		INNER JOIN dbo.OBJECT_VAR_KBK OVR ON (OVR.RECORD = AP.LINK)
		WHERE OVR.LINK_UP = @nOtborLinkKBK
	ELSE
		INSERT INTO @TAB_KBK
		SELECT LINK_AP, AP_CODE
		FROM dbo.BK_GetTableDictionByAP ('KBK')

	--- Параметры организации --- 
	SET @intSVOD_ZB = ISNULL (@intSVOD_ZB, 0)
	SET @varKSLINK_DEP = dbo.BK_GetDepZB ()

	IF @intSVOD_ZB = 1 OR @varKSLINK_DEP IS NULL
		SET @varKSLINK_DEP = dbo.GetOwnDepLink()

	SELECT
		@varKSLINK_DEP = LINK,
		@varKSDEP_CODE = CODE,
		@varKSDEP_NAME = [NAME],
		@varKSDEP_OKPO = OKPO
	FROM dbo.DICTIONARY_DEPARTMENT
	WHERE LINK = @varKSLINK_DEP

	IF @intSVOD_ZB = 1
		SET @varKSDEP_NAME = RTRIM (@varKSDEP_NAME) + ' (ЦБ)'

	SET @varKSDATE_REST = DATEADD (DAY, 1, @varKSDATE_END)

	DECLARE @BALANSE_OS TABLE (DEP [INT], ACCOUNT [INT], INV [INT], KBK INT,
		IN_QTY [NUMERIC] (28,4), IN_SUMMA [NUMERIC] (28,4),
		OUT_QTY [NUMERIC] (28,4), OUT_SUMMA [NUMERIC] (28,4))

	INSERT INTO @BALANSE_OS
	SELECT T1.DEP,
		T1.ACCOUNT,
		T1.INV,
		T1.KBK,
		SUM (T1.IN_QTY),
		SUM (T1.IN_SUMMA),
		SUM (T1.OUT_QTY),
		SUM (T1.OUT_SUMMA)
	FROM dbo.BK_GetTableOSVByDate (@varKSDATE_BEGIN, @varKSDATE_END, @intDEP_LINK) T1
	INNER JOIN @ACCT_BALANSE T2 ON (T2.LINK_ACCT = T1.ACCOUNT)
	INNER JOIN @TAB_KBK T3 ON (T3.LINK_KBK = T1.KBK)
	WHERE @intSVOD_ZB = 1 
		OR (@intSVOD_ZB = 0 AND T1.DEP_LINK = @varKSLINK_DEP)
	GROUP BY T1.DEP,
		T1.ACCOUNT,
		T1.INV,
		T1.KBK

--select '@BALANSE_OS', convert (varchar (100), getdate (), 121)


	DECLARE @AMORT_OS TABLE (ACCOUNT [INT], INV [INT], KBK INT, 
		cSOURCE CHAR (1), cSINTH CHAR (3), cANALIT CHAR (2), cUSER VARCHAR (4),
		IN_SUMMA [NUMERIC] (28,4), K_SUMMA [NUMERIC] (28,4),
		OUT_SUMMA [NUMERIC] (28,4))

	INSERT INTO @AMORT_OS
	SELECT T1.ACCOUNT,
		T1.INV,
		T1.KBK,
		T2.cSOURCE,
		T2.cSINTH,
		T2.cANALIT,
		T2.cUSER,
		SUM (ISNULL (T1.IN_SUMMA, 0)),
		SUM (ISNULL (T1.K_SUMMA, 0)),
		SUM (ISNULL (T1.OUT_SUMMA, 0))
	FROM dbo.BK_GetTableOSVByDate (@varKSDATE_BEGIN, @varKSDATE_END, @intDEP_LINK) T1
	INNER JOIN @ACCT_AMORT T2 ON (T2.LINK_ACCT = T1.ACCOUNT)
	INNER JOIN @TAB_KBK T3 ON (T3.LINK_KBK = T1.KBK)
--	WHERE T1.DEP_LINK = @varKSLINK_DEP
	WHERE @intSVOD_ZB = 1 
		OR (@intSVOD_ZB = 0 AND T1.DEP_LINK = @varKSLINK_DEP)
	GROUP BY T1.ACCOUNT,
		T1.INV,
		T1.KBK,
		T2.cSOURCE,
		T2.cSINTH,
		T2.cANALIT,
		T2.cUSER
	HAVING	SUM (ISNULL (T1.IN_SUMMA, 0)) <> 0
		OR SUM (ISNULL (T1.K_SUMMA, 0)) <> 0
		OR SUM (ISNULL (T1.OUT_SUMMA, 0)) <> 0

--select '@AMORT_OS', convert (varchar (100), getdate (), 121)

	DECLARE @TABLE_DATE_OUT_OS TABLE (INV [INT], DATE_OUT [DATETIME])
	INSERT INTO @TABLE_DATE_OUT_OS
	SELECT INV,
		MAX (DATE_OPER)
	FROM dbo.BK_GetDateTableOutOS (DEFAULT , @varKSDATE_END)
	GROUP BY INV

--select '@TABLE_DATE_OUT_OS', convert (varchar (100), getdate (), 121)

	-- ОС, по которым начислялась амортизация за указанный период --
	SET @intAMORT_ONLY_PER = ISNULL (@intAMORT_ONLY_PER, 0)
--SELECT @varKSDATE_END,  * FROM @TABLE_DATE_OUT_OS

	DECLARE
		@TAB_RES TABLE (ACCOUNT [INT], INV [INT],
		ACCT_CODE [VARCHAR] (30),
		INV_CODE [VARCHAR] (20), INV_NAME [VARCHAR] (254),
		BEGIN_USED [VARCHAR] (10), 
		QTY [NUMERIC] (28,4), BALANSE [NUMERIC] (28,4),
		ASUM_PB [NUMERIC] (28,4), ASUM_P [NUMERIC] (28,4), ASUM_PE [NUMERIC] (28,4),
		LSUM_BE  [NUMERIC] (28,4), LSUM_PE  [NUMERIC] (28,4),
		PERC_RATE [NUMERIC] (10,2),
		DEP_NAME [VARCHAR] (254),
		GLBUH [VARCHAR] (100),
		MONTH_NAME [VARCHAR] (20),
		YEAR_NAME [INT],
		DATE1 [VARCHAR] (10),
		DATE2 [VARCHAR] (10),
		YPERC_RATE [FLOAT],
		YSUM_RATE  [NUMERIC] (28,4),
		MSUM_RATE  [NUMERIC] (28,4),
		ISPERIOD   [TINYINT],
		PERIOD_END [VARCHAR] (10),
		DATE_OUT [VARCHAR] (10),
		KBK_CODE VARCHAR (30))

	SET @varKSMonth = dbo.DateMonthName (@varKSnMonth1)
	SET @varKSMonth = ISNULL (@varKSMonth, '')

	SELECT @strGLBUH = SHORT_NAME
	FROM dbo.GetOtvFaceData (@varKSLINK_DEP, 'Главный бухгалтер')

	SET @intGRP_KBK = ISNULL (@intGRP_KBK, 0)

	INSERT INTO @TAB_RES
	SELECT
		T1.ACCOUNT,
		T1.INV,
		RTRIM (SA.CODE),
		ISNULL (INV.CODE, ''),
		ISNULL (INV.NAME, ''),
		ISNULL (CONVERT (VARCHAR (10), INV_DOP.DATE_BEGIN, 104), ''),
		CASE
			WHEN T1.OUT_QTY > 0 THEN T1.OUT_QTY
			WHEN T1.IN_QTY > 0 THEN T1.IN_QTY
			ELSE 0
		END,
		CASE
			WHEN T1.OUT_SUMMA > 0 THEN T1.OUT_SUMMA
			WHEN T1.IN_SUMMA > 0 THEN T1.IN_SUMMA
			ELSE 0
		END,
		ISNULL (T2.IN_SUMMA, 0),
		ISNULL (T2.K_SUMMA, 0),
		ISNULL (T2.OUT_SUMMA, 0),
		T1.IN_SUMMA - ISNULL (T2.IN_SUMMA, 0),
		T1.OUT_SUMMA - ISNULL (T2.OUT_SUMMA, 0),
		0,
		@varKSDEP_NAME,
		@strGLBUH,
		@varKSMonth,
		YEAR (@varKSDATE_BEGIN),
		CONVERT (VARCHAR (10), @varKSDATE_BEGIN, 104),
		CONVERT (VARCHAR (10), DATEADD (DAY, 1, @varKSDATE_END), 104),
/*		ISNULL (INV_DOP.DEPRE_RATE, CASE
						WHEN ISNULL (INV_DOP.PERIOD_USED, 0) <> 0
						THEN 100 / INV_DOP.PERIOD_USED
						ELSE 0
					END),
*/		ISNULL (NORM_D.DEPRE_RATE, 0),
		0, 0,
		@intREPORT_BY_PERIOD,
		@strDATE_END_PERIOD,
		ISNULL (CONVERT (VARCHAR (10), DATE_OUT, 104), ''),
		ISNULL (K.CODE, '')
	FROM @BALANSE_OS T1
--	INNER JOIN @AMORT_OS T2 ON (T2.INV = T1.INV)
	INNER JOIN dbo.INVENTORY_CARD INV ON (INV.LINK = T1.INV)
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = T1.ACCOUNT)
	LEFT OUTER JOIN @AMORT_OS T2 ON (T2.INV = T1.INV
				 AND T2.cSOURCE = SA.cSOURCE)
	LEFT OUTER JOIN dbo.BV_INVENTORY_CARD_DOP INV_DOP ON (INV_DOP.LINK_UP = T1.INV)
	LEFT OUTER JOIN @TABLE_DATE_OUT_OS OUT_OS ON (OUT_OS.INV = T1.INV)
	LEFT OUTER JOIN dbo.BK_GetNormDepreTableByOS (DEFAULT) NORM_D ON (NORM_D.INV = T1.INV)
	LEFT JOIN dbo.KL_KBK K ON (@intGRP_KBK = 1 AND K.LINK = T1.KBK)
	WHERE 
		(@intAMORT_ONLY_PER = 0 
			OR @intAMORT_ONLY_PER = 1 AND ISNULL (T2.K_SUMMA, 0) <> 0)
		AND (@intNO_AMORT = 0 AND T2.INV = T1.INV
			OR @intNO_AMORT = 1)


	UPDATE @TAB_RES SET PERC_RATE = ASUM_PE / BALANSE * 100
	WHERE BALANSE <> 0
	
	UPDATE @TAB_RES SET YSUM_RATE = BALANSE * YPERC_RATE /100
	UPDATE @TAB_RES SET MSUM_RATE = YSUM_RATE / 12

--select '@TAB_RES', convert (varchar (100), getdate (), 121)				

	SELECT * FROM @TAB_RES ORDER BY KBK_CODE, ACCT_CODE, RIGHT ('00000000000000000000' + INV_CODE, 20)

--select 'end', convert (varchar (100), getdate (), 121)
	
END



GO


GRANT EXECUTE ON dbo.[BK_REPORT_BOOK_AMORT1] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_EXPORT_F1152004_503]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_EXPORT_F1152004_503]

GO
CREATE PROCEDURE dbo.BK_EXPORT_F1152004_503
	(@iLINK_FORM INT)
AS
BEGIN

--перенос формы из архивной базы
exec RN_MOVE_FORM_FROM_ARH @iLINK_FORM

	DECLARE
		@FNAME VARCHAR (254),
		@FNAME_ID VARCHAR (254),

		@PART_NAME_NNN VARCHAR (100),

		@DEP_LINK	INT,
		@INN	VARCHAR (12),
		@KPP VARCHAR (9),
		@IMNS VARCHAR (4),
		@OKVED VARCHAR (8),
		@TLF_GL_BUH	VARCHAR (10),
		@POST_GL_BUH	VARCHAR (254),
		@DEP_NAME VARCHAR (254),

		@DOC_ID		VARCHAR (36),

		@NAME_RUK	VARCHAR (60),
		@FAM_RUK	VARCHAR (60),
		@OT_RUK		VARCHAR (60),

		@NAME_GL_BUH	VARCHAR (60),
		@FAM_GL_BUH	VARCHAR (60),
		@OT_GL_BUH	VARCHAR (60),

		@dDATE_FORM	DATETIME,
		@PERIOD_TYPE	INT,
		@PERIOD_NUM	INT,
		@cPERIOD_NUM	VARCHAR (2),

		@iLINK_TABLE	INT,
		@PROC_NAME	VARCHAR (254),

		--- Раздел 1 ---
		@KBK VARCHAR (20),
		@OKTMO VARCHAR (15),
		@OKTMO_DIC VARCHAR (15),
		@SUMMA	NUMERIC (15,0),

		@SUM_AV NUMERIC (15,0),
		@SUM_PAY NUMERIC (15,0),
		@SUM_LOW NUMERIC (15,0),

		@LINK_COL_CODE INT,
		@NUM_KOR NUMERIC (20),
		
		@strNUM_COR	VARCHAR (3),
		@C_PLACE	VARCHAR (3),
		
		@cREORG_CODE	VARCHAR (1),
		@cREORG_INN	VARCHAR (12),
		@cREORG_KPP	VARCHAR (12),
		
		@SUM1	NUMERIC (15,0),
		@SUM11	NUMERIC (15,0),
		@SUM12	NUMERIC (15,0),
		@SUM13	NUMERIC (15,0),
		@SUM2	NUMERIC (15,0),

		--- Раздел 2 ---
		@LINK_COL_VIDTS	INT,
		@LINK_COL_VIN	INT,
		@LINK_COL_MARKA	INT,
		@LINK_COL_REGNO	INT,
		@LINK_COL_NALBAS INT,
		@LINK_COL_OKEI	INT,
		@LINK_COL_SROK	INT,
		@LINK_COL_K3623	INT,
		@LINK_COL_STAVKA INT,
		@LINK_COL_SUM_IS	INT,
		@LINK_COL_LGOTA	INT,
		@LINK_COL_SUM_LGOTA	INT,
		@LINK_COL_SUM_UPL	INT,

		@strEXEC	VARCHAR (8000)

	--- Данные организации ---
	SELECT
		@DEP_LINK = RSF.LINK_ORGANIZATION,
		@dDATE_FORM	= RSF.BEGIN_DATE,
		@PERIOD_TYPE = RSF.PERIOD_TYPE,
		@PERIOD_NUM	= RSF.PERIOD_NUMBER,
		
		@INN	= CONVERT (VARCHAR (10), DEP.INN_LONG),
		@KPP = CONVERT (VARCHAR (9), DEP.KPP),
		@IMNS = CONVERT (VARCHAR (4), DEP.IMNS),
		@OKVED = CONVERT (VARCHAR (8), DEP.OKVED),
		@DEP_NAME = DEP.[NAME],
		@OKTMO_DIC = CONVERT (VARCHAR (11), REPLACE (DEP.OKTMO, ' ', ''))
		
	FROM dbo.REPORT_SAVED_FORMS RSF
	INNER JOIN dbo.DICTIONARY_DEPARTMENT DEP ON (DEP.LINK = RSF.LINK_ORGANIZATION)
	WHERE RSF.LINK_SAVED_FORM = @iLINK_FORM

	SET @cPERIOD_NUM = CASE
							WHEN @PERIOD_NUM = 1 THEN '21'
							WHEN @PERIOD_NUM = 2 THEN '22'
							WHEN @PERIOD_NUM = 3 THEN '23'
						END

	EXEC dbo.GetRandStr
			36,
			@DOC_ID OUTPUT

	SELECT
		@PART_NAME_NNN = @DOC_ID

	SELECT
		@TLF_GL_BUH = A.PHONE,
		@POST_GL_BUH = B.POST_NAME,

		@NAME_GL_BUH = B.IM,
		@FAM_GL_BUH = B.FM,
		@OT_GL_BUH = B.OT
	FROM dbo.DICTIONARY_OTV_FACE A
	LEFT JOIN dbo.KU_EMPL_PLACING B ON (B.LINK = A.FACE_LINK)
	WHERE A.DEP_LINK = @DEP_LINK
		AND A.[NAME] = 'Главный бухгалтер'
		
	SELECT
		@NAME_RUK = IM,
		@FAM_RUK = FM,
		@OT_RUK = OT
	FROM dbo.KU_EMPL_PLACING 
	WHERE LINK = (SELECT
						FACE_LINK
					FROM dbo.DICTIONARY_OTV_FACE
					WHERE DEP_LINK = @DEP_LINK
						AND [NAME] = 'Руководитель')

	--- !!!РАСЧЕТ!!! ---
	-- Данные раздела 1 --
	SELECT 
		@iLINK_TABLE = LINK_TABLE
	FROM dbo.REPORT_SAVED_FORMS RSF 
	INNER JOIN dbo.REPORT_TABLES RT ON (RT.LINK_FORM = RSF.LINK_FORM)
	WHERE RSF.LINK_SAVED_FORM = @iLINK_FORM
		AND ORDERS = 1

	CREATE TABLE #TAB1
		(
		CHECKED INT,
		UPD INT,
		DEL INT,
		LINK_SAVED_FORM INT,
		LINK_ROW INT,
		ORDERS INT,
		CALC_ORDERS INT,
		PRINT_NULL INT,
		CODE VARCHAR (50),
		COL1 VARCHAR (254),
		COL2 VARCHAR(100),	-- 
		FCOL2 VARCHAR (1000),
		COL3 NUMERIC (20), 	-- 
		FCOL3 VARCHAR (1000),
		COL4 NUMERIC(20), 	-- 
		FCOL4 VARCHAR (1000),
		COL5 NUMERIC(20),	-- 
		FCOL5 VARCHAR (1000),
		COL6 NUMERIC (20), 	-- 
		FCOL6 VARCHAR (1000),
		COL7 NUMERIC (20), 	-- 
		FCOL7 VARCHAR (1000),
		COL8 NUMERIC(20),	-- 
		FCOL8 VARCHAR (1000),
		COL9 VARCHAR(100),	-- 
		FCOL9 VARCHAR (1000),
		COL10 VARCHAR (100),	-- 
		FCOL10 VARCHAR (1000),
		COL11 VARCHAR(100),	-- 
		FCOL11 VARCHAR (1000),
		COL12 VARCHAR(100),	-- 
		FCOL12 VARCHAR (1000),
		COL13 VARCHAR(100),	-- 
		FCOL13 VARCHAR (1000),
		COL14 VARCHAR(100),	-- 
		FCOL14 VARCHAR (1000),
		COL15 VARCHAR(100),	-- 
		FCOL15 VARCHAR (1000),
		ITOG NUMERIC(20)
		)
	
	IF @iLINK_TABLE > 0
	BEGIN
	
		SET @strEXEC = 'INSERT INTO #TAB1 (CHECKED, UPD, DEL,
							LINK_SAVED_FORM, LINK_ROW,
							ORDERS, CALC_ORDERS, PRINT_NULL,
							CODE, COL1, COL2, FCOL2, COL3, FCOL3,
							COL4, FCOL4, COL5, FCOL5, COL6, FCOL6,
							COL7, FCOL7, COL8, FCOL8, COL9, FCOL9,
							COL10, FCOL10, COL11, FCOL11, COL12, FCOL12,
							COL13, FCOL13, COL14, FCOL14, COL15, FCOL15,
							ITOG)
				EXEC dbo.RI_PROC_T' + LTRIM (STR (@iLINK_TABLE))
					+ ' ' + LTRIM (STR (@iLINK_FORM)) + ', 0'

--		SET @strEXEC = 'EXEC dbo.RI_PROC_T' + LTRIM (STR (@iLINK_TABLE))
--					+ ' ' + LTRIM (STR (@iLINK_FORM)) + ', 0'

		EXECUTE (@strEXEC)
		
-- SELECT * FROM #TAB1
		
	END
	
	SELECT
		@OKTMO = ISNULL (COL2, ''),
		@KBK = ISNULL (COL9, ''),
		@strNUM_COR = ISNULL (COL10, ''),
		@C_PLACE = ISNULL (COL11, ''),
		@cPERIOD_NUM = ISNULL (COL12, ''),
		@cREORG_CODE = ISNULL (COL13, ''),
		@cREORG_INN = ISNULL (COL14, ''),
		@cREORG_KPP = ISNULL (COL15, ''),
		
		@SUM1	= ISNULL (COL3, 0),
		@SUM11	= ISNULL (COL4, 0),
		@SUM12	= ISNULL (COL5, 0),
		@SUM13	= ISNULL (COL6, 0),
		@SUM2	= ISNULL (COL7, 0) - ISNULL (COL7, 0)
	FROM #TAB1

	-- Данные раздела 2 --
	SET @iLINK_TABLE = 0
	SELECT @iLINK_TABLE = LINK_TABLE
	FROM dbo.REPORT_SAVED_FORMS RSF 
	INNER JOIN dbo.REPORT_TABLES RT ON (RT.LINK_FORM = RSF.LINK_FORM)
	WHERE RSF.LINK_SAVED_FORM = @iLINK_FORM
		AND ORDERS = 2
		
	CREATE TABLE #TAB2
		(
		CHECKED INT,
		UPD INT,
		DEL INT,
		LINK_SAVED_FORM INT,
		LINK_ROW INT,
		ORDERS INT,
		CALC_ORDERS INT,
		PRINT_NULL INT,
		CODE VARCHAR (50),
		COL1 VARCHAR (254),
		COL2 VARCHAR(100),	-- 
		FCOL2 VARCHAR (1000),
		COL3 VARCHAR(100),	-- 
		FCOL3 VARCHAR (1000),
		COL4 VARCHAR(100),	-- 
		FCOL4 VARCHAR (1000),
		COL5 VARCHAR(100),	-- 
		FCOL5 VARCHAR (1000),
		COL6 NUMERIC (20, 2), 	-- 
		FCOL6 VARCHAR (1000),
		COL7 VARCHAR(100), --
		FCOL7 VARCHAR (1000),
		COL8 VARCHAR(100), --
		FCOL8 VARCHAR (1000),
		COL9 NUMERIC (20), 	-- 
		FCOL9 VARCHAR (1000),
		COL10 NUMERIC (20), 	-- 
		FCOL10 VARCHAR (1000),
		
		COL11 VARCHAR (100), -- 
		FCOL11 VARCHAR (1000),
		
		COL12 NUMERIC (20, 4), -- 
		FCOL12 VARCHAR (1000),
		COL13 NUMERIC (20, 4), -- 
		FCOL13 VARCHAR (1000),
		
		COL14 NUMERIC (20, 1), -- 
		FCOL14 VARCHAR (1000),
				
		COL15 NUMERIC (20), -- 
		FCOL15 VARCHAR (1000),
		COL16 NUMERIC (20),	-- 
		FCOL16 VARCHAR (1000),
		COL17 NUMERIC (20, 4), -- 
		FCOL17 VARCHAR (1000),
		
		COL18 VARCHAR(100), --
		FCOL18 VARCHAR (1000),
		COL19 NUMERIC (20), 	-- 
		FCOL19 VARCHAR (1000),
		COL20 VARCHAR(100), --
		FCOL20 VARCHAR (1000),
		COL21 NUMERIC (20), 	-- 
		FCOL21 VARCHAR (1000),
		COL22 VARCHAR(100), --
		FCOL22 VARCHAR (1000),
		COL23 NUMERIC (20), -- 
		FCOL23 VARCHAR (1000),
		COL24 NUMERIC (20), -- 
		FCOL24 VARCHAR (1000),
		
		ITOG NUMERIC(20) DEFAULT (0)
		)

	IF @iLINK_TABLE > 0
	BEGIN
		SET @strEXEC = 'INSERT INTO #TAB2 (CHECKED, UPD, DEL,
							LINK_SAVED_FORM, LINK_ROW,
							ORDERS, CALC_ORDERS, PRINT_NULL,
							CODE, COL1, COL2, FCOL2, COL3, FCOL3,
							COL4, FCOL4, COL5, FCOL5, COL6, FCOL6,
							COL7, FCOL7, COL8, FCOL8, COL9, FCOL9,
							COL10, FCOL10, COL11, FCOL11, COL12, FCOL12,
							COL13, FCOL13, COL14, FCOL14, COL15, FCOL15,
							COL16, FCOL16, COL17, FCOL17, COL18, FCOL18,
							COL19, FCOL19, COL20, FCOL20, COL21, FCOL21,
							COL22, FCOL22, COL23, FCOL23, COL24, FCOL24
							)
				EXEC dbo.RI_PROC_T' + LTRIM (STR (@iLINK_TABLE))
					+ ' ' + LTRIM (STR (@iLINK_FORM)) + ', 0'
		EXECUTE (@strEXEC)
	END

	--- Формирование XML ---
	SELECT @FNAME_ID = 'NO_TRAND_' + ISNULL (RTRIM (@IMNS), '0000') + '_' + ISNULL (RTRIM (@IMNS), '0000') + '_'
		+ ISNULL (RTRIM (@INN), '0000000000') + ISNULL (RTRIM (@KPP), '000000000')
		+ '_' + CONVERT (VARCHAR (10), GETDATE (), 112) + '_'
		+ SUBSTRING (@PART_NAME_NNN, LEN (@PART_NAME_NNN) - 36, 36) 

	SELECT @FNAME = RTRIM (@FNAME_ID) + '.XML'

	DECLARE @OUTPUT TABLE
		(
		ID int identity(1,1),
		F_NAME VARCHAR(254) DEFAULT (''),
		OUT_TEXT TEXT DEFAULT ('')
		)

	--Строка заголовка
	CREATE TABLE #TASK_PROP (ID int identity(1,1), VAL VARCHAR (254))

	INSERT INTO #TASK_PROP (VAL) exec dbo.X_GET_PROP_CLIENT 'PROJECT','VERSION_MAJOR',1
	INSERT INTO #TASK_PROP (VAL) exec dbo.X_GET_PROP_CLIENT 'PROJECT','VERSION_MINOR',1
	INSERT INTO #TASK_PROP (VAL) exec dbo.X_GET_PROP_CLIENT 'PROJECT','VERSION_FIX',1

	DECLARE
		@NAME_PROG varchar(254),
		@VERS_PROG VARCHAR(254)
		
	SELECT
		@NAME_PROG = UPPER(RTRIM(LTRIM([NAME]))), 
		@VERS_PROG = (SELECT RTRIM(LTRIM(VAL)) FROM #TASK_PROP WHERE [ID] = 1)
		+ '.' + (SELECT REPLACE(STR(RTRIM(LTRIM(VAL)),2),' ','0') FROM #TASK_PROP WHERE [ID] = 2)
		+ '.' + (SELECT REPLACE(STR(RTRIM(LTRIM(VAL)),2),' ','0') FROM #TASK_PROP WHERE [ID] = 3)
	FROM dbo.DICTIONARY_TASK
	WHERE CODE = 'SMETA'

	SET @NAME_PROG = RTRIM (@NAME_PROG) + ' ' + @VERS_PROG
	
	-- Заголовок --
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'OEM')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<?xml version ="1.0" encoding ="windows-1251"?>')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<Файл xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ИдФайл="' + RTRIM (@FNAME_ID) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ВерсПрог="' + RTRIM (LEFT (@NAME_PROG, 40)) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ВерсФорм="5.03">')
	
	-- Документ -- 
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<Документ КНД="1152004"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ДатаДок="' + CONVERT (VARCHAR (10), GETDATE (), 104) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'Период="' + @cPERIOD_NUM + '"')	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ОтчетГод="' + LTRIM (STR (YEAR (@dDATE_FORM))) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'КодНО="' + ISNULL (@IMNS, '') + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'НомКорр="' + ISNULL (@strNUM_COR, '0') + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ПоМесту="' + ISNULL (@C_PLACE, '') + '">')

	-- Сведения о налогоплательщике --
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<СвНП ОКВЭД="' + ISNULL (@OKVED, '') + '"')
	IF ISNULL (@TLF_GL_BUH, '') <> ''
		INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'Тлф="' + RTRIM (ISNULL (@TLF_GL_BUH, '')) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '>')

	-- Сведения об организации --
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<НПЮЛ НаимОрг="'
			 + RTRIM (ISNULL (REPLACE (@DEP_NAME, '"', '&quot;'), '')) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ИННЮЛ="' + ISNULL (@INN, '') + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'КПП="' + ISNULL (@KPP, '') + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '>')

	-- Сведения о реорганизованной (ликвидированной) организации (СвРеоргЮЛ) --
	IF LEN (@cREORG_CODE) > 0	
	BEGIN
		INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<СвРеоргЮЛ ФормРеорг="'
			+ ISNULL (@cREORG_CODE, '') + '"')

		IF @cREORG_CODE LIKE '[1-3, 5-6]'
		BEGIN
			INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'ИННЮЛ="' + @cREORG_INN + '"')
			INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'КПП="' + @cREORG_KPP + '"')
		END	
		INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '/>')
	END

	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</НПЮЛ>')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</СвНП>')
	
	-- Лицо, подписавшее документ (Подписант) --
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<Подписант ПрПодп="1">')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<ФИО Фамилия="' + RTRIM (ISNULL (@FAM_RUK, '')) 
					+ '" Имя="' + RTRIM (@NAME_RUK) + '"'
					+ CASE WHEN ISNULL (@OT_RUK, '') <> '' THEN ' Отчество="' + RTRIM (ISNULL (@OT_RUK, '')) + '"'
							ELSE '' END
					+ '/>')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</Подписант>')

	-- Налоговая декларация по транспортному налогу (ТрНалНД) --
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<ТрНалНД>')
	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<СумНалПУ КБК="' + @KBK + '">')
	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<СумПУ ОКТМО="' + @OKTMO + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'НалИсчисл="' + CONVERT (VARCHAR (15), @SUM1) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'АвПУКв1="' + CONVERT (VARCHAR (15), @SUM11) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'АвПУКв2="' + CONVERT (VARCHAR (15), @SUM12) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'АвПУКв3="' + CONVERT (VARCHAR (15), @SUM13) + '"')
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, 'НалПУ="' + CONVERT (VARCHAR (15), @SUM2) + '">')

	-- Расчет суммы транспортного налога по каждому транспортному средству (РасчНалТС) --
--	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '<РасчНалТС>')

	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT)
	SELECT
		@FNAME,
		'<РасчНалТС КодВидТС="' + LTRIM (ISNULL (COL2, '')) 
		+ '" ИдНомТС="' + LTRIM (ISNULL (COL3, '')) 
		+ '" МаркаТС="' + LTRIM (ISNULL (COL4, '')) 
		+ '" РегЗнакТС="' + LTRIM (ISNULL (COL5, '')) 
		+ '" НалБаза="' + LTRIM (STR (ISNULL (COL6, 0), 16, 2))  
		+ '" ОКЕИНалБаза="' + LTRIM (ISNULL (COL7, ''))
		+ '" ЭкологКл="' + LTRIM (ISNULL (COL8, ''))
		+ '" ВыпускТС="' + LTRIM (STR (ISNULL (COL9, 0)))
		+ '" ВладенТС="' + LTRIM (STR (ISNULL (COL10, 0)))
		+ '" ДоляТС="' + LTRIM (ISNULL (COL11, ''))
		
		+ '" КоэфКв="' + LTRIM (STR (ISNULL (COL12, 0), 6, 4))  
		+ '" НалСтавка="' + LTRIM (STR (ISNULL (COL13, 0), 10, 2))

		+ CASE  WHEN ISNULL (COL14, 0) = 1 THEN '' ELSE  ('" КоэфКп="' + LTRIM (STR (ISNULL (COL14, 0), 3, 1)) ) END 

		+ '" СумИсчисл="' + LTRIM (STR (ISNULL (COL15, 0)))
		+ '" ЛьготМесТС="' + LTRIM (STR (ISNULL (COL16, 0)))
		+ '" КоэфКл="' + LTRIM (STR (ISNULL (COL17, 0), 6, 4))  
		+ '" СумИсчислУпл="' + LTRIM (STR (ISNULL (COL24, 0))) + '">'
		+ '<ЛьготОсвНал КодОсвНал="' + LTRIM (ISNULL (COL18, ''))
		+ '" СумОсвНал="' + LTRIM (STR (ISNULL (COL19, 0))) + '"/>'
		+ '<ЛьготУменСум КодУменСум="' + LTRIM (ISNULL (COL20, ''))
		+ '" СумУменСум="' + LTRIM (STR (ISNULL (COL21, 0))) + '"/>'
		+ '<ЛьготСнижСтав КодСнижСтав="' + LTRIM (ISNULL (COL22, ''))
		+ '" СумУменСум="' + LTRIM (STR (ISNULL (COL23, 0))) + '"/>'
		+ '</РасчНалТС>'
	FROM #TAB2 

--	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</РасчНалТС>')
	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</СумПУ>')
	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</СумНалПУ>')
	
	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</ТрНалНД>')

	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</Документ>')

	INSERT INTO @OUTPUT (F_NAME, OUT_TEXT) VALUES (@FNAME, '</Файл>')

	SELECT *
	FROM @OUTPUT
	ORDER BY ID

	DROP TABLE #TAB1
	DROP TABLE #TAB2
	DROP TABLE #TASK_PROP

END 


GO


GRANT EXECUTE ON dbo.[BK_EXPORT_F1152004_503] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[PV_SAVE_G_PROV2_MENU_REQ]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[PV_SAVE_G_PROV2_MENU_REQ]

GO


CREATE	PROCEDURE dbo.PV_SAVE_G_PROV2_MENU_REQ
	@varKSnLINK_GP1  INT,		
	@varKSnTYP_LINK INT,			
	@varKSnLINK_INV  INT,			
	@varKSnQTY NUMERIC(19,4) = 0,
	@varKSnLINK_MOL INT = 0,
	@varKSdCALC_DATE DATETIME = NULL,
	@varKSpcSOU_CODE CHAR(1) = '0'

AS

DECLARE
	@varKScSOU_CODE CHAR(1),
	@varKSnKBK INT,
	@varKSnEKR INT,
	@varKSnDEP INT,
	@varKSnSUB INT,
	@varKSnEMP INT,
	@varKSnNOMEN INT,
	@varKSnINV INT,
	@varKSnKAU INT,
	@varKSnDEP_ACC INT,
	@varKSnTMC INT,
	@varKSnINDATE DATETIME,
	@varKSnAP1 INT,
	@varKSnAP2 INT,
	@varKSnAP3 INT,

	@varKSnSGU_DT INT,
	@varKSnKBK_DT INT,
	@varKSnEKR_DT INT,
	@varKSnDEP_DT INT,
	@varKSnSUB_DT INT,
	@varKSnEMP_DT INT,
	@varKSnNOMEN_DT INT,
	@varKSnINV_DT INT,
	@varKSnKAU_DT INT,
	@varKSnDEP_ACC_DT INT,
	@varKSnTMC_DT INT,
	@varKSnINDATE_DT DATETIME,
	@varKSnAP1_DT INT,
	@varKSnAP2_DT INT,
	@varKSnAP3_DT INT,

	@varKSnSGU_KT INT,
	@varKSnKBK_KT INT,
	@varKSnEKR_KT INT,
	@varKSnDEP_KT INT,
	@varKSnSUB_KT INT,
	@varKSnEMP_KT INT,
	@varKSnNOMEN_KT INT,
	@varKSnINV_KT INT,
	@varKSnKAU_KT INT,
	@varKSnDEP_ACC_KT INT,
	@varKSnTMC_KT INT,
	@varKSnINDATE_KT DATETIME,
	@varKSnAP1_KT INT,
	@varKSnAP2_KT INT,
	@varKSnAP3_KT INT,

	@varKSnSumma NUMERIC(28,4),
	@varKSnG2_LINK  INT,
	@varKScG2_NAME  VARCHAR(254),
	@varKSnG2_ECON_OPER INT,
	@varKSnG2_ORDERS INT,
	@varKSnGAP_ACCOUNT_DT INT,
	@varKSnGAP_ACCOUNT_KT INT,
	@varKSnLINK_GP2 INT,
	@varKSnLINK_ACC_DT INT,
	@varKSnLINK_ACC_KT INT,
	@varKSLINK_DOC INT,
	@varKSxRet INT,
	@varKSnDEP_LINK INT,
	@varKSnRowCount INT
	

DECLARE G2_CUR CURSOR LOCAL STATIC READ_ONLY FOR
	SELECT LINK, NAME, ECON_OPER, ORDERS FROM dbo.G_PROV2 WHERE LINK_UP = @varKSnTYP_LINK

IF @varKSnLINK_GP1 IS NULL
	RETURN -1	

IF @varKSnLINK_MOL IS NULL
	SET @varKSnLINK_MOL = 0

IF @varKSdCALC_DATE IS NULL
	SELECT @varKSdCALC_DATE = WORKDATE FROM USER_INFO

IF @varKSpcSOU_CODE IS NULL OR @varKSpcSOU_CODE = ''
	SET @varKSpcSOU_CODE = '0'

-- Вычисление организации для ЦБ
SELECT TOP 1 @varKSnDEP_LINK = G.DEP 
FROM G_PROV G,  G_PROV1 G1 
WHERE G1.LINK = @varKSnLINK_GP1 AND G.LINK = G1.LINK_UP

--SELECT LINK, NAME, ECON_OPER, ORDERS FROM G_PROV2 WHERE LINK_UP = @varKSnTYP_LINK

OPEN G2_CUR
FETCH NEXT FROM G2_CUR INTO @varKSnG2_LINK, @varKScG2_NAME, @varKSnG2_ECON_OPER, @varKSnG2_ORDERS
WHILE @@FETCH_STATUS = 0
BEGIN
	SELECT GAP.* 
	INTO #GAP_CUR
	FROM dbo.G_PROV_AP GAP
	WHERE GAP.LINK_UP = @varKSnG2_LINK

	SELECT @varKSnGAP_ACCOUNT_DT = ACCOUNT, @varKSnSGU_DT = SGU,
			@varKSnKBK_DT = KBK,
			@varKSnEKR_DT = EKR,
			@varKSnDEP_DT = DEP,
			@varKSnSUB_DT = SUB,
			@varKSnEMP_DT = EMP,
			@varKSnNOMEN_DT = NOMEN,
			@varKSnINV_DT = INV,
			@varKSnKAU_DT = KAU,
			@varKSnDEP_ACC_DT = DEP_ACC,
			@varKSnTMC_DT = TMC,
			@varKSnINDATE_DT = INDATE,
			@varKSnAP1_DT = AP1,
			@varKSnAP2_DT = AP2,
			@varKSnAP3_DT = AP3
	FROM #GAP_CUR WHERE DB_KR = 0

	IF @@ROWCOUNT = 0
		SELECT @varKSnGAP_ACCOUNT_DT = NULL, @varKSnSGU_DT = NULL,
			@varKSnKBK_DT = NULL,
			@varKSnEKR_DT = NULL,
			@varKSnDEP_DT = NULL,
			@varKSnSUB_DT = NULL,
			@varKSnEMP_DT = NULL,
			@varKSnNOMEN_DT = NULL,
			@varKSnINV_DT = NULL,
			@varKSnKAU_DT = NULL,
			@varKSnDEP_ACC_DT = NULL,
			@varKSnTMC_DT = NULL,
			@varKSnINDATE_DT = NULL,
			@varKSnAP1_DT = NULL,
			@varKSnAP2_DT = NULL,
			@varKSnAP3_DT = NULL

	SELECT @varKSnGAP_ACCOUNT_KT = ACCOUNT, @varKSnSGU_KT = SGU,
			@varKSnKBK_KT = KBK,
			@varKSnEKR_KT = EKR,
			@varKSnDEP_KT = DEP,
			@varKSnSUB_KT = SUB,
			@varKSnEMP_KT = EMP,
			@varKSnNOMEN_KT = NOMEN,
			@varKSnINV_KT = INV,
			@varKSnKAU_KT = KAU,
			@varKSnDEP_ACC_KT = DEP_ACC,
			@varKSnTMC_KT = TMC,
			@varKSnINDATE_KT = INDATE,
			@varKSnAP1_KT = AP1,
			@varKSnAP2_KT = AP2,
			@varKSnAP3_KT = AP3
	FROM #GAP_CUR WHERE DB_KR = 1

	IF @@ROWCOUNT = 0
		SELECT @varKSnGAP_ACCOUNT_KT = NULL, @varKSnSGU_KT = NULL,
			@varKSnKBK_KT = NULL,
			@varKSnEKR_KT = NULL,
			@varKSnDEP_KT = NULL,
			@varKSnSUB_KT = NULL,
			@varKSnEMP_KT = NULL,
			@varKSnNOMEN_KT = NULL,
			@varKSnINV_KT = NULL,
			@varKSnKAU_KT = NULL,
			@varKSnDEP_ACC_KT = NULL,
			@varKSnTMC_KT = NULL,
			@varKSnINDATE_KT = NULL,
			@varKSnAP1_KT = NULL,
			@varKSnAP2_KT = NULL,
			@varKSnAP3_KT = NULL


	SELECT TOP 1 
		SA.cSource,
		SA.cSinth,
		SA.cAnalit,
		SA.cUser,
		SA.CODE,
		ART.* 
	INTO #REST_OS
	FROM dbo.ARestTableByDate(@varKSdCALC_DATE, default) ART, S_ACCOUNTS SA, S_ACCOUNTS SAT
	WHERE ART.DEP_LINK = @varKSnDEP_LINK AND ART.NOMEN = @varKSnLINK_INV AND ART.ACCOUNT = SA.LINK AND SA.cSinth = SAT.cSinth AND (SAT.LINK = @varKSnGAP_ACCOUNT_DT OR SAT.LINK = @varKSnGAP_ACCOUNT_KT)
		AND (@varKSnLINK_MOL = 0 OR ART.EMP = @varKSnLINK_MOL)
	ORDER BY SA.cSinth

	SET @varKSnRowCount = @@ROWCOUNT

	IF @varKSnRowCount = 1
		SELECT 	@varKScSOU_CODE = cSource,
			@varKSnKBK = KBK,
			@varKSnEKR = EKR,

			@varKSnDEP = DEP,
			@varKSnSUB = dbo.SubdivisionLink (@varKSdCALC_DATE, SUB),
			@varKSnEMP = EMP,
			@varKSnNOMEN = NOMEN,
			@varKSnINV = INV,
			@varKSnKAU = KAU,
			@varKSnDEP_ACC = DEP_ACC,
			@varKSnTMC = TMC,
			@varKSnAP1 = AP1,
			@varKSnAP2 = AP2,
			@varKSnAP3 = AP3,
			@varKSnINDATE = INDATE,
			@varKSnSumma = CASE
						WHEN (D_QUANTITY - K_QUANTITY) = 0 THEN (D_SUMMA - K_SUMMA)
							ELSE (D_SUMMA - K_SUMMA) / (D_QUANTITY - K_QUANTITY) 
					END * @varKSnQTY
		FROM #REST_OS ROS
	ELSE
		SELECT @varKScSOU_CODE = @varKSpcSOU_CODE,
			@varKSnKBK = NULL,
			@varKSnEKR = NULL,
			@varKSnDEP = NULL,
			@varKSnSUB = NULL,
			@varKSnEMP = @varKSnLINK_MOL,
			@varKSnNOMEN = @varKSnLINK_INV,
			@varKSnINV = NULL,
			@varKSnKAU = NULL,
			@varKSnDEP_ACC = NULL,
			@varKSnTMC = NULL,
			@varKSnAP1 = NULL,
			@varKSnAP2 = NULL,
			@varKSnAP3 = NULL,
			@varKSnINDATE = NULL,
		@varKSnSumma = 0

	IF @varKSnSumma = 0
	  BEGIN
		FETCH NEXT FROM G2_CUR INTO @varKSnG2_LINK, @varKScG2_NAME, @varKSnG2_ECON_OPER, @varKSnG2_ORDERS
		DROP TABLE #GAP_CUR
		DROP TABLE #REST_OS
		CONTINUE
	  END 

--select @varKSnNOMEN, @varKSnSumma

	SELECT 		
			@varKSnKBK_DT = ISNULL(@varKSnKBK, @varKSnKBK_DT),
			@varKSnEKR_DT = ISNULL(@varKSnEKR, @varKSnEKR_DT),
			@varKSnDEP_DT = ISNULL(@varKSnDEP, @varKSnDEP_DT),
			@varKSnSUB_DT = ISNULL(@varKSnSUB, @varKSnSUB_DT),
			@varKSnEMP_DT = ISNULL(@varKSnEMP, @varKSnEMP_DT),
			@varKSnNOMEN_DT = ISNULL(@varKSnNOMEN, @varKSnNOMEN_DT),
			@varKSnINV_DT = ISNULL(@varKSnINV, @varKSnINV_DT),
			@varKSnKAU_DT = ISNULL(@varKSnKAU, @varKSnKAU_DT),
			@varKSnDEP_ACC_DT = ISNULL(@varKSnDEP_ACC, @varKSnDEP_ACC_DT),
			@varKSnTMC_DT = ISNULL(@varKSnTMC, @varKSnTMC_DT),
			@varKSnINDATE_DT = ISNULL(@varKSnINDATE, @varKSnINDATE_DT),
			@varKSnAP1_DT = ISNULL(@varKSnAP1, @varKSnAP1_DT),
			@varKSnAP2_DT = ISNULL(@varKSnAP2, @varKSnAP2_DT),
			@varKSnAP3_DT = ISNULL(@varKSnAP3, @varKSnAP3_DT),

			@varKSnKBK_KT = ISNULL(@varKSnKBK, @varKSnKBK_KT),
			@varKSnEKR_KT = ISNULL(@varKSnEKR, @varKSnEKR_KT),
			@varKSnDEP_KT = ISNULL(@varKSnDEP, @varKSnDEP_KT),
			@varKSnSUB_KT = ISNULL(@varKSnSUB, @varKSnSUB_KT),
			@varKSnEMP_KT = ISNULL(@varKSnEMP, @varKSnEMP_KT),
			@varKSnNOMEN_KT = ISNULL(@varKSnNOMEN, @varKSnNOMEN_KT),
			@varKSnINV_KT = ISNULL(@varKSnINV, @varKSnINV_KT),
			@varKSnKAU_KT = ISNULL(@varKSnKAU, @varKSnKAU_KT),
			@varKSnDEP_ACC_KT = ISNULL(@varKSnDEP_ACC, @varKSnDEP_ACC_KT),
			@varKSnTMC_KT = ISNULL(@varKSnTMC, @varKSnTMC_KT),
			@varKSnINDATE_KT = ISNULL(@varKSnINDATE, @varKSnINDATE_KT),
			@varKSnAP1_KT = ISNULL(@varKSnAP1, @varKSnAP1_KT),
			@varKSnAP2_KT = ISNULL(@varKSnAP2, @varKSnAP2_KT),
			@varKSnAP3_KT = ISNULL(@varKSnAP3, @varKSnAP3_KT)

	SELECT @varKSLINK_DOC = LINK_UP FROM G_PROV1 WHERE LINK = @varKSnLINK_GP1


	IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE LINK = @varKSnGAP_ACCOUNT_DT AND cSinth IN ('101','102','103', '105', '201'))
		  IF @varKSnLINK_INV IS NOT NULL AND @varKSnLINK_INV <> 0
			SELECT @varKSnLINK_ACC_DT = SA.LINK
			FROM NOMENCLATURE N,  GROUP_INV GI, S_ACCOUNTS SA
			WHERE N.LINK = @varKSnLINK_INV AND GI.LINK = N.GROUP_INV AND SA.LINK = GI.ACCOUNT
		  ELSE
			SELECT @varKSnLINK_ACC_DT = ACCOUNT FROM #REST_OS
	ELSE
		SET @varKSnLINK_ACC_DT = @varKSnGAP_ACCOUNT_DT

	IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE LINK = @varKSnGAP_ACCOUNT_KT AND cSinth IN ('101','102','103', '105', '201'))
		  IF @varKSnLINK_INV IS NOT NULL AND @varKSnLINK_INV <> 0
			SELECT @varKSnLINK_ACC_KT = SA.LINK
			FROM NOMENCLATURE N,  GROUP_INV GI, S_ACCOUNTS SA
			WHERE N.LINK = @varKSnLINK_INV AND GI.LINK = N.GROUP_INV AND SA.LINK = GI.ACCOUNT
		  ELSE
			SELECT @varKSnLINK_ACC_KT = ACCOUNT FROM #REST_OS
	ELSE
		SET @varKSnLINK_ACC_KT = @varKSnGAP_ACCOUNT_KT


	SELECT TOP 1 @varKSnLINK_ACC_DT = SA2.LINK FROM S_ACCOUNTS SA1, S_ACCOUNTS SA2 WHERE SA1.LINK = @varKSnLINK_ACC_DT 
		AND SA2.ZABALANS = SA1.ZABALANS
		AND SA2.cAnalit = SA1.cAnalit
		AND ((LEN(SA1.cSinth) = 3 AND SA1.cSinth = SA2.cSinth) OR (LEN(SA1.cSinth) < 3 AND SA2.cSinth LIKE (RTRIM(SA1.cSinth) + '%') ))
		AND SA2.cUser = SA1.cUser
		AND SA2.cSource = @varKScSOU_CODE
	IF @@ROWCOUNT <> 1
		SET @varKSnLINK_ACC_DT = @varKSnGAP_ACCOUNT_DT

	SELECT TOP 1 @varKSnLINK_ACC_KT = SA2.LINK FROM S_ACCOUNTS SA1, S_ACCOUNTS SA2 WHERE SA1.LINK = @varKSnLINK_ACC_KT 
		AND SA2.ZABALANS = SA1.ZABALANS
		AND SA2.cAnalit = SA1.cAnalit
		AND ((LEN(SA1.cSinth) = 3 AND SA1.cSinth = SA2.cSinth) OR (LEN(SA1.cSinth) < 3 AND SA2.cSinth LIKE (RTRIM(SA1.cSinth) + '%') ))
		AND SA2.cUser = SA1.cUser
		AND SA2.cSource = @varKScSOU_CODE
	IF @@ROWCOUNT <> 1
		SET @varKSnLINK_ACC_KT = @varKSnGAP_ACCOUNT_KT

	print 'Операция2 Дт ' + str(isnull(@varKSnLINK_ACC_DT,0)) + ' Кт '  + str(isnull(@varKSnLINK_ACC_KT,0))


	IF @varKSnSGU_DT IS NULL 
--	OR NOT EXISTS(SELECT * FROM S_ACCOUNTS_SGU S, KOSGU K WHERE S.ACCOUNT = @varKSnLINK_ACC_DT AND S.LINK_SGU = K.LINK AND K.LINK = @varKSnSGU_DT AND DB_KR = 0)
		SELECT TOP 1 @varKSnSGU_DT = K.LINK FROM S_ACCOUNTS_SGU S, KOSGU K WHERE S.ACCOUNT = @varKSnLINK_ACC_DT AND S.LINK_SGU = K.LINK AND K.DB_KR = 0

	IF @varKSnSGU_KT IS NULL 
--	OR NOT EXISTS(SELECT * FROM S_ACCOUNTS_SGU S, KOSGU K WHERE S.ACCOUNT = @varKSnLINK_ACC_KT AND S.LINK_SGU = K.LINK AND K.LINK = @varKSnSGU_KT AND DB_KR = 1)
		SELECT TOP 1 @varKSnSGU_KT = K.LINK FROM S_ACCOUNTS_SGU S, KOSGU K WHERE S.ACCOUNT = @varKSnLINK_ACC_KT AND S.LINK_SGU = K.LINK AND K.DB_KR = 1



	IF NOT EXISTS(SELECT * FROM S_ACCOUNTS WHERE LINK IN (@varKSnGAP_ACCOUNT_DT, @varKSnGAP_ACCOUNT_KT) AND KSU = CONVERT(TINYINT,1))
		SET @varKSnQTY = 0

	SET @varKSnLINK_GP2 = NULL

	SELECT TOP 1 @varKScG2_NAME = ISNULL(RTRIM(@varKScG2_NAME) + ' ', '') + 'Номенклатура:' + RTRIM(CODE) + ' ' + RTRIM(NAME) FROM NOMENCLATURE WHERE LINK = @varKSnLINK_INV

	EXEC @varKSxRet = X_UPDATE_G_PROV2 @varKSnLINK_GP2 OUTPUT, @varKSnLINK_GP1, NULL,
		@varKSnSumma, @varKSnQTY, 0, @varKScG2_NAME, @varKSnG2_ECON_OPER,  @varKSnG2_ORDERS
	IF @varKSxRet <> 0
		RETURN @varKSxRet
	IF @varKSnLINK_GP2 IS NULL
		RETURN -3	

	IF @varKSnLINK_ACC_DT IS NOT NULL AND @varKSnLINK_ACC_DT > 0
	  BEGIN
		IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE p_KASSA = 1  AND LINK = @varKSnLINK_ACC_DT)
		  SET @varKSnEKR_DT = @varKSnSGU_DT

		SELECT @varKSnEKR_DT = ANALIT_EKR FROM S_ACCOUNTS WHERE LINK = @varKSnLINK_ACC_DT AND p_EKR = 1

		EXEC @varKSxRet = X_UPDATE_G_PROV_AP @varKSnLINK_GP2, 0, @varKSnLINK_ACC_DT, @varKSnKBK_DT, @varKSnEKR_DT, @varKSnDEP_DT,
			@varKSnSUB_DT, @varKSnEMP_DT, @varKSnNOMEN_DT, @varKSnINV_DT, @varKSnKAU_DT, @varKSnDEP_ACC_DT, @varKSnTMC_DT, @varKSnINDATE_DT, @varKSnAP1_DT, @varKSnAP2_DT, @varKSnAP3_DT, @varKSnSGU_DT
		IF @varKSxRet <> 0
			RETURN @varKSxRet
	  END
	
	
	IF @varKSnLINK_ACC_KT IS NOT NULL AND @varKSnLINK_ACC_KT > 0
	  BEGIN
		IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE p_KASSA = 1  AND LINK = @varKSnLINK_ACC_KT)
		  SET @varKSnEKR_KT = @varKSnSGU_KT

		SELECT @varKSnEKR_KT = ANALIT_EKR FROM S_ACCOUNTS WHERE LINK = @varKSnLINK_ACC_KT AND p_EKR = 1

		EXEC @varKSxRet = X_UPDATE_G_PROV_AP @varKSnLINK_GP2, 1, @varKSnLINK_ACC_KT, @varKSnKBK_KT, @varKSnEKR_KT, @varKSnDEP_KT,
			@varKSnSUB_KT, @varKSnEMP_KT, @varKSnNOMEN_KT, @varKSnINV_KT, @varKSnKAU_KT, @varKSnDEP_ACC_KT, @varKSnTMC_KT, @varKSnINDATE_KT, @varKSnAP1_KT, @varKSnAP2_KT, @varKSnAP3_KT, @varKSnSGU_KT
		IF @varKSxRet <> 0
			RETURN @varKSxRet
	  END

	DROP TABLE #REST_OS
	DROP TABLE #GAP_CUR
	FETCH NEXT FROM G2_CUR INTO @varKSnG2_LINK, @varKScG2_NAME, @varKSnG2_ECON_OPER, @varKSnG2_ORDERS
END

CLOSE G2_CUR
DEALLOCATE G2_CUR

RETURN 0

GO

GRANT EXECUTE ON dbo.[PV_SAVE_G_PROV2_MENU_REQ] TO PUBLIC

GO

--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RSA_RSV_1_PERS_UCH_SZV]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RSA_RSV_1_PERS_UCH_SZV]

GO

-- Пример вызова exec [dbo].RSA_RSV_1_PERS_UCH_SZV '20140401', '20140630', 13488 , 2,  2561
CREATE PROCEDURE dbo.RSA_RSV_1_PERS_UCH_SZV
	@dDate1 DATETIME,
	@dDate2 DATETIME,
	@LINK_DEP int = NULL,
	@REP TINYINT = 0, 
	@VARILSF INT = null
AS BEGIN

	declare @DEP_LINK int
	exec dbo.xd_whats_zb @DEP_LINK output

	SET @DEP_LINK = COALESCE(@LINK_DEP,@DEP_LINK)

   DECLARE @nYEAR INT, @nMONTH1 INT, @nMONTH2 INT, @nMONTH3 INT
	
	SELECT 
		@nYEAR = YEAR(@dDATE1),
		@nMONTH1 = MONTH(@dDATE1),
		@nMONTH2 = MONTH(@dDATE1)+1,
		@nMONTH3 = MONTH(@dDATE1)+2

	DECLARE @ATR_PERS_UCH INT
	SET @ATR_PERS_UCH  = (SELECT DBO.RN_GET_ATR_VALUE(@VARILSF, 'REPORTS_ATR_PERS_UCH'))

	SELECT * into #docs FROM   dbo.SA_SZV4_PACHKA P 
	WHERE
	p.link_dep = @DEP_LINK and p.link = @ATR_PERS_UCH 
	
	INSERT INTO #docs
	SELECT * 
	FROM   dbo.SA_SZV4_PACHKA P 
	WHERE
	p.link_dep = @DEP_LINK and p.year_begin = year(@dDate1) and month_end <= month(@dDate2) and p.type = 1 and vid_kor <> 1
	/*AND p.[per_edt] < p.[per] *//*AND p.YEAR_EDT >= 2014*/ AND P.LINK_ISHOD = @ATR_PERS_UCH


	--Округление каждой строчки таблицы
	DECLARE @ROUND_TYPE tinyint, @ROUND_LEN tinyint
	Set @ROUND_TYPE = dbo.sa_get_option_by_code('SA_SZV4_OPT2')
	Set @ROUND_LEN = (case when @ROUND_TYPE <= 1 then 2 else 0 end)
	Set @ROUND_TYPE = (case when @ROUND_TYPE = 3 then 1 else 0 end)

	--Округление только итогов
	DECLARE @IT_ROUND_TYPE tinyint
	Set @IT_ROUND_TYPE = dbo.sa_get_option_by_code('SA_SZV4_OPT5')
	
	----- общие сведения
	Select
		[YEAR] = ISNULL(CASE WHEN year_begin >= 2013 THEN year_begin ELSE NULL END ,0),
		[CODE] = K.CODE,
		[PER] = ISNULL(CASE WHEN year_begin >= 2013 THEN PER ELSE NULL END ,0),
		[PER10] = ISNULL(CASE WHEN year_begin = 2013 THEN PER ELSE NULL END ,0),
		[TYPE] = P.vid_kor,
		[PER_EDT] = ISNULL(PER_EDT,0),
		[YEAR_EDT] = ISNULL(YEAR_EDT,0),
		[NGROUP] = S.pachka,
		[PFNUMBER] = PF_NUM,
		[T_DOG] = s.forma,
		LINK_FACE,
		NUM = ROW_NUMBER() OVER (PARTITION BY LINK_FACE ORDER BY s.forma),
		[FM],
		[IM],
		[OT],
		[ADDRESS] = [ADDRESS],
		[INC_M1] = s1.INCOME_M1,
		[B_BEF_M1] = s1.BASE_BEFORE_M1,
		[B_AFT_M1] = s1.BASE_AFTER_M1, 
		[INC_M2] = s1.INCOME_M2,
		[B_BEF_M2] = s1.BASE_BEFORE_M2,
		[B_AFT_M2] = s1.BASE_AFTER_M2,	
		[INC_M3] = s1.INCOME_M3,
		[B_BEF_M3] = s1.BASE_BEFORE_M3,
		[B_AFT_M3] = s1.BASE_AFTER_M3,
		[INC_T1M1] = s1.INCOME_T1_M1,
		[INC_T2M1] = s1.INCOME_T2_M1,
		[INC_T1M2] = s1.INCOME_T1_M2,
		[INC_T2M2] = s1.INCOME_T2_M2,
		[INC_T1M3] = s1.INCOME_T1_M3,
		[INC_T2M3] = s1.INCOME_T2_M3, 
		[INSUR] = COALESCE(S.sum_doh,0), --Это сумма начисленных взносов на страхов. часть
		[INSUR1] = COALESCE(S.INSUR,0), --Это сумма уплаченных взносов на страхов. часть
		[GAIN] = COALESCE(S.GAIN,0), --Это сумма начисленных взносов на накопит. часть
		[GAIN1] = COALESCE(S.DOP,0), --Это сумма уплаченных взносов на накопит. часть
		[DOP] = COALESCE(S.DOP,0),
		[ID_EX] = ST.orders,
		[DATE_BEGIN] = date1,
		[DATE_END] = date2,
		dper_vn_m = coalesce(s.dper_vn_m,0),
		dper_vn_d = coalesce(s.dper_vn_d,0),
		dper_oz_m = coalesce(s.dper_oz_m,0),
		dper_oz_d = coalesce(s.dper_oz_d,0),
		[TU_CODE] = f_ter_usl,
		[OS_CODE] = f_osob_usl,
		osob_usl,
		OSOB_SPO = LTRIM(RTRIM(ST.OSOB_SPO)),
		[EX_CODE] = is_osnov,
		f_is_dop,
		[P_CODE] = ud_osnov,
		f_ud_dop,
		DATE_DOC = [date],
		dep_PFNUM = d.PFNUMBER,
		FNAME = 'PFR-700-Y-' + CONVERT(VARCHAR(4),year_begin) + '-ORG-' + LTRIM(RTRIM(d.PFNUMBER)) + '-DCK-' + REPLACE(str(S.pachka,5),' ','0') + '-DPT-000000-DCK-00000.XML'	
	INTO #SZV_ALL
	FROM
		dbo.SA_SZV4_PACHKA P INNER JOIN dbo.SA_SZV4_SVEDENIA S ON P.link = S.link
		inner join SZV4_SVEDENIA s1 on s1.link = s.link1
		INNER JOIN dbo.SA_PFR_KATEG K ON K.LINK = S.LINK_KATEG AND year_begin BETWEEN YBEG AND YEND	
		LEFT JOIN dbo.SA_SZV4_STAZH ST ON S.link1 = ST.link
		inner join departments d on d.link = p.link_dep 
	WHERE
		P.link in (select link from #DOCS)
		and P.proverka = 1
		and p.link_dep = @DEP_LINK
	ORDER BY
		[TYPE], K.CODE, s.forma, S.pachka, S.orders, ST.orders
		
--- нумирация пачек исходных и корректирующих сведений
declare @MAX_PACHKA_ISHOD  int,@MIN_PACHKA_ISHOD int,  @MIN_PACHKA_KORR int,  
		@ID int

select @MAX_PACHKA_ISHOD = max(NGROUP),
		@MIN_PACHKA_ISHOD = min(NGROUP),
		@MIN_PACHKA_KORR = (select min(NGROUP) FROM #SZV_ALL WHERE TYPE <> 1)
		FROM #SZV_ALL WHERE TYPE = 1

IF @MIN_PACHKA_ISHOD = @MIN_PACHKA_KORR

BEGIN 
	declare @Cur cursor , @GR int , @FNAME varchar(100)
	set @ID = 1
	SET @Cur = CURSOR FORWARD_ONLY
	FOR 
		select ngroup,FNAME  from #SZV_ALL WHERE TYPE <> 1 group by ngroup,FNAME
	OPEN @Cur
	FETCH NEXT FROM @Cur INTO @GR, @FNAME
	
	WHILE (@@fetch_status <> -1)
	BEGIN
		
		IF (@@fetch_status <> -2)
		BEGIN	

			UPDATE #SZV_ALL
				set NGROUP = @MAX_PACHKA_ISHOD+@ID --, t.[cGRP] =  '00'+ (@MAX_PACHKA_ISHOD+@ID)
			where ngroup = @GR AND FNAME = @FNAME and TYPE <> 1
				
			set @ID = @ID+1	
		end
		FETCH NEXT FROM @Cur INTO @GR , @FNAME
	end

CLOSE @Cur
DEALLOCATE @Cur

END 

UPDATE t
	SET  FNAME=  'PFR-700-Y-' + CONVERT(VARCHAR(4),[year]) + '-ORG-' + LTRIM(RTRIM(dep_PFNUM)) + '-DCK-' + REPLACE(str(NGROUP,5),' ','0') + '-DPT-000000-DCK-00000.XML'	
	from #SZV_ALL t  WHERE TYPE <> 1

----------------------------
SELECT * INTO #SZV_SUM FROM
(SELECT 
	RN = ROW_NUMBER() OVER (PARTITION BY LINK_FACE, CODE, T_DOG, [TYPE] ORDER BY T_DOG),
	CODE,
	LINK_FACE,
	[PFNUMBER],
	T_DOG,
	INC_M1,
	B_BEF_M1,
	B_AFT_M1,
	INC_M2,
	B_BEF_M2,
	B_AFT_M2,
	INC_M3,
	B_BEF_M3,
	B_AFT_M3,		
	per,
	[year],
	[TYPE],
	per_edt,
	year_edt,
	INSUR	
FROM 
	#SZV_ALL 
) T WHERE RN = 1	

-----------
DECLARE @PREDEL NUMERIC(18,2)
SET @PREDEL = ISNULL((SELECT MIN(PREDEL) FROM dbo.DICTIONARY_RANGE_PF WHERE WAY_CALC = 6 AND TARIF = 1 AND [DATE] >= dbo.ConvertDMY2Date(1,1,YEAR(@dDate1))),0)
-----------
SELECT 
	LINK_FACE, [PFNUMBER], CODE, per, [year], [TYPE], per_edt, year_edt, INSUR = SUM(INSUR)
INTO 
	#SZV_PC 		
FROM 
	(
	SELECT 
		A.LINK_FACE, A.[PFNUMBER], A.CODE, A.T_DOG, A.per, A.[year], A.[TYPE], A.per_edt, A.year_edt, 
		INSUR = CASE WHEN MIN(B_AFT_M1) + MIN(B_AFT_M2) + MIN(B_AFT_M3) <> 0 THEN
					MIN(B_BEF_M1 * PERCENT1 / 100) + MIN(B_BEF_M2 * PERCENT1 / 100) + MIN(B_BEF_M3 * PERCENT1 / 100)
				ELSE
					MIN(INSUR)
				END				
	FROM 
		#SZV_ALL A INNER JOIN dbo.SA_PFR_KATEG B ON A.CODE = B.CODE AND [year] BETWEEN YBEG AND YEND
			INNER JOIN 
			(
				SELECT 
					TARIF, PERCENT1
				FROM 
					dbo.DICTIONARY_RANGE_PF D
				WHERE
					WAY_CALC = 6 AND PREDEL = @PREDEL
					AND [DATE] = (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE_PF D1 WHERE D1.TARIF = D.TARIF AND ISNULL(D1.SPECO,0) = ISNULL(D.SPECO,0) AND WAY_CALC = 6 AND DATE < @dDate1 ORDER BY [DATE] DESC) 
			) C ON C.TARIF = B.LINK2 
	GROUP BY
		A.LINK_FACE, A.[PFNUMBER], A.CODE, A.T_DOG, A.per, A.[year], A.[TYPE], A.per_edt, A.year_edt
	) T
GROUP BY
	LINK_FACE, [PFNUMBER], CODE, per, [year], [TYPE], per_edt, year_edt

-----------------------------------------------------

	IF @REP = 0 
	BEGIN 
		SELECT
			CODE = CONVERT(VARCHAR(14), [PFNUMBER]),
			COL1 = CONVERT(VARCHAR(14),[PFNUMBER]),
			COL2 = CONVERT(varchar(100),[FM]),
			COL3 = CONVERT(varchar(100),[IM]),
			COL4 = CONVERT(varchar(100),[OT]),
			COL5 = CONVERT(varchar(14),[PFNUMBER]),
			COL6 = [TYPE],
			COL7 = [NGROUP],
			COL8 = [FNAME],
			COL9 = CONVERT(VARCHAR(10), DATE_DOC, 104)
		FROM
			#SZV_ALL
		GROUP BY [TYPE],[T_DOG],[FM],[IM],[OT],[PFNUMBER], [NGROUP], [FNAME],DATE_DOC
		ORDER BY
			[TYPE],[T_DOG],[FM],[IM],[OT]
		
	END

	IF @REP = 1 
	BEGIN 	

	/*****************************************************/
	-- Собираем информацию по Исходным пачками
	/*****************************************************/
		create table #TMP1(CODE int,col1 int,   COL2 varchar(14), COL3 varchar(100), COL4 varchar (4), COL5 varchar (4), COL6 numeric(18,2), COL7 numeric(18,2), 
						   COL8 numeric(18,2), COL9 numeric(18,2), COL10 varchar(1), COL11 varchar(4), COL12 varchar(15), COL13 varchar(1), COL14 varchar(4),
						   COL15 int, COL16 varchar(100), COL17 varchar(100), COL18 varchar(100), COL19 int, COL20 int, COL21 numeric(18,2), COL22 numeric(18,2), COL23 numeric(18,2),
						   COL24 int, COL25 int, COL26 numeric(18,2), COL27 numeric(18,2), COL28 numeric(18,2),
						   COL29 int, COL30 int, COL31 numeric(18,2), COL32 numeric(18,2), COL33 numeric(18,2),
						   COL34 int, COL35 int, COL36 numeric(18,2), COL37 numeric(18,2), COL38 numeric(18,2),
						   COL39 int, COL40 int, COL41 numeric(18,2), COL42 numeric(18,2), COL43 numeric(18,2), COL44 numeric(18,2))
		
		
		/***************************************/
		-- для подсчета суммы с начала года по конец отчетного периода  
			
			
			------
	
			--- Обьявляем даты
			DECLARE @BYearDate	datetime
			SET @BYearDate = dbo.DateBeginOfYear (@dDate1)

			DECLARE @nYEAR1 INT, @nMONTH_1 INT, @nMONTH_2 INT, @nMONTH_3 INT
			SELECT 
				@nYEAR1 = YEAR(@dDate1),
				@nMONTH_1 = MONTH(@dDate1),
				@nMONTH_2 = MONTH(@dDate1)+1,
				@nMONTH_3 = MONTH(@dDate1)+2
			
			DECLARE @BDate datetime, @EndDate datetime, @EDate DATETIME, @EndYear datetime
			Set @EndYear = dbo.DateEndOfYear(@dDate1)
			SELECT @BDate = @dDate1, @EndDate = @dDate2
			SET @EDate = dateadd(year,1,convert(varchar, YEAR(@BDate))+'0101')
	
			--Фактическая база для договорников
			SELECT 
				GT.PERS_LINK, MONTH(G.[DATE]) AS MONTH_BASE, F.ENVD, SUMMA_BASE = sum(GT.SUMMA_BASE)
			INTO #DGH_FAKT_BASE
			FROM 
				dbo.DOCUMENTS_DGH G INNER JOIN dbo.DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
				INNER JOIN dbo.SAL_SFIN F on F.LINK = GT.LINK_VKR
			WHERE 
				FLAG_JC = 1
				AND GT.WAY_CALC  = 6
				AND YEAR(G.[DATE]) = @nYEAR1
				AND MONTH(G.[DATE]) <= @nMONTH_3
				--AND LINK_DEP = @DEP_LINK 
			GROUP BY 
				GT.PERS_LINK, MONTH(G.[DATE]), F.ENVD

			SELECT  PERS_LINK, MONTH_BASE, SUMMA_BASE = SUM(SUMMA_BASE)
			INTO #DGH_FAKT_BASE1
			FROM #DGH_FAKT_BASE
			GROUP BY PERS_LINK, MONTH_BASE


			-- Журнал операций 
			CREATE TABLE #CALCULATE_JURNAL (LINK_PAYS INT, PERIOD_BEGIN DATETIME, LINK_DOC INT, PERS_LINK INT, LINK_VKR INT, LINK_EKR INT, LINK_EMPL INT, SUMMA NUMERIC(18,2), WAY_CALC TINYINT , SPECO int)
			INSERT INTO #CALCULATE_JURNAL (LINK_PAYS, PERIOD_BEGIN, LINK_DOC, PERS_LINK, LINK_VKR, LINK_EKR, LINK_EMPL, SUMMA,way_calc , SPECO)
			SELECT CJ.LINK_PAYS, CJ.PERIOD_BEGIN, CJ.LINK_DOC, CJ.PERS_LINK, CJ.LINK_VKR, cj.LINK_EKR, CJ.LINK_EMPL, SUMMA = SUM(CJ.SUMMA), p.way_calc , SPECO
			FROM dbo.CALCULATE_JURNAL CJ INNER JOIN dbo.PAYS P ON  CJ.LINK_PAYS = p.link
			WHERE
				Year(period_begin) = @nYEAR1 
				and Month(period_begin) <= @nMONTH_3 
				and CJ.LINK_DEP = @DEP_LINK
			GROUP BY
				cj.LINK_PAYS, cj.PERIOD_BEGIN, cj.LINK_DOC, cj.PERS_LINK, cj.LINK_VKR, cj.LINK_EKR, cj.LINK_EMPL, P.WAY_CALC,cj.SPECO
						
			--
			Declare @StBase2 table (link int)
			Insert into @StBase2 (link)
			select distinct link_pays from tax_ref where link_tax = (select top 1 link from pays where object = 3 and way_calc = 6)
			
			DECLARE @LINK_EKR213 INT
			SET @LINK_EKR213 = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '213')

			DECLARE @ESN_213 INT --Начислять страховые взносы на доходы с 213 ЭКР                                                    
			SET @ESN_213 = dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_5')
			
							
			------	у кого была инвалидность в заданном периоде
			SELECT DISTINCT PERS_LINK 
			INTO #PERS_INV
			FROM dbo.PERS_INVALID I
			WHERE COALESCE(I.DATE_BEGIN,@BYearDate) <= @EndYear AND COALESCE(I.DATE_END,@EndYear) >= @BYearDate

			------	у кого есть расчеты по доп тарифам со спец оценками в заданном периоде 
			SELECT DISTINCT sd.LINK, DOP = (CASE when S.COD_POS_SPISOK is NOT NULL then 1 else 2 end) , SPO = isnull(s4.code,'')
			INTO #EMPL_DT
			FROM DBO.KU_EMPL_PLACING SD
				left JOIN (select * from STAFF WHERE dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@nMONTH_3,@nYEAR1)) BETWEEN DATE_BEGIN AND DATE_END  ) S ON S.LINK_up = SD.STAFF_HEAD AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@nMONTH_3,@nYEAR1 )) BETWEEN S.DATE_BEGIN AND S.DATE_END
				LEFT JOIN SA_SZV4_SPR  s4 ON  s4.link = s.COD_SPO_USL_TRUD AND s4.spr_code = 'SPO_USL_TRUDA'
				WHERE 
					(S.COD_POS_SPISOK is NOT NULL OR S.COD_POS_SPISOK2 is NOT NULL) 

			--Заготовка для #SALARY_SUM2
			CREATE TABLE #SALARY_SUM_DATA (PERS_LINK INT,t_dog TINYINT, PERIOD_BEGIN DATETIME, SUMMA_ALL NUMERIC(18,2), SUMMA_NO NUMERIC(18,2), SUMMA_ALL_I NUMERIC(18,2), SUMMA_NO_I NUMERIC(18,2), SUMMA_ALL_E NUMERIC(18,2), SUMMA_NO_E NUMERIC(18,2), INV TINYINT 
					, SUMMA_NO_D1 NUMERIC(18,2), SUMMA_NO_D2 NUMERIC(18,2),    
				SUM_NO_D1_O4 NUMERIC(18,2) ,SUM_NO_D1_B34 NUMERIC(18,2) ,SUM_NO_D1_B33 NUMERIC(18,2),SUM_NO_D1_B32 NUMERIC(18,2), SUM_NO_D1_B31 NUMERIC(18,2),
					SUM_NO_D2_O4 NUMERIC(18,2) ,SUM_NO_D2_B34 NUMERIC(18,2) ,SUM_NO_D2_B33 NUMERIC(18,2),SUM_NO_D2_B32 NUMERIC(18,2), SUM_NO_D2_B31 NUMERIC(18,2) 
					)

			--Сотрудники
			INSERT INTO #SALARY_SUM_DATA (PERS_LINK, t_dog, PERIOD_BEGIN, SUMMA_ALL, SUMMA_NO, SUMMA_ALL_I, SUMMA_NO_I, SUMMA_ALL_E, SUMMA_NO_E, INV 
					, SUMMA_NO_D1, SUMMA_NO_D2,SUM_NO_D1_O4,SUM_NO_D1_B34,SUM_NO_D1_B33, SUM_NO_D1_B32, SUM_NO_D1_B31,
					SUM_NO_D2_O4,SUM_NO_D2_B34,SUM_NO_D2_B33, SUM_NO_D2_B32, SUM_NO_D2_B31
					)
			select
				E.PERS_LINK, 
				TDOG = 1,
				CJ.PERIOD_BEGIN,
				SUMMA_ALL = SUM(SUMMA),
				SUMMA_NO = SUM(CASE WHEN B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0 THEN SUMMA ELSE 0 END), --на которые не начисляются страховые взносы
				SUMMA_ALL_I = 0,
				SUMMA_NO_I = 0,
				SUMMA_ALL_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END),
				SUMMA_NO_E = SUM(CASE WHEN F.ENVD = 1 AND (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) THEN SUMMA ELSE 0 END),
				INV =  dbo.is_invalid(e.PERS_LINK,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) ,
				SUMMA_NO_D1 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and ED.DOP = 1 AND isnull(SPO,'') ='' THEN SUMMA ELSE 0 END),
				SUMMA_NO_D2 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and ED.DOP = 2 and  isnull(SPO,'') ='' THEN SUMMA ELSE 0 END),
				SUM_NO_D1_O4 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='О4'  THEN SUMMA ELSE 0 END),
				SUM_NO_D1_B34 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.4' THEN SUMMA ELSE 0 END),
				SUM_NO_D1_B33 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.3' THEN SUMMA ELSE 0 END), 
				SUM_NO_D1_B32 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.2' THEN SUMMA ELSE 0 END), 
				SUM_NO_D1_B31 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.1' THEN SUMMA ELSE 0 END),	
				SUM_NO_D2_O4 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='О4' THEN SUMMA ELSE 0 END),
				SUM_NO_D2_B34 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.4' THEN SUMMA ELSE 0 END),
				SUM_NO_D2_B33 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.3' THEN SUMMA ELSE 0 END), 
				SUM_NO_D2_B32 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.2' THEN SUMMA ELSE 0 END), 
				SUM_NO_D2_B31 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.1' THEN SUMMA ELSE 0 END)
			from 
			#CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
			INNER JOIN dbo.SAL_SFIN F on F.LINK = CJ.LINK_VKR
			INNER JOIN DBO.EMPL E ON E.LINK = CJ.LINK_EMPL
			LEFT JOIN @StBase2 B ON B.LINK = cj.LINK_PAYS
			/*LEFT JOIN #PERS_INV I ON I.PERS_LINK = E.PERS_LINK*/
			LEFT JOIN #EMPL_DT ED ON ED.link = CJ.LINK_EMPL
			
			where 	
				P.[OBJECT] = 1
				AND EXISTS(SELECT LINK_FACE FROM #SZV_all WHERE link_face = E.PERS_LINK )
			GROUP BY
				E.PERS_LINK/*, I.PERS_LINK*/, CJ.PERIOD_BEGIN

			--Договрники
			INSERT INTO #SALARY_SUM_DATA (PERS_LINK, t_dog, PERIOD_BEGIN, SUMMA_ALL, SUMMA_NO, SUMMA_ALL_I, SUMMA_NO_I, SUMMA_ALL_E, SUMMA_NO_E, INV 
					)
			select
				CJ.PERS_LINK, 
				T_DOG = 2,
				CJ.PERIOD_BEGIN,
				SUMMA_ALL = SUM(SUMMA),
				SUMMA_NO = SUM(SUMMA) - ISNULL((SELECT SUM(B1.SUMMA_BASE) FROM #DGH_FAKT_BASE1 B1 WHERE B1.PERS_LINK = CJ.PERS_LINK AND B1.MONTH_BASE = Month(CJ.PERIOD_BEGIN)),0), --на которые не начисляются страховые взносы
				SUMMA_ALL_I = 0,
				SUMMA_NO_I = 0,
				SUMMA_ALL_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END),
				SUMMA_NO_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END)  - ISNULL((SELECT SUM(B.SUMMA_BASE) FROM #DGH_FAKT_BASE B WHERE B.PERS_LINK = CJ.PERS_LINK AND B.MONTH_BASE = Month(CJ.PERIOD_BEGIN) AND B.ENVD = 1),0),
				INV =  dbo.is_invalid(CJ.PERS_LINK,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN))
					
			from 
				#CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
				INNER JOIN dbo.SAL_SFIN F on F.LINK = CJ.LINK_VKR
				INNER JOIN DBO.PERSON P1 ON P1.LINK = CJ.PERS_LINK
				--LEFT JOIN #PERS_INV I ON I.PERS_LINK = CJ.PERS_LINK
			where 	
				P.[OBJECT] = 1
			GROUP BY
				CJ.PERS_LINK,/* I.PERS_LINK,*/ CJ.PERIOD_BEGIN, P1.RESIDENT, p1.birthdate

				--корректировка в соотвествие с тем, в каком месяце кто был инвалидом
			UPDATE D SET 
				SUMMA_ALL_I = (CASE WHEN EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_ALL ELSE 0 END), 
				SUMMA_NO_I = (CASE WHEN EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_NO ELSE 0 END), 
				SUMMA_ALL_E = (CASE WHEN NOT EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_ALL_E ELSE 0 END), 
				SUMMA_NO_E = (CASE WHEN NOT EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_NO_E ELSE 0 END)

			FROM #SALARY_SUM_DATA D
			WHERE INV =2 --которые имели инвалидность в каком-то месяце периода	

----------<<<<<<<<< #SPR_ESN для определения скидочной части (кусок ИЗ РСВ)
		create table #SPR_ESN1 ([MONTH_BASE] TINYINT, SUMMA_BASE numeric(12,2) default 0.00, DED_M numeric(12,2) default 0.00, INV_M numeric(12,2) default 0.00, SUMMA numeric(12,2) default 0.00, WAY_CALC int default 0.00, REF_PHYS_PERS int default 0 , PF_NUM VARCHAR (14), FACE_GROUP TINYINT, I TINYINT, E TINYINT , SP VARCHAR(4))

		Insert InTo #SPR_ESN1 ([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS , PF_NUM, FACE_GROUP, I, E, SP)
		Select [MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0 THEN 3 
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END ) AS FACE_GROUP, 
			dbo.is_invalid(REF_PHYS_PERS,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH_BASE,@nYEAR1))),
			F.ENVD,
			SP = isnull(s4.code,'')
		from dbo.SA_ESN_VIEW(@nYEAR1, @nMONTH_3, @LINK_DEP, 0) S
			inner join PERSON P on S.REF_PHYS_PERS = P.link
			inner join dbo.SAL_SFIN F on F.LINK = S.LINK_VKR
			LEFT JOIN SA_SZV4_SPR  s4 ON  s4.link = S.SPECO AND s4.spr_code = 'SPO_USL_TRUDA'
		WHERE  WAY_CALC not in (5)

		--Суммы по договорникам
		INSERT INTO #SPR_ESN1 
			([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, PF_NUM, FACE_GROUP, I, E)
		SELECT 
			MONTH(G.[DATE]) AS MONTH_BASE, GT.SUMMA_BASE, 0, 0, GT.SUMMA, GT.WAY_CALC, GT.PERS_LINK, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0  THEN 3
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END) AS FACE_GROUP , 
			dbo.is_invalid(GT.PERS_LINK,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,G.[MONTH],@nYEAR1))),
			F.ENVD
		FROM 
			DOCUMENTS_DGH G INNER JOIN DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
			inner join PERSON P on GT.PERS_LINK = P.link
			inner join dbo.SAL_SFIN F on F.LINK = GT.LINK_VKR
		WHERE 
			FLAG_JC = 1
			AND GT.WAY_CALC  not in (5)
			AND YEAR(G.[DATE]) = @nYEAR1
			AND MONTH(G.[DATE]) <= @nMONTH_3
			AND LINK_DEP = @DEP_LINK


		DELETE FROM #SPR_ESN1
		WHERE  EXISTS (SELECT * FROM dbo.KJ_PERS_PENSION K WHERE K.PERS_LINK = REF_PHYS_PERS AND K.CHECK_SZV = 0)
---------->>>>>>>>>>

		--DECLARE @PREDEL NUMERIC(18,2)
		--SET @PREDEL = (SELECT TOP 1 PREDEL FROM DICTIONARY_RANGE WHERE TARIF = 1 AND YEAR([DATE]) =  @nYEAR1)

		--Данные о начисленной зарплате
		SELECT 
			PERS_LINK,
			T_DOG = MIN(T_DOG),
			SUMMA_ALL = SUM(SUMMA_ALL), SUMMA_NO = SUM(SUMMA_NO), 
			SUMMA_ALL_I = SUM(SUMMA_ALL_I), SUMMA_NO_I = SUM(SUMMA_NO_I),
			SUMMA_ALL_E = SUM(SUMMA_ALL_E), SUMMA_NO_E = SUM(SUMMA_NO_E),
			SUMMA_ALL_DO_I = (CASE WHEN SUM(SUMMA_ALL_I) > @PREDEL THEN  @PREDEL ELSE (SUM(SUMMA_ALL_I) - SUM(SUMMA_NO_I)) END ),
			SUMMA_ALL_DO = (CASE WHEN SUM(SUMMA_ALL) > @PREDEL THEN  @PREDEL ELSE (SUM(SUMMA_ALL) - SUM(SUMMA_NO)) END ),
			SUMMA_ALL_AFTER = (CASE WHEN SUM(SUMMA_ALL - SUMMA_ALL_I - SUMMA_NO - SUMMA_NO_I)  > @PREDEL THEN  SUM(SUMMA_ALL) - @PREDEL ELSE 0 END ),
			SUMMA_ALL_AFTER_I = (CASE WHEN SUM(SUMMA_ALL_I) > @PREDEL THEN  SUM(SUMMA_ALL) - @PREDEL ELSE 0 END )
			,BASE_DOG = SUM(CASE WHEN T_DOG = 2 THEN SUMMA_ALL - SUMMA_NO ELSE 0 END)
		INTO #SALARY_SUM2
		FROM #SALARY_SUM_DATA s 
		GROUP BY
			PERS_LINK

-----------<<<<<<<<</*СВЕДЕНИЯ ЗА ПЕРИОД , ПО КОРРЕКТИРУЮЩИМ*/
		
		DECLARE @nYEAR1_K INT, @nMONTH_1_K INT, @nMONTH_2_K INT, @nMONTH_3_K INT	
		select 
   		@nYEAR1_K = YEAR_EDT,
   		@nMONTH_1_K = /*case when YEAR_EDT  between '2011' and '2013' then (*/case  PER_EDT when 1 then  1 when 2 then  4 when 3 then  7 when 4 then  10 else 10 end/*)
					when  YEAR_EDT >= '2014'  then (case  PER_EDT when 3 then  1 when 6 then  4 when 9 then  7 else  10 end)
					else null end */
		from #SZV_ALL	
		where [TYPE] = 2
		and YEAR_EDT >=2014
							 
		select @nMONTH_2_K = @nMONTH_1_K+1,
				@nMONTH_3_K = @nMONTH_1_K +2	

		DECLARE @BYearDate_K	datetime , @EndYear_K datetime
		SET @BYearDate_K = dbo.DateBeginOfYear (@nYEAR1_K+'0101')
		Set @EndYear_K = dbo.DateEndOfYear(@BYearDate_K)

		--Фактическая база для договорников
		SELECT 
			GT.PERS_LINK, MONTH(G.[DATE]) AS MONTH_BASE, F.ENVD, SUMMA_BASE = sum(GT.SUMMA_BASE)
		INTO #DGH_FAKT_BASE_K
		FROM 
			dbo.DOCUMENTS_DGH G INNER JOIN dbo.DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
			INNER JOIN dbo.SAL_SFIN F on F.LINK = GT.LINK_VKR
		WHERE 
			FLAG_JC = 1
			AND GT.WAY_CALC  = 6
			AND YEAR(G.[DATE]) = @nYEAR1_K
			AND MONTH(G.[DATE]) <= @nMONTH_3_K
			--AND LINK_DEP = @DEP_LINK 
		GROUP BY 
			GT.PERS_LINK, MONTH(G.[DATE]), F.ENVD

			SELECT  PERS_LINK, MONTH_BASE, SUMMA_BASE = SUM(SUMMA_BASE)
			INTO #DGH_FAKT_BASE1_K
			FROM #DGH_FAKT_BASE_K
			GROUP BY PERS_LINK, MONTH_BASE


			-- Журнал операций 
			CREATE TABLE #CALCULATE_JURNAL_K (LINK_PAYS INT, PERIOD_BEGIN DATETIME, LINK_DOC INT, PERS_LINK INT, LINK_VKR INT, LINK_EKR INT, LINK_EMPL INT, SUMMA NUMERIC(18,2), WAY_CALC TINYINT , SPECO int)
			INSERT INTO #CALCULATE_JURNAL_K (LINK_PAYS, PERIOD_BEGIN, LINK_DOC, PERS_LINK, LINK_VKR, LINK_EKR, LINK_EMPL, SUMMA,way_calc , SPECO)
			SELECT CJ.LINK_PAYS, CJ.PERIOD_BEGIN, CJ.LINK_DOC, CJ.PERS_LINK, CJ.LINK_VKR, cj.LINK_EKR, CJ.LINK_EMPL, SUMMA = SUM(CJ.SUMMA), p.way_calc , SPECO
			FROM dbo.CALCULATE_JURNAL CJ INNER JOIN dbo.PAYS P ON  CJ.LINK_PAYS = p.link
			WHERE
				Year(period_begin) = @nYEAR1_K 
				and Month(period_begin) <= @nMONTH_3_K
				and CJ.LINK_DEP = @DEP_LINK
			GROUP BY
				cj.LINK_PAYS, cj.PERIOD_BEGIN, cj.LINK_DOC, cj.PERS_LINK, cj.LINK_VKR, cj.LINK_EKR, cj.LINK_EMPL, P.WAY_CALC,cj.SPECO
						
						
			------	у кого была инвалидность в заданном периоде
			SELECT DISTINCT PERS_LINK 
			INTO #PERS_INV_K
			FROM dbo.PERS_INVALID I
			WHERE COALESCE(I.DATE_BEGIN,@BYearDate_K) <= @EndYear_K AND COALESCE(I.DATE_END,@EndYear_K) >= @BYearDate_K

			------	у кого есть расчеты по доп тарифам со спец оценками в заданном периоде 
			SELECT DISTINCT sd.LINK, DOP = (CASE when S.COD_POS_SPISOK is NOT NULL then 1 else 2 end) , SPO = isnull(s4.code,'')
			INTO #EMPL_DT_K
			FROM DBO.KU_EMPL_PLACING SD
				left JOIN (select * from STAFF WHERE dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@nMONTH_3_K,@nYEAR1_K)) BETWEEN DATE_BEGIN AND DATE_END  ) S ON S.LINK_up = SD.STAFF_HEAD AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@nMONTH_3_K,@nYEAR1_K )) BETWEEN S.DATE_BEGIN AND S.DATE_END
				LEFT JOIN SA_SZV4_SPR  s4 ON  s4.link = s.COD_SPO_USL_TRUD AND s4.spr_code = 'SPO_USL_TRUDA'
				WHERE 
					(S.COD_POS_SPISOK is NOT NULL OR S.COD_POS_SPISOK2 is NOT NULL) 

			--Заготовка для #SALARY_SUM2
			CREATE TABLE #SALARY_SUM_DATA_K (PERS_LINK INT,t_dog TINYINT, PERIOD_BEGIN DATETIME, SUMMA_ALL NUMERIC(18,2), SUMMA_NO NUMERIC(18,2), SUMMA_ALL_I NUMERIC(18,2), SUMMA_NO_I NUMERIC(18,2), SUMMA_ALL_E NUMERIC(18,2), SUMMA_NO_E NUMERIC(18,2), INV TINYINT 
					, SUMMA_NO_D1 NUMERIC(18,2), SUMMA_NO_D2 NUMERIC(18,2),    
				SUM_NO_D1_O4 NUMERIC(18,2) ,SUM_NO_D1_B34 NUMERIC(18,2) ,SUM_NO_D1_B33 NUMERIC(18,2),SUM_NO_D1_B32 NUMERIC(18,2), SUM_NO_D1_B31 NUMERIC(18,2),
					SUM_NO_D2_O4 NUMERIC(18,2) ,SUM_NO_D2_B34 NUMERIC(18,2) ,SUM_NO_D2_B33 NUMERIC(18,2),SUM_NO_D2_B32 NUMERIC(18,2), SUM_NO_D2_B31 NUMERIC(18,2) 
					)

			--Сотрудники
			INSERT INTO #SALARY_SUM_DATA_K (PERS_LINK, t_dog, PERIOD_BEGIN, SUMMA_ALL, SUMMA_NO, SUMMA_ALL_I, SUMMA_NO_I, SUMMA_ALL_E, SUMMA_NO_E, INV 
					, SUMMA_NO_D1, SUMMA_NO_D2,SUM_NO_D1_O4,SUM_NO_D1_B34,SUM_NO_D1_B33, SUM_NO_D1_B32, SUM_NO_D1_B31,
					SUM_NO_D2_O4,SUM_NO_D2_B34,SUM_NO_D2_B33, SUM_NO_D2_B32, SUM_NO_D2_B31
					)
			select
				E.PERS_LINK, 
				TDOG = 1,
				CJ.PERIOD_BEGIN,
				SUMMA_ALL = SUM(SUMMA),
				SUMMA_NO = SUM(CASE WHEN B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0 THEN SUMMA ELSE 0 END), --на которые не начисляются страховые взносы
				SUMMA_ALL_I = 0,
				SUMMA_NO_I = 0,
				SUMMA_ALL_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END),
				SUMMA_NO_E = SUM(CASE WHEN F.ENVD = 1 AND (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) THEN SUMMA ELSE 0 END),
				INV =  dbo.is_invalid(e.PERS_LINK,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) ,
				SUMMA_NO_D1 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and ED.DOP = 1 AND isnull(SPO,'') ='' THEN SUMMA ELSE 0 END),
				SUMMA_NO_D2 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and ED.DOP = 2 and  isnull(SPO,'') ='' THEN SUMMA ELSE 0 END),
				SUM_NO_D1_O4 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='О4'  THEN SUMMA ELSE 0 END),
				SUM_NO_D1_B34 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.4' THEN SUMMA ELSE 0 END),
				SUM_NO_D1_B33 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.3' THEN SUMMA ELSE 0 END), 
				SUM_NO_D1_B32 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.2' THEN SUMMA ELSE 0 END), 
				SUM_NO_D1_B31 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =1 AND SPO ='В3.1' THEN SUMMA ELSE 0 END),	
				SUM_NO_D2_O4 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='О4' THEN SUMMA ELSE 0 END),
				SUM_NO_D2_B34 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.4' THEN SUMMA ELSE 0 END),
				SUM_NO_D2_B33 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.3' THEN SUMMA ELSE 0 END), 
				SUM_NO_D2_B32 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.2' THEN SUMMA ELSE 0 END), 
				SUM_NO_D2_B31 = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) and CJ.LINK_EMPL = ED.link and DOP =2 AND SPO ='В3.1' THEN SUMMA ELSE 0 END)
			from 
			#CALCULATE_JURNAL_K CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
			INNER JOIN dbo.SAL_SFIN F on F.LINK = CJ.LINK_VKR
			INNER JOIN DBO.EMPL E ON E.LINK = CJ.LINK_EMPL
			LEFT JOIN @StBase2 B ON B.LINK = cj.LINK_PAYS
			/*LEFT JOIN #PERS_INV I ON I.PERS_LINK = E.PERS_LINK*/
			LEFT JOIN #EMPL_DT_K ED ON ED.link = CJ.LINK_EMPL
			
			where 	
				P.[OBJECT] = 1
				AND EXISTS(SELECT LINK_FACE FROM #SZV_all WHERE link_face = E.PERS_LINK )
			GROUP BY
				E.PERS_LINK/*, I.PERS_LINK*/, CJ.PERIOD_BEGIN

			--Договрники
			INSERT INTO #SALARY_SUM_DATA (PERS_LINK, t_dog, PERIOD_BEGIN, SUMMA_ALL, SUMMA_NO, SUMMA_ALL_I, SUMMA_NO_I, SUMMA_ALL_E, SUMMA_NO_E, INV 
					)
			select
				CJ.PERS_LINK, 
				T_DOG = 2,
				CJ.PERIOD_BEGIN,
				SUMMA_ALL = SUM(SUMMA),
				SUMMA_NO = SUM(SUMMA) - ISNULL((SELECT SUM(B1.SUMMA_BASE) FROM #DGH_FAKT_BASE1 B1 WHERE B1.PERS_LINK = CJ.PERS_LINK AND B1.MONTH_BASE = Month(CJ.PERIOD_BEGIN)),0), --на которые не начисляются страховые взносы
				SUMMA_ALL_I = 0,
				SUMMA_NO_I = 0,
				SUMMA_ALL_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END),
				SUMMA_NO_E = SUM(CASE WHEN F.ENVD = 1 THEN SUMMA ELSE 0 END)  - ISNULL((SELECT SUM(B.SUMMA_BASE) FROM #DGH_FAKT_BASE B WHERE B.PERS_LINK = CJ.PERS_LINK AND B.MONTH_BASE = Month(CJ.PERIOD_BEGIN) AND B.ENVD = 1),0),
				INV =  dbo.is_invalid(CJ.PERS_LINK,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN))
					
			from 
				#CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
				INNER JOIN dbo.SAL_SFIN F on F.LINK = CJ.LINK_VKR
				INNER JOIN DBO.PERSON P1 ON P1.LINK = CJ.PERS_LINK
				--LEFT JOIN #PERS_INV I ON I.PERS_LINK = CJ.PERS_LINK
			where 	
				P.[OBJECT] = 1
			GROUP BY
				CJ.PERS_LINK,/* I.PERS_LINK,*/ CJ.PERIOD_BEGIN, P1.RESIDENT, p1.birthdate

				--корректировка в соотвествие с тем, в каком месяце кто был инвалидом
			UPDATE D SET 
				SUMMA_ALL_I = (CASE WHEN EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_ALL ELSE 0 END), 
				SUMMA_NO_I = (CASE WHEN EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_NO ELSE 0 END), 
				SUMMA_ALL_E = (CASE WHEN NOT EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_ALL_E ELSE 0 END), 
				SUMMA_NO_E = (CASE WHEN NOT EXISTS (SELECT * FROM dbo.PERS_INVALID I1 WHERE I1.PERS_LINK = D.PERS_LINK AND dbo.DateEndOfMonth(PERIOD_BEGIN) BETWEEN ISNULL(I1.DATE_BEGIN,PERIOD_BEGIN) AND  ISNULL(I1.DATE_END,dbo.DateEndOfMonth(PERIOD_BEGIN))) THEN SUMMA_NO_E ELSE 0 END)

			FROM #SALARY_SUM_DATA D
			WHERE INV =2 --которые имели инвалидность в каком-то месяце периода	

---------<<<<<<<<< #SPR_ESN_K (корректирующие) для определения скидочной части (кусок ИЗ РСВ)
		create table #SPR_ESN1_K ([MONTH_BASE] TINYINT, SUMMA_BASE numeric(12,2) default 0.00, DED_M numeric(12,2) default 0.00, INV_M numeric(12,2) default 0.00, SUMMA numeric(12,2) default 0.00, WAY_CALC int default 0.00, REF_PHYS_PERS int default 0 , PF_NUM VARCHAR (14), FACE_GROUP TINYINT, I TINYINT, E TINYINT , SP VARCHAR(4))

		Insert InTo #SPR_ESN1_K ([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS , PF_NUM, FACE_GROUP, I, E, SP)
		Select [MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0 THEN 3 
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END ) AS FACE_GROUP, 
			dbo.is_invalid(REF_PHYS_PERS,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH_BASE,@nYEAR1_K))),
			F.ENVD,
			SP = isnull(s4.code,'')
		from dbo.SA_ESN_VIEW(@nYEAR1_K, @nMONTH_3_K, @LINK_DEP, 0) S
			inner join PERSON P on S.REF_PHYS_PERS = P.link
			inner join dbo.SAL_SFIN F on F.LINK = S.LINK_VKR
			LEFT JOIN SA_SZV4_SPR  s4 ON  s4.link = S.SPECO AND s4.spr_code = 'SPO_USL_TRUDA'
		WHERE  WAY_CALC not in (5)

		--Суммы по договорникам
		INSERT INTO #SPR_ESN1_K 
			([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, PF_NUM, FACE_GROUP, I, E)
		SELECT 
			MONTH(G.[DATE]) AS MONTH_BASE, GT.SUMMA_BASE, 0, 0, GT.SUMMA, GT.WAY_CALC, GT.PERS_LINK, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0  THEN 3
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END) AS FACE_GROUP , 
			dbo.is_invalid(GT.PERS_LINK,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,G.[MONTH],@nYEAR1_K))),
			F.ENVD
		FROM 
			DOCUMENTS_DGH G INNER JOIN DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
			inner join PERSON P on GT.PERS_LINK = P.link
			inner join dbo.SAL_SFIN F on F.LINK = GT.LINK_VKR
		WHERE 
			FLAG_JC = 1
			AND GT.WAY_CALC  not in (5)
			AND YEAR(G.[DATE]) = @nYEAR1_K
			AND MONTH(G.[DATE]) <= @nMONTH_3_K
			AND LINK_DEP = @DEP_LINK


		DELETE FROM #SPR_ESN1_K
		WHERE  EXISTS (SELECT * FROM dbo.KJ_PERS_PENSION K WHERE K.PERS_LINK = REF_PHYS_PERS AND K.CHECK_SZV = 0)
---------->>>>>>>>>>

		DECLARE @PREDEL_K NUMERIC(18,2)
		SET @PREDEL_K = (SELECT TOP 1 PREDEL FROM DICTIONARY_RANGE WHERE TARIF = 1 AND YEAR([DATE]) =  @nYEAR1_K)

		--Данные о начисленной зарплате
		SELECT 
			PERS_LINK,
			T_DOG = MIN(T_DOG),
			/*MON = Month(PERIOD_BEGIN),*/ 
			SUMMA_ALL = SUM(SUMMA_ALL), SUMMA_NO = SUM(SUMMA_NO), 
			SUMMA_ALL_I = SUM(SUMMA_ALL_I), SUMMA_NO_I = SUM(SUMMA_NO_I),
			SUMMA_ALL_E = SUM(SUMMA_ALL_E), SUMMA_NO_E = SUM(SUMMA_NO_E),
			SUMMA_ALL_D =  ISNULL((select SUM(SUMMA_ALL) FROM  #SALARY_SUM_DATA WHERE PERS_LINK = s.PERS_LINK AND t_dog=2 ),0) ,
			SUMMA_ALL_DO_I = (CASE WHEN SUM(SUMMA_ALL_I) > @PREDEL THEN  @PREDEL ELSE (SUM(SUMMA_ALL_I) - SUM(SUMMA_NO_I)) END ),
			SUMMA_ALL_DO = (CASE WHEN SUM(SUMMA_ALL) > @PREDEL THEN  @PREDEL ELSE (SUM(SUMMA_ALL) - SUM(SUMMA_NO)) END ),
			SUMMA_ALL_AFTER = (CASE WHEN SUM(SUMMA_ALL - SUMMA_ALL_I)  > @PREDEL THEN  SUM(SUMMA_ALL) - @PREDEL ELSE 0 END ),
			SUMMA_ALL_AFTER_I = (CASE WHEN SUM(SUMMA_ALL_I)  > @PREDEL THEN  SUM(SUMMA_ALL) - @PREDEL ELSE 0 END )
			,BASE_DOG = SUM(CASE WHEN T_DOG = 2 THEN SUMMA_ALL - SUMMA_NO ELSE 0 END)					
											
		INTO #SALARY_SUM2_K
		FROM #SALARY_SUM_DATA_K s 
		GROUP BY
			pers_link--, T_DOG--,Month(PERIOD_BEGIN)


		DROP TABLE #SALARY_SUM_DATA	
		DROP TABLE #DGH_FAKT_BASE
		DROP TABLE #DGH_FAKT_BASE1
		DROP TABLE #PERS_INV
		DROP TABLE #CALCULATE_JURNAL
		DROP TABLE #EMPL_DT		

		DROP TABLE #SALARY_SUM_DATA_K	
		DROP TABLE #DGH_FAKT_BASE_K
		DROP TABLE #DGH_FAKT_BASE1_K
		DROP TABLE #PERS_INV_K
		DROP TABLE #CALCULATE_JURNAL_K
		DROP TABLE #EMPL_DT_K				

		
		/*Корректирующие сведения по физ лицам для печати раздела 6.6*/
		SELECT year_edt = p.YEAR_EDT, 
				PER_EDT = p.PER_EDT, 
				link_dep = p.link_dep,
				link_pers = s.link_pers,
				Link_kateg = S.Link_kateg,
				pachka = s.pachka
		INTO #tmp_pers_r1
		FROM 	dbo.SA_SZV4_PACHKA P 
				INNER JOIN dbo.SZV4_SVEDENIA S ON P.link = S.link_up 															
		where
			P.link in (select link from #DOCS WHERE vid_kor = 2)
			and P.proverka = 1
			and P.vid_kor > 1
			and p.link_dep = @DEP_LINK


		CREATE TABLE #tmp_pers_kor_sum_R1 (link INT  , [date] DATETIME, YEAR_degin INT , per INT , vid_kor int, link_dep INT , proverka INT  , CODE VARCHAR(5), link_pers INT , 
										sum_doh NUMERIC(18,2), sum_str NUMERIC(18,2), sum_nak NUMERIC(18,2),sum_dop NUMERIC(18,2) , pachka int) 
	
		DECLARE @Cur_R1 CURSOR, @link_R1 int ,@LINK_pers_R1 INT, @year_edt_R1 INT , @per_edt_R1 INT , @Link_kateg_R1 INT ,@pachka_R1 int
		SET @Cur_R1 = CURSOR FORWARD_ONLY

		FOR SELECT LINK_pers, year_edt, per_edt, Link_kateg ,pachka FROM #tmp_pers_r1 ORDER by link_pers

		OPEN @Cur_R1
		FETCH NEXT FROM @Cur_R1 INTO @LINK_pers_R1, @year_edt_R1, @per_edt_R1 , @link_kateg_R1, @pachka_R1
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				
				
					SET @link_R1 = 0
					
					SELECT @link_R1 =max(pp.link)
					FROM SA_SZV4_PACHKA pp 
					INNER JOIN dbo.SZV4_SVEDENIA Ss ON ss.link_up = pp.link  
					WHERE  pp.proverka = 1 AND pp.vid_kor = 1 
										  AND pp.link_dep = @DEP_LINK 
										  AND pp.year_begin =@year_edt_R1  
										  AND pp.PER =@per_edt_R1 
										  AND @LINK_pers_R1 = ss.link_pers
										  AND @link_kateg_R1 = ss.link_kateg  
										  AND pp.date = (SELECT MAX(p1.[date]) FROM SA_SZV4_PACHKA p1 
																INNER JOIN dbo.SZV4_SVEDENIA S1 ON s1.link_up = p1.link  
																WHERE  pp.proverka = 1 AND p1.vid_kor = 1 
																					  AND p1.link_dep = @DEP_LINK 
																					  AND p1.year_begin =@year_edt_R1  
																					  AND p1.PER =@per_edt_R1 
																					  AND @LINK_pers_R1 = s1.link_pers
																					  AND @link_kateg_R1 = s1.link_kateg )
					
					INSERT INTO #tmp_pers_kor_sum_R1  (link, [date], YEAR_degin, per, vid_kor, link_dep, proverka , CODE, link_pers, 
										sum_doh, sum_str, sum_nak,sum_dop, pachka) 
					SELECT pp.link, pp.[date], pp.YEAR_begin, pp.per, pp.vid_kor, pp.link_dep, pp.proverka, CODE = k.code, ss.link_pers, 
										ss.sum_doh, ss.sum_str, ss.sum_nak,ss.sum_dop , pachka = @pachka_R1
					FROM SA_SZV4_PACHKA pp 
					INNER JOIN dbo.SZV4_SVEDENIA Ss ON ss.link_up = pp.link  
					INNER JOIN dbo.SA_PFR_KATEG K ON K.LINK = ss.LINK_KATEG AND pp.YEAR_begin BETWEEN YBEG AND YEND		
					WHERE pp.link = @link_R1 and pp.proverka = 1 
										 AND pp.vid_kor = 1 
										 AND pp.link_dep = @DEP_LINK 
										 AND pp.year_begin =@year_edt_R1  
										 AND pp.PER =@per_edt_R1 
										 AND ss.link_pers = @LINK_pers_R1
										 AND ss.link_kateg = @link_kateg_R1
										  

			END

			FETCH NEXT FROM @Cur_R1 INTO @LINK_pers_R1, @year_edt_R1, @per_edt_R1, @link_kateg_R1, @pachka_R1
		END

		CLOSE @Cur_R1
		DEALLOCATE @Cur_R1


		/******************* ИСХОДНЫЕ СВЕДЕНИЯ ********************/
							   
		DECLARE @Cur1 CURSOR, @CODE varchar(4), @TYPE tinyint , @T_DOG tinyint, @PFNUMBER VARCHAR (14) , @FM VARCHAR(100),@IM VARCHAR(100),@OT VARCHAR(100),
		@pf_num1 VARCHAR(14) , @CODE_old VARCHAR(4), @TYPE_OLD TINYINT, @nom_pp INT, @DATE DATETIME
		set @pf_num1 = ''
		set @CODE_old = '' 
		set @TYPE_OLD = 0
		set @nom_pp = 1

		SET @Cur1 = CURSOR FORWARD_ONLY
		FOR SELECT  [CODE],[TYPE],[PFNUMBER], [FM],[IM],[OT], MIN(DATE_BEGIN) AS DATE_BEGIN  
			FROM #SZV_ALL where [TYPE] = 1 --AND LINK_FACE = 565 
			GROUP BY [FM],[IM],[OT],[PFNUMBER],[TYPE],CODE
			ORDER BY [FM],[IM],[OT],[PFNUMBER],DATE_BEGIN
		OPEN @Cur1
		FETCH NEXT FROM @Cur1 INTO  @CODE,@TYPE/*,@T_DOG*/,@PFNUMBER,@FM,@IM,@OT, @DATE
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				--- Заполнение информации по первому коду категории сотрудника (нр , оои, пнэд)
				IF (/*@T_DOG = 1 and */ @PFNUMBER <> @pf_num1 ) 
				BEGIN
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE =  @nom_pp,
						   COL1 =  @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'400'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = CASE WHEN @CODE = 'ООИ' THEN ISNULL(SS.SUMMA_ALL_I,0) ELSE ISNULL(SS.SUMMA_ALL - SS.SUMMA_ALL_I,0) END,
						   COL7 = 
								CASE WHEN @CODE = 'ООИ' THEN
										(CASE WHEN
											(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL 
										THEN @PREDEL
										ELSE 
											(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											)
										END)	
									ELSE
										(CASE WHEN 
											( ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL 
										THEN @PREDEL
										ELSE 
											( ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) 
										END) 
								 END,
						   COL8 = ISNULL(SS.BASE_DOG,0),
						   COL9 = CASE WHEN @CODE = 'ООИ' THEN
										(CASE WHEN
											(ISNULL(SS.SUMMA_ALL_I,0) - ISNULL(SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL 
										THEN 
											(ISNULL(SS.SUMMA_ALL_I,0) - ISNULL(SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) - @PREDEL 
										ELSE 
											0
										END)	
									ELSE
										(CASE WHEN 
											(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL
										THEN 
											(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) - @PREDEL
										ELSE 
											0
										END) 
								 END,
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT), 
						   COL44 = isnull([INSUR],0)
					FROM #SZV_PC s LEFT JOIN #SALARY_SUM2 ss ON ss.pers_link = s.link_face
					WHERE 
						code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					
					select row_number() over (order by PER_EDT) as ID , 
							[PER_EDT] as k_PER_EDT, 
							YEAR_EDT as k_YEAR_EDT, 
							INSUR - (SELECT SUM(SUM_doh) FROM #tmp_pers_kor_sum_r1 WHERE CODE = 'НР' AND LINK_pers = s.link_face  )  as k_INSUR, 
							GAIN - (SELECT SUM(SUM_NAK) FROM #tmp_pers_kor_sum_r1 WHERE CODE = 'НР' AND LINK_pers = s.link_face  ) as k_GAIN, 
							PFNUMBER as k_PFNUMBER , 
							FM as k_FM 
					INTO #TMP01
					from  #SZV_ALL s
					WHERE  [TYPE] = 2 AND id_ex =1 and FM = @FM AND PFNUMBER = @PFNUMBER
			
					UPDATE #TMP1
					SET COL19 = (SELECT TOP 1 k_PER_EDT FROM #TMP01 where ID=1),
						COL20 = (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=1),
						COL21 = (CASE WHEN (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=1) >= '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=1)  ELSE 0 END ),
						COL22 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=1) < '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=1) ELSE 0 END ),
						COL23 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=1) < '2014' THEN (SELECT TOP 1 k_GAIN FROM #TMP01 where ID=1) ELSE 0 END ), 
						COL24 = (SELECT TOP 1 k_PER_EDT FROM #TMP01 where ID=2),
					    COL25 = (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=2), 
					    COL26 = (CASE WHEN (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=2) >= '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=2)  ELSE 0 END ), 
					    COL27 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=2) < '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=2) ELSE 0 END ), 
					    COL28 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=2) < '2014' THEN (SELECT TOP 1 k_GAIN FROM #TMP01 where ID=2) ELSE 0 END ),
					    COL29 = (SELECT TOP 1 k_PER_EDT FROM #TMP01 where ID=3),
					    COL30 = (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=3), 
					    COL31 = (CASE WHEN (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=3) >= '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=3)  ELSE 0 END ), 
					    COL32 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=3) < '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=3) ELSE 0 END ), 
					    COL33 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=3) < '2014' THEN (SELECT TOP 1 k_GAIN FROM #TMP01 where ID=3) ELSE 0 END ),
					    COL34 = (SELECT TOP 1 k_PER_EDT FROM #TMP01 where ID=4),
					    COL35 = (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=4), 
					    COL36 = (CASE WHEN (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=4) >= '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=4)  ELSE 0 END ), 
					    COL37 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=4) < '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=4) ELSE 0 END ), 
					    COL38 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=4) < '2014' THEN (SELECT TOP 1 k_GAIN FROM #TMP01 where ID=4) ELSE 0 END ),
					    COL39 = (SELECT TOP 1 k_PER_EDT FROM #TMP01 where ID=5),
					    COL40 = (SELECT TOP 1 k_YEAR_EDT FROM #TMP01 where ID=5), 
					    COL41 = (CASE WHEN (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=5) >= '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=5)  ELSE 0 END ), 
					    COL42 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=5) < '2014' THEN (SELECT TOP 1 k_INSUR FROM #TMP01 where ID=5) ELSE 0 END ), 
					    COL43 = (case when (select TOP 1 k_YEAR_EDT FROM #TMP01 where ID=5) < '2014' THEN (SELECT TOP 1 k_GAIN FROM #TMP01 where ID=5) ELSE 0 END )--,
					FROM #TMP1
					WHERE #TMP1.COL5 = @CODE 
						AND #TMP1.COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), '') 
						AND #TMP1.COL2 = @PFNUMBER and #TMP1.COL16 = @FM and #TMP1.COL17 = @IM and #TMP1.COL18 = @OT

					drop table #TMP01

					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14,COL15, COL16,COL17, COL18 , COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'401'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M1]),
						   COL7 = SUM([B_BEF_M1]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M1] ELSE 0 END),
						   COL9 = SUM([B_AFT_M1]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year],''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'402'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M2]),
						   COL7 = SUM([B_BEF_M2]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M2] ELSE 0 END),
						   COL9 = SUM([B_AFT_M2]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'403'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M3]),
						   COL7 = SUM([B_BEF_M3]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M3] ELSE 0 END),
						   COL9 = SUM([B_AFT_M3]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
				END
		
				--- Заполнение информации по следующему коду категории сотрудника (если за расчетный период у сотрудника была не одна категория)
				IF /*@T_DOG = 1 and*/  @PFNUMBER = @pf_num1 and @CODE <> @CODE_old	and  @TYPE = @TYPE_OLD
				BEGIN 

					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'410'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = CASE WHEN @CODE = 'ООИ' then ISNULL(SS.SUMMA_ALL_I,0) ELSE ISNULL(SS.SUMMA_ALL- SS.SUMMA_ALL_I,0) end,
						   COL7 = 
								CASE WHEN @CODE = 'ООИ' THEN
									--база по ООИ
									(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
									- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
									)
								ELSE
									--база по НР
									( (ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0)) - (ISNULL(SS.SUMMA_NO,0) -  ISNULL(SS.SUMMA_NO_I,0))
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
									)
								END
								- --сумма превышения
								CASE WHEN 
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) > @PREDEL
								THEN
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) - @PREDEL
								ELSE
									0
								END,	
														
						   COL8 = ISNULL(SS.BASE_DOG,0),

						   COL9 = 
								--сумма превышения
								CASE WHEN 
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) > @PREDEL
								THEN
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1 WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) - @PREDEL
								ELSE
									0
								END,
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   COL44 =  isnull([INSUR],0)
					FROM 
						#SZV_PC s LEFT JOIN #SALARY_SUM2 ss ON ss.pers_link = s.link_face
					WHERE 
						code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'411'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M1]),
						   COL7 = SUM([B_BEF_M1]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M1] ELSE 0 END),
						   COL9 = SUM([B_AFT_M1]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
						   
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'412'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M2]),
						   COL7 = SUM([B_BEF_M2]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M2] ELSE 0 END),
						   COL9 = SUM([B_AFT_M2]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'413'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M3]),
						   COL7 = SUM([B_BEF_M3]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M3] ELSE 0 END),
						   COL9 = SUM([B_AFT_M3]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
				END						

				--- заполняем пустые строки '410','411','412','413' 
			
				if not exists (select * from #tmp1 
								where COl2 = @PFNUMBER 
								and COL12 = (case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end)
								and COL4 = '410' ) AND NOT EXISTS (SELECT * FROM #SZV_ALL WHERE PFNUMBER = @PFNUMBER AND CODE != @CODE AND [TYPE] = 1) 
				begin 
						
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL(@PFNUMBER,''), 
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'410'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((SELECT TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),''), 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = '', 
						   COL14 = '',
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL(@PFNUMBER,''),
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'411'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),'') , 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = '', 
						   COL14 = '',
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL(@PFNUMBER,''), 
						 COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'412'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),'') , 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = '', 		
						   COL14 = '',
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1		
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp, 
						   COL2 = ISNULL(@PFNUMBER,''),
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'413'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),'') , 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = 'Исходная' and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = '', 
						   COL14 = '',
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1	
				
				end 

					set @pf_num1 = @PFNUMBER
					set @CODE_old = @CODE
					set @TYPE_OLD = @TYPE
			END

			FETCH NEXT FROM @Cur1 INTO @CODE,@TYPE/*,@T_DOG*/,@PFNUMBER,@FM,@IM,@OT, @DATE
		END

		CLOSE @Cur1
		DEALLOCATE @Cur1

		/*****************************************************/
		-- Собираем информацию по Кореектирующим/Отменяющим
		/*****************************************************/
		DECLARE @Cur2 CURSOR
		set @pf_num1 = ''
		set @CODE_old = '' 
		set @TYPE_OLD = 0
		set @nom_pp = (SELECT MAX(CODE) FROM #TMP1 WHERE COL12= 'Исходная') + 1 
		
		SET @Cur2 = CURSOR FORWARD_ONLY
		FOR SELECT  [CODE],[TYPE]/*,[T_DOG]*/,[PFNUMBER], [FM],[IM],[OT]  FROM #SZV_ALL where /*T_DOG = 1 and*/ [TYPE] != 1 AND YEAR_EDT >=2014 GROUP BY [FM],[IM],[OT],[PFNUMBER],[TYPE],CODE/*, [T_DOG]*/ ORDER BY [FM],[IM],[OT],[PFNUMBER],[TYPE],CODE/*, [T_DOG]*/
		OPEN @Cur2
		FETCH NEXT FROM @Cur2 INTO  @CODE,@TYPE/*,@T_DOG*/,@PFNUMBER,@FM,@IM,@OT
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				--- Заполнение информации по первому коду категории сотрудника (нр , оои, пнэд)
				IF (/*@T_DOG = 1 and */ @PFNUMBER <> @pf_num1 ) 
				BEGIN
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE =  @nom_pp,
						   COL1 =  @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'400'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = CASE WHEN @CODE = 'ООИ' THEN ISNULL(SS.SUMMA_ALL_I,0) ELSE ISNULL(SS.SUMMA_ALL - SS.SUMMA_ALL_I,0) END,
						   COL7 = 
								CASE WHEN @CODE = 'ООИ' THEN
										(CASE WHEN
											(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL_K 
										THEN @PREDEL_K
										ELSE 
											(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											)
										END)	
									ELSE
										(CASE WHEN 
											( ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL_K 
										THEN @PREDEL_K
										ELSE 
											( ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) 
										END) 
								 END,								 

						   COL8 = ISNULL(SS.BASE_DOG,0),

						   COL9 = CASE WHEN @CODE = 'ООИ' THEN
										(CASE WHEN
											(ISNULL(SS.SUMMA_ALL_I,0) - ISNULL(SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL_K 
										THEN 
											(ISNULL(SS.SUMMA_ALL_I,0) - ISNULL(SS.SUMMA_NO_I,0) 
											- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
											) - @PREDEL_K 
										ELSE 
											0
										END)	
									ELSE
										(CASE WHEN 
											(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) > @PREDEL_K
										THEN 
											(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
											- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
											) - @PREDEL_K
										ELSE 
											0
										END) 
								 END,
																			
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   COL44 = isnull([INSUR],0)
					FROM 
						#SZV_PC s LEFT JOIN #SALARY_SUM2_K ss ON ss.pers_link = s.link_face
					WHERE 
						code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER

					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14,COL15, COL16,COL17, COL18 , COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'401'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M1]),
						   COL7 = SUM([B_BEF_M1]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M1] ELSE 0 END),
						   COL9 = SUM([B_AFT_M1]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE  code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
										
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'402'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M2]),
						   COL7 = SUM([B_BEF_M2]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M2] ELSE 0 END),
						   COL9 = SUM([B_AFT_M2]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
										
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),	
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'403'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M3]),
						   COL7 = SUM([B_BEF_M3]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M3] ELSE 0 END),
						   COL9 = SUM([B_AFT_M3]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL(CONVERT(VARCHAR(1),[per_edt]), ''), 
						   COL14 = ISNULL(CONVERT(VARCHAR(4),[year_edt]), ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_SUM WHERE code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
					
					set @nom_pp = @nom_pp + 1
				END
					
				
				--- Заполнение информации по следующему коду категории сотрудника (если за расчетный период у сотрудника была не одна категория)
				IF /*@T_DOG = 1 and*/  @PFNUMBER = @pf_num1 and @CODE <> @CODE_old	and  @TYPE = @TYPE_OLD
				BEGIN 
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'410'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = CASE WHEN @CODE = 'ООИ' then ISNULL(SS.SUMMA_ALL_I,0) ELSE ISNULL(SS.SUMMA_ALL - SS.SUMMA_ALL_I,0) end,
						   COL7 = 
								CASE WHEN @CODE = 'ООИ' THEN
									--база по ООИ
									(ISNULL(SS.SUMMA_ALL_I - SS.SUMMA_NO_I,0) 
									- ( CONVERT(numeric(18,2),ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 2 AND ref_phys_pers = s.link_face) ,0) ))
									)
								ELSE
									--база по НР
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_ALL_I,0) - (ISNULL(SS.SUMMA_NO,0) - ISNULL(SS.SUMMA_NO_I,0))
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND I = 1 AND ref_phys_pers = s.link_face) ,0) ))
									)
								END
								- --сумма превышения
								CASE WHEN 
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) > @PREDEL_K
								THEN
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) - @PREDEL_K
								ELSE
									0
								END,
													
						   COL8 = ISNULL(SS.BASE_DOG,0),
						   
						   COL9 = 
								--сумма превышения
								CASE WHEN 
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) > @PREDEL_K
								THEN
									(ISNULL(SS.SUMMA_ALL,0) - ISNULL(SS.SUMMA_NO,0) 
									- ( CONVERT(numeric(18,2),ISNULL((SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN1_K WHERE WAY_CALC = 6 AND ref_phys_pers = s.link_face) ,0) ))
									) - @PREDEL_K
								ELSE
									0
								END,										
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM 
						#SZV_ALL s LEFT JOIN #SALARY_SUM2_K ss ON ss.pers_link = s.link_face
					WHERE 
						S.NUM = 1 AND code = @CODE and [TYPE] = @TYPE AND PFNUMBER = @PFNUMBER and FM = @FM					
					GROUP BY 
						[TYPE],CODE, [T_DOG],[FM],[IM],[OT],[PFNUMBER],[per],[year],[per_edt],[year_edt],[INSUR],[INC_M1],[INC_M2],[INC_M3],[B_BEF_M1],[B_BEF_M2],[B_BEF_M3], [B_AFT_M1],[B_AFT_M2],[B_AFT_M3],SS.SUMMA_ALL_I, SS.SUMMA_NO, SS.SUMMA_NO_I, SS.SUMMA_NO_E
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0),
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'411'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M1]),
						   COL7 = SUM([B_BEF_M1]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M1] ELSE 0 END),
						   COL9 = SUM([B_AFT_M1]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM 
						#SZV_ALL WHERE  code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY 
						[TYPE],CODE, [T_DOG],[FM],[IM],[OT],[PFNUMBER],[per],[year],[per_edt],[year_edt],[INSUR],[INC_M1],[INC_M2],[INC_M3],[B_BEF_M1],[B_BEF_M2],[B_BEF_M3], [B_AFT_M1],[B_AFT_M2],[B_AFT_M3]
					
					set @nom_pp = @nom_pp + 1
			
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'412'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M2]),
						   COL7 = SUM([B_BEF_M2]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M2] ELSE 0 END),
						   COL9 = SUM([B_AFT_M2]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						  COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_ALL WHERE code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
										
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL([PFNUMBER],0), 
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'413'),
						   COL5 = CONVERT(VARCHAR(4),@CODE),
						   COL6 = SUM([INC_M3]),
						   COL7 = SUM([B_BEF_M3]),
						   COL8 = SUM(CASE WHEN T_DOG = 2 THEN [B_BEF_M3] ELSE 0 END),
						   COL9 = SUM([B_AFT_M3]),
						   COL10 = ISNULL([per],''), 
						   COL11 = ISNULL([year], ''), 
						   COL12 = ISNULL((case WHEN [TYPE] = 1 then 'Исходная' when [TYPE] = 2 then 'Корректирующая' else 'Отменяющая' end ), ''), 
						   COL13 = ISNULL([per_edt], ''), 
						   COL14 = ISNULL([year_edt], ''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					FROM #SZV_ALL WHERE code = @CODE and [TYPE] = @TYPE /*and T_DOG = @T_DOG*/ AND PFNUMBER = @PFNUMBER
					GROUP BY [PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]
										
					set @nom_pp = @nom_pp + 1
				END						

				--- заполняем пустые строки '410','411','412','413' 
			
				if not exists (select * from #tmp1 
								where COL2 = @PFNUMBER 
								and COL12 = (case WHEN @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end)
								and COL4 = '410' ) AND NOT EXISTS (SELECT * FROM #SZV_ALL WHERE PFNUMBER = @PFNUMBER AND CODE != @CODE AND [TYPE] = 1) 
				begin 
						
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,	
						   COL2 = ISNULL(@PFNUMBER,''), 
						   COL3 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),
						   COL4 = CONVERT(VARCHAR(4),'410'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL((select TOP 1 COL13 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL14 = ISNULL((select TOP 1 COL14 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						 COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL(@PFNUMBER,''),
						   COL3 = CONVERT(VARCHAR(100), '1 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'411'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL((select TOP 1 COL13 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL14 = ISNULL((select TOP 1 COL14 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13,COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp,
						   COL2 = ISNULL(@PFNUMBER,''), 
						   COL3 = CONVERT(VARCHAR(100), '2 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'412'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL((select TOP 1 COL13 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 		
						   COL14 = ISNULL((select TOP 1 COL14 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
					
					set @nom_pp = @nom_pp + 1		
					
					INSERT INTO #TMP1 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15, COL16,COL17, COL18, COL44)
					SELECT CODE = @nom_pp,
						   COL1 = @nom_pp, 
						   COL2 = ISNULL(@PFNUMBER,''),
						   COL3 = CONVERT(VARCHAR(100), '3 месяц'),
						   COL4 = CONVERT(VARCHAR(4),'413'),
						   COL5 = CONVERT(VARCHAR(4),''),
						   COL6 = 0,
						   COL7 = 0,
						   COL8 = 0,
						   COL9 = 0,
						   COL10 = ISNULL((select TOP 1 COL10 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL11 = ISNULL((select TOP 1 COL11 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL12 = ISNULL((case WHEN @TYPE = 1 then 'Исходная' when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end), ''), 
						   COL13 = ISNULL((select TOP 1 COL13 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''), 
						   COL14 = ISNULL((select TOP 1 COL14 from #tmp1 where COl2 = @PFNUMBER and COL12 = (case when @TYPE = 2 then 'Корректирующая' else 'Отменяющая'end) and COL4 = '400'),''),
						   COL15 = @nom_pp,
						   COL16 = CONVERT(varchar(100),@FM),
						   COL17 = CONVERT(varchar(100),@IM),
						   COL18 = CONVERT(varchar(100),@OT),
						   0
						   
					
					set @nom_pp = @nom_pp + 1	
				
				end 

					set @pf_num1 = @PFNUMBER
					set @CODE_old = @CODE
					set @TYPE_OLD = @TYPE
			END

			FETCH NEXT FROM @Cur2 INTO @CODE,@TYPE/*,@T_DOG*/,@PFNUMBER,@FM,@IM,@OT
		END

		CLOSE @Cur2
		DEALLOCATE @Cur2
		
	 
        
		SELECT DISTINCT * FROM #TMP1 where col5 <> '' ORDER BY  CODE/*, col2, col4 */, COL15

		
	drop table #SALARY_SUM2_K
	drop table #SPR_ESN1_K			
	drop table #SPR_ESN1
	drop table #SALARY_SUM2
	drop table #TMP1

	END  
	IF @REP = 2 
	BEGIN 	
		/*Информация по раздеру 6.6 Информация о корректирующих сведениях*/
		/*К Исходным  заполняется в формах  с типом сведений «исходная» в случае, если в последние три месяца отчетного периода плательщиком страховых взносов 
		* корректируются данные, представленные в предыдущие отчетные периоды.При наличии данных в подразделе 6.6 дополнительно, 
		* в обязательном порядке предоставляются корректирующие (отменяющие)  разделы 6 и (или)  формы СЗВ-6-1, и (или) СЗВ-6-2, и (или) СЗВ-6-4.
		*/
		/*Заполняются в исходных , если есть по ним корректирующие */
	
		--- Обьявляем даты корректирующих сведений
			DECLARE @BYDateK	datetime , @nYEAR_K INT, @nMON1 INT, @nMON2 INT, @nMON3 INT
	

			select top 1 
			@BYDateK = (convert(varchar(4),YEAR_EDT)+'0101'),
			@nYEAR_K = YEAR_EDT,
			@nMON1 = (case  PER_EDT when 1 then  1 when 2 then  4 when 3 then  7 when 4 then  10 else 10 end)
			from #SZV_ALL WHERE [TYPE] = 2
			
			SELECT  @nMON2 = @nMON1 +1 , 	
					@nMON3 = @nMON1 +2 	

----------<<<<<<<<< #SPR_ESN для определения скидочной части (кусок ИЗ РСВ)

		/*Корректирующие сведения по физ лицам*/
		SELECT year_edt = p.YEAR_EDT, 
				PER_EDT = p.PER_EDT, 
				link_dep = p.link_dep,
				link_pers = s.link_pers,
				Link_kateg = S.Link_kateg,
				pachka = s.pachka
		INTO #tmp_pers
		FROM 	dbo.SA_SZV4_PACHKA P 
				INNER JOIN dbo.SZV4_SVEDENIA S ON P.link = S.link_up 															
		where
			P.link in (select link from #DOCS WHERE vid_kor = 2)
			and P.proverka = 1
			and P.vid_kor > 1
			and p.link_dep = @DEP_LINK


		CREATE TABLE #tmp_pers_kor_sum (link INT  , [date] DATETIME, YEAR_degin INT , per INT , vid_kor int, link_dep INT , proverka INT  , CODE VARCHAR(5), link_pers INT , 
										sum_doh NUMERIC(18,2), sum_str NUMERIC(18,2), sum_nak NUMERIC(18,2),sum_dop NUMERIC(18,2) , pachka int) 
	
		DECLARE @Cur_R2 CURSOR, @link int ,@LINK_pers INT, @year_edt INT , @per_edt INT , @Link_kateg INT ,@pachka int
		SET @Cur_R2 = CURSOR FORWARD_ONLY

		FOR SELECT LINK_pers, year_edt, per_edt, Link_kateg ,pachka FROM #tmp_pers ORDER by link_pers

		OPEN @Cur_R2
		FETCH NEXT FROM @Cur_R2 INTO @LINK_pers, @year_edt, @per_edt , @link_kateg, @pachka
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				
				
					SET @link = 0
					
					SELECT @link =max(pp.link)
					FROM SA_SZV4_PACHKA pp 
					INNER JOIN dbo.SZV4_SVEDENIA Ss ON ss.link_up = pp.link  
					WHERE  pp.proverka = 1 AND pp.vid_kor = 1 
										  AND pp.link_dep = @DEP_LINK 
										  AND pp.year_begin =@year_edt  
										  AND pp.PER =@per_edt 
										  AND @LINK_pers = ss.link_pers
										  AND @link_kateg = ss.link_kateg  
										  AND pp.date = (SELECT MAX(p1.[date]) FROM SA_SZV4_PACHKA p1 
																INNER JOIN dbo.SZV4_SVEDENIA S1 ON s1.link_up = p1.link  
																WHERE  pp.proverka = 1 AND p1.vid_kor = 1 
																					  AND p1.link_dep = @DEP_LINK 
																					  AND p1.year_begin =@year_edt  
																					  AND p1.PER =@per_edt 
																					  AND @LINK_pers = s1.link_pers
																					  AND @link_kateg = s1.link_kateg )
					
					INSERT INTO #tmp_pers_kor_sum (link, [date], YEAR_degin, per, vid_kor, link_dep, proverka , CODE, link_pers, 
										sum_doh, sum_str, sum_nak,sum_dop, pachka) 
					SELECT pp.link, pp.[date], pp.YEAR_begin, pp.per, pp.vid_kor, pp.link_dep, pp.proverka, CODE = k.code, ss.link_pers, 
										ss.sum_doh, ss.sum_str, ss.sum_nak,ss.sum_dop , pachka = @pachka
					FROM SA_SZV4_PACHKA pp 
					INNER JOIN dbo.SZV4_SVEDENIA Ss ON ss.link_up = pp.link  
					INNER JOIN dbo.SA_PFR_KATEG K ON K.LINK = ss.LINK_KATEG AND pp.YEAR_begin BETWEEN YBEG AND YEND		
					WHERE pp.link = @link and pp.proverka = 1 
										 AND pp.vid_kor = 1 
										 AND pp.link_dep = @DEP_LINK 
										 AND pp.year_begin =@year_edt  
										 AND pp.PER =@per_edt 
										 AND ss.link_pers = @LINK_pers
										 AND ss.link_kateg = @link_kateg
										  

			END

			FETCH NEXT FROM @Cur_R2 INTO @LINK_pers, @year_edt, @per_edt, @link_kateg, @pachka
		END

		CLOSE @Cur_R2
		DEALLOCATE @Cur_R2


---------->>>>>>>>>>
		create table #TMP2(CODE int identity(1,1) ,col1 int,   COL2 tinyint, COL3 varchar(4), COL4 numeric(18,2), COL5 numeric(18,2), COL6 numeric(18,2), COL7 VARCHAR(14), COL8 INT)

		INSERT INTO #TMP2 (COL2, COL3, COL4, COL5, COL6, COL7)
		SELECT 
			   COL2 = /*case when YEAR_EDT between '2011' and '2013'  then (case*/ [PER_EDT]/* when 1 then 1 when 2 then 2 when 3 then 3 when 4 then 4 else 0 end)
							when YEAR_EDT = '2014' then (case [PER_EDT] when 1 then 3 when 2 then 6 when 3 then 9 when 4 then 0 else null end) end */, 
			   COL3 = CONVERT(VARCHAR(4),YEAR_EDT),
			   COL4 = (CASE WHEN YEAR_EDT = '2014' THEN INSUR - (SELECT SUM(SUM_doh) FROM #tmp_pers_kor_sum WHERE CODE = 'НР' AND LINK_pers = s.link_face  )  ELSE 0 END ),
			   COL5 = (CASE WHEN YEAR_EDT < '2014' THEN INSUR - (SELECT SUM(SUM_doh) FROM #tmp_pers_kor_sum WHERE CODE = 'НР' AND LINK_pers = s.link_face  )  ELSE 0 END ),
			   COL6 = (CASE WHEN YEAR_EDT < '2014' THEN GAIN - (SELECT SUM(SUM_NAK) FROM #tmp_pers_kor_sum WHERE CODE = 'НР' AND LINK_pers = s.link_face  )   ELSE 0 END ),
			   COL7 = CONVERT(VARCHAR(14),PFNUMBER)
		FROM #SZV_ALL s WHERE  [TYPE] = 2 AND id_ex =1 
		GROUP BY link_face, YEAR_EDT,  [PER_EDT] , INSUR , GAIN ,[FM],[IM],[OT], PFNUMBER 
		ORDER BY [FM],[IM],[OT],[PFNUMBER]
		
		UPDATE #TMP2 
			SET col1 = CODE , COL8 = CODE 

		
		SELECT * FROM #TMP2 ORDER BY CODE


		drop table #tmp_pers
		drop table #tmp_pers_kor_sum
		--DROP TABLE #SPR_ESN_K
		drop table #TMP2
		--GROUP BY [TYPE],CODE, [T_DOG],[FM],[IM],[OT],[PFNUMBER],[per],[year],[per_edt],[year_edt]	
	

	
	END	
		
	IF @REP = 3 
	BEGIN 	
		/*Информация по раздеру 6.7 Сведения о сумме выплат и иных вознаграждений в пользу физического лица, занятого на соответствующих видах работ, 
		* с которых начислены страховые взносы по дополнительному тарифу для отдельных категорий плательщиков страховых взносов, указанных в частях 1, 2 и 2.1 статьи 58.3 
		* Федерального закона от 24 июля 2009 г. № 212-ФЗ */

	/*****************************************************/
	-- Собираем информацию по Исходным пачками
	/*****************************************************/

		DECLARE @BYear_Date	datetime
			SET @BYear_Date = dbo.DateBeginOfYear (@dDate1)

		create table #SPR_ESN ([MONTH_BASE] TINYINT, SUMMA_BASE numeric(12,2) default 0.00, DED_M numeric(12,2) default 0.00, INV_M numeric(12,2) default 0.00, SUMMA numeric(12,2) default 0.00, WAY_CALC int default 0.00, REF_PHYS_PERS int default 0 , PF_NUM VARCHAR (14), FACE_GROUP TINYINT, I TINYINT, E TINYINT , SP VARCHAR(4))

		Insert InTo #SPR_ESN ([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS , PF_NUM, FACE_GROUP, I, E, SP)
		Select [MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0 THEN 3 
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END ) AS FACE_GROUP, 
			dbo.is_invalid(REF_PHYS_PERS,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH_BASE,@nYEAR))),
			F.ENVD,
			SP = isnull(s4.code,'')
		from dbo.SA_ESN_VIEW(@nYEAR, @nMONTH3, @LINK_DEP, 0) S
			inner join PERSON P on S.REF_PHYS_PERS = P.link
			inner join dbo.SAL_SFIN F on F.LINK = S.LINK_VKR
			LEFT JOIN SA_SZV4_SPR  s4 ON  s4.link = S.SPECO AND s4.spr_code = 'SPO_USL_TRUDA'
		WHERE  WAY_CALC not in (5)

		--Суммы по договорникам
		INSERT INTO #SPR_ESN 
			([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, PF_NUM, FACE_GROUP, I, E)
		SELECT 
			MONTH(G.[DATE]) AS MONTH_BASE, GT.SUMMA_BASE, 0, 0, GT.SUMMA, GT.WAY_CALC, GT.PERS_LINK, p.INSUR_NUM ,
			( CASE WHEN P.RESIDENT = 0  THEN 3
				   WHEN YEAR(birthdate)<= 1966 THEN 1 
				   WHEN YEAR(birthdate)>= 1967 THEN 2 END) AS FACE_GROUP , 
			dbo.is_invalid(GT.PERS_LINK,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,G.[MONTH],@nYEAR))),
			F.ENVD
			
		FROM 
			DOCUMENTS_DGH G INNER JOIN DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
			inner join PERSON P on GT.PERS_LINK = P.link
			inner join dbo.SAL_SFIN F on F.LINK = GT.LINK_VKR
		WHERE 
			FLAG_JC = 1
			AND GT.WAY_CALC  not in (5)
			AND YEAR(G.[DATE]) = @nYEAR
			AND MONTH(G.[DATE]) <= @nMONTH3
			AND LINK_DEP = @DEP_LINK


		DELETE FROM #SPR_ESN
		WHERE  EXISTS (SELECT * FROM dbo.KJ_PERS_PENSION K WHERE K.PERS_LINK = REF_PHYS_PERS AND K.CHECK_SZV = 0)

	
		UPDATE #SZV_ALL
			SET [OSOB_SPO] =  SP 
			FROM #SPR_ESN  WHERE pf_num = #SZV_ALL.[PFNUMBER] AND WAY_CALC IN (10,11) AND MONTH_BASE = @nMONTH3  AND SUMMA_BASE <> 0        



		create table #TMP3(CODE int,col1 int,   COL2 varchar(100), COL3 varchar(4), COL4 varchar (4), COL5 numeric(18,2), COL6 numeric(18,2), COL7 VARCHAR(14), COL8 int, COL9 int, 
							COL10 VARCHAR(10), COL11 VARCHAR(10), COL12 VARCHAR(10),COL13 VARCHAR(20), COL14 VARCHAR(10), COL15 VARCHAR(100), COL16 VARCHAR(10),COL17 VARCHAR(100),
							COL18 VARCHAR(10), COL19 VARCHAR(10), COL20 VARCHAR(10),COL21 VARCHAR(20), COL22 VARCHAR(10), COL23 VARCHAR(100), COL24 VARCHAR(10), COL25 VARCHAR(100), 
							COL26 VARCHAR(10), COL27 VARCHAR(10), COL28 VARCHAR(10),COL29 VARCHAR(20), COL30 VARCHAR(10), COL31 VARCHAR(100), COL32 VARCHAR(10), COL33 VARCHAR(100),
							COL34 VARCHAR(10), COL35 VARCHAR(10), COL36 VARCHAR(10), COL37 VARCHAR(20), COL38 VARCHAR(10), COL39 VARCHAR(100), COL40 VARCHAR(10), COL41 VARCHAR(100), COL42 varchar(100), COL43 varchar(100), COL44 varchar(100))


		
		DECLARE @Cur3 CURSOR, @CODE1 varchar(4), @TYPE1 tinyint , @PFNUMBER1 VARCHAR (14) , @FM1 VARCHAR(100),@IM1 VARCHAR(100),@OT1 VARCHAR(100),
		@pf_num11 VARCHAR(14) ,@TYPE_OLD1 TINYINT, @nom_pp1 INT, @OSOB_SPO VARCHAR(4), @OSOB_SPO_old VARCHAR(4),
		@DateM1B DATETIME, @DateM2B DATETIME, @DateM3B DATETIME, @DateM1E DATETIME, @dateM2E DATETIME, @dateM3E DATETIME
		set @pf_num11 = ''
		set @OSOB_SPO_old = NULL 
		set @TYPE_OLD1 = 0
		set @nom_pp1 = 1
		
		SELECT @DateM1B = @dDate1,
			   @DateM2B =  dbo.ConvertDMY2Date(1,month(@dDate1)+1,YEAR(@dDate1)), 	
			   @DateM3B =  dbo.ConvertDMY2Date(1,month(@dDate1)+2,YEAR(@dDate1)), 
			   @DateM1E =  dbo.DateEndOfMonth(@DateM1B),
			   @DateM2E =  dbo.DateEndOfMonth(@DateM2B), 	
			   @DateM3E =  @dDate2

		SET @Cur3 = CURSOR FORWARD_ONLY
		FOR SELECT  [CODE],[TYPE],[PFNUMBER], [FM],[IM],[OT], [OSOB_SPO]  FROM #SZV_ALL where /*T_DOG = 1 and*/ [TYPE] = 1  GROUP BY [FM],[IM],[OT],[PFNUMBER],[TYPE],CODE, [OSOB_SPO] ORDER BY [FM],[IM],[OT],[PFNUMBER],[TYPE],CODE, [OSOB_SPO]
		OPEN @Cur3
		FETCH NEXT FROM @Cur3 INTO  @CODE1,@TYPE1,@PFNUMBER1,@FM1,@IM1,@OT1, @OSOB_SPO
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				
				SELECT @OSOB_SPO = ISNULL(@OSOB_SPO, '')
				select @OSOB_SPO_old = ISNULL(@OSOB_SPO_old, '')
				--- Заполнение информации по первому коду категории сотрудника (нр , оои, пнэд)
				IF (ltrim(rtrim(@PFNUMBER1)) <> ltrim(rtrim(@pf_num11)) ) 
				BEGIN

					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42, COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'700'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = CASE WHEN PER = 1 THEN  ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) ,0)
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																+ (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0)
									END ,
						   COL6 = CASE WHEN PER = 1 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)) 
															   + (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
								  END,
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE], 
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
						   
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)					
					WHERE  s.code = @CODE1 and s.[TYPE] = @TYPE1 AND s.PFNUMBER = @PFNUMBER1 AND ISNULL(s.OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3 ,s.OSOB_SPO,E.SP, e.PF_NUM 
		
					SELECT  @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'701'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL( (sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   ,0),
						   COL6 = ISNULL( (sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)		
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,s.OSOB_SPO,E.SP, e.PF_NUM 
					
				




					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'702'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL( (sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   ,0),
						   COL6 = ISNULL( (sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1

					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'703'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@dateM3E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3	,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1
				
				END
					
				
				--- Заполнение информации по следующему коду категории сотрудника (если за расчетный период у сотрудника была не одна категория)
				IF @PFNUMBER1 = @pf_num11 and @OSOB_SPO <> @OSOB_SPO_old
				BEGIN 
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'710'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = CASE WHEN PER = 1 THEN  ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) ,0)
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																+ (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0)
									END ,
						   COL6 = CASE WHEN PER = 1 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)) 
															   + (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
								  END,
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'711'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'712'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL  s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end	,s.OSOB_SPO,E.SP, e.PF_NUM 	
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'713'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1
				END						

				--- заполняем пустые строки '410','411','412','413' 
		
				if not exists (select * from #tmp3 
								where COL7 = @PFNUMBER1 
								and COL9 = @TYPE1
								and COL4 = '710' ) AND NOT EXISTS (SELECT * FROM #SZV_ALL WHERE PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') != ISNULL(@OSOB_SPO,'') AND [TYPE] = 1) 
				begin 
						
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT 
						   CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'710'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'711'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'712'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1		
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'713'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1	
				end 

					select	row_number() over (order by DATE_BEGIN) as ID ,
							FM1 = [FM]  ,
							IM1 = [IM],
							OT1 = [OT],
							PFNUMBER1 = [PFNUMBER], 
							T_DOG1= T_DOG,
							TYPE1 = [TYPE], 
							DATE_BEGIN1 = [DATE_BEGIN], 
							DATE_END1 = (CASE WHEN [DATE_END]> @dDate2 THEN @dDate2 ELSE [DATE_END] end) , 
							TU_CODE1 = [TU_CODE], 
							OS_CODE1 = [OS_CODE], 
							EX_CODE1 = [EX_CODE], 
							f_is_dop1 = [f_is_dop], 
							P_CODE1 = [P_CODE], 
							f_ud_dop1 = [f_ud_dop] 
					into #TMP03
					FROM #SZV_ALL  WHERE  id_ex IS NOT NULL AND YEAR(@dDate1)<=YEAR(Date_END) and MONTH(@dDate2) >= MONTH(Date_END) and MONTH(@dDate2) >= MONTH(Date_BEGIN) and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 and fm = @FM1 and T_DOG = 1
					GROUP BY [FM],[IM],[OT],[PFNUMBER], T_DOG,[TYPE], [DATE_BEGIN], [DATE_END] , [TU_CODE], [OS_CODE], [EX_CODE], [f_is_dop], [P_CODE], [f_ud_dop]
					ORDER BY  [FM],[IM],[OT],[PFNUMBER], T_DOG,[TYPE]
					
					
					UPDATE #TMP3
					set COL10 = (SELECT distinct convert(varchar(10),DATE_BEGIN1,104 ) FROM #TMP03 where ID=1 and FM1= @FM1),
						COL11 = (SELECT distinct convert(varchar(10),DATE_END1,104 ) FROM #TMP03 where ID=1 and FM1= @FM1),
						COL12 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP03 where ID=1 and FM1= @FM1) ,
						COL13 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP03 where ID=1 and FM1= @FM1),
						COL14 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP03 where ID=1 and FM1= @FM1), 
						COL15 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP03 where ID=1 and FM1= @FM1),
					    COL16 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP03 where ID=1 and FM1= @FM1), 
					    COL17 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP03 where ID=1 and FM1= @FM1), 
					    COL18 = (SELECT distinct convert(varchar(10),DATE_BEGIN1,104 ) FROM #TMP03 where ID=2 and FM1= @FM1), 
					    COL19 = (SELECT distinct convert(varchar(10),DATE_END1,104 ) FROM #TMP03 where ID=2 and FM1= @FM1),
					    COL20 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP03 where ID=2 and FM1= @FM1),
					    COL21 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP03 where ID=2 and FM1= @FM1),
						COL22 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP03 where ID=2 and FM1= @FM1), 
						COL23 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP03 where ID=2 and FM1= @FM1),
					    COL24 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP03 where ID=2 and FM1= @FM1), 
					    COL25 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP03 where ID=2 and FM1= @FM1),
					    COL26 = (SELECT distinct convert(varchar(10),DATE_BEGIN1,104 ) FROM #TMP03 where ID=3 and FM1= @FM1), 
					    COL27 = (SELECT distinct convert(varchar(10),DATE_END1,104 ) FROM #TMP03 where ID=3 and FM1= @FM1),
					    COL28 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP03 where ID=3 and FM1= @FM1),
					    COL29 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP03 where ID=3 and FM1= @FM1),
						COL30 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP03 where ID=3 and FM1= @FM1), 
						COL31 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP03 where ID=3 and FM1= @FM1),
					    COL32 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP03 where ID=3 and FM1= @FM1), 
					    COL33 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP03 where ID=3 and FM1= @FM1),
					    COL34 = (SELECT distinct convert(varchar(10),DATE_BEGIN1,104 ) FROM #TMP03 where ID=4 and FM1= @FM1), 
					    COL35 = (SELECT distinct convert(varchar(10),DATE_END1,104 ) FROM #TMP03 where ID=4 and FM1= @FM1),
					    COL36 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP03 where ID=4 and FM1= @FM1),
					    COL37 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP03 where ID=4 and FM1= @FM1),
						COL38 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP03 where ID=4 and FM1= @FM1), 
						COL39 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP03 where ID=4 and FM1= @FM1),
					    COL40 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP03 where ID=4 and FM1= @FM1), 
					    COL41 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP03 where ID=4 and FM1= @FM1)
					from #TMP3	
					WHERE #TMP3.COL9 = @TYPE1 
					and #TMP3.COL7 = @PFNUMBER1 AND #TMP3.COL3 = '700' /*and #TMP3.CODE =  @nom_pp1*/

					drop table #TMP03				

					set @pf_num11 = @PFNUMBER1
					set @OSOB_SPO_old = @OSOB_SPO
					set @TYPE_OLD1 = @TYPE1
					
			
			END

			FETCH NEXT FROM @Cur3 INTO @CODE1,@TYPE1,@PFNUMBER1,@FM1,@IM1,@OT1, @OSOB_SPO
		END

		CLOSE @Cur3
		DEALLOCATE @Cur3
		
		
		
		
		/*****************************************************/
		-- Собираем информацию по Кореектирующим/Отменяющим
		/*****************************************************/
		--create table #TMP1(CODE int,col1 int,   COL2 varchar(14), COL3 varchar(100), COL4 varchar (4), COL5 varchar (4), COL6 numeric(18,2), COL7 numeric(18,2), COL8 numeric(18,2), COL9 numeric(18,2), COL10 varchar(1), COL11 varchar(4), COL12 varchar(15), COL13 varchar(1), COL14 varchar(4),COL15 int)
	
		DECLARE @Cur4 CURSOR
		set @pf_num11 = ''
		set @OSOB_SPO_old = ''  
		set @TYPE_OLD1 = 0
		set @nom_pp1 = (SELECT MAX(CODE) FROM #TMP3 WHERE COL9 = 1) + 1 
		
				
		SET @Cur4 = CURSOR FORWARD_ONLY
		FOR SELECT  [CODE],[TYPE],[PFNUMBER], [FM],[IM],[OT], [OSOB_SPO]  FROM #SZV_ALL where /*T_DOG = 1 and */[TYPE] != 1 and year_edt >=2014  GROUP BY [CODE],[TYPE],[PFNUMBER], [FM],[IM],[OT], [OSOB_SPO]ORDER BY [CODE],[TYPE],[PFNUMBER], [FM],[IM],[OT], [OSOB_SPO]
		OPEN @Cur4
		FETCH NEXT FROM @Cur4 INTO  @CODE1,@TYPE1,@PFNUMBER1,@FM1,@IM1,@OT1, @OSOB_SPO
		WHILE (@@fetch_status <> -1)
		BEGIN

			IF (@@fetch_status <> -2)
			BEGIN
				
				SELECT @OSOB_SPO = ISNULL(@OSOB_SPO, '')
				select @OSOB_SPO_old = ISNULL(@OSOB_SPO_old, '')	
				--- Заполнение информации по первому коду категории сотрудника (нр , оои, пнэд)
				IF (@PFNUMBER1 <> @pf_num11 ) 
				BEGIN
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'700'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = CASE WHEN PER = 1 THEN  ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) ,0)
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																+ (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0)
									END ,
						   COL6 = CASE WHEN PER = 1 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)) 
															   + (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
								  END,

						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt], INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3 , date_end,s.OSOB_SPO,E.SP, e.PF_NUM 
					

					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'701'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end ,s.OSOB_SPO,E.SP, e.PF_NUM 	
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'702'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end	,s.OSOB_SPO,E.SP, e.PF_NUM 
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'703'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt]	,INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 		
					
					set @nom_pp1 = @nom_pp1 + 1
				END
					
				
				--- Заполнение информации по следующему коду категории сотрудника (если за расчетный период у сотрудника была не одна категория)
				IF @PFNUMBER1 = @pf_num11 and @OSOB_SPO <> @OSOB_SPO_old
				BEGIN 
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'710'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = CASE WHEN PER = 1 THEN  ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
										WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																 + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																 + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																 + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																 + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) ,0)
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))  
																+ (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)) 
																+ (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))   
																+ (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END))
																+ (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0)
									END ,
						   COL6 = CASE WHEN PER = 1 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 2 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))  ,0)
									   WHEN PER = 3 THEN ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
													ELSE ISNULL( (sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 1 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 2 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 3 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 4 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 5 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 6 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))
															   + (sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 7 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 8 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 9 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)) 
															   + (sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 10 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))    
															   + (sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 11 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   
															   + (sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END) - sum(CASE WHEN MONTH_BASE= 12 AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END))   ,0)  
								  END,						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)		
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end	,s.OSOB_SPO,E.SP, e.PF_NUM 	
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'711'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM1E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 		
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'712'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM2E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)		
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end,s.OSOB_SPO,E.SP, e.PF_NUM 			
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'713'),
						   COL4 = CONVERT(VARCHAR(4),ISNULL(s.OSOB_SPO,'')),
						   COL5 = ISNULL((sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 10	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL6 = ISNULL( ( sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN SUMMA_BASE ELSE 0 END)- sum(CASE WHEN MONTH_BASE= month(@DateM3E) AND e.WAY_CALC = 11	 THEN DED_M + INV_M  ELSE 0 END)),0),
						   COL7 = ISNULL([PFNUMBER],0),
						   COL8 = @nom_pp1,
						   COL9 = [TYPE],
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					FROM #SZV_ALL s
					left JOIN #SPR_ESN  e ON 	e.PF_NUM = s.PFNUMBER AND ISNULL(e.SP,'') = ISNULL(s.OSOB_SPO,'') AND e.WAY_CALC IN (10,11)	
					WHERE  code = @CODE1 and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') = @OSOB_SPO AND s.ID_EX = 1
					GROUP BY [TYPE],CODE,[FM],[IM],[OT],[PFNUMBER],[per],[year],[TYPE],[per_edt],[year_edt],INC_T1M1,INC_T1M2,INC_T1M3, INC_T2M1,INC_T2M2,INC_T2M3,date_end	,s.OSOB_SPO,E.SP, e.PF_NUM  		
					
					set @nom_pp1 = @nom_pp1 + 1
				END						

				--- заполняем пустые строки '710','711','712','713' 
			
				if not exists (select * from #tmp3 
								where COL7 = @PFNUMBER1 
								and COL9 = @TYPE1
								and COL4 = '710' ) AND NOT EXISTS (SELECT * FROM #SZV_ALL WHERE PFNUMBER = @PFNUMBER1 AND ISNULL(OSOB_SPO,'') != @OSOB_SPO AND [TYPE] = 2) 
				begin 
						
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), 'Всего с начала расчетного периода, в том числе за последние три месяца отчетного периода:'),	
						   COL3 = CONVERT(VARCHAR(4),'710'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '1 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'711'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '2 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'712'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1		
					
					INSERT INTO #TMP3 (CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL42 , COL43, COL44)
					SELECT CODE =  @nom_pp1,
						   COL1 =  @nom_pp1,	
						   COL2 = CONVERT(VARCHAR(100), '3 месяц'),	
						   COL3 = CONVERT(VARCHAR(4),'713'),
						   COL4 = CONVERT(VARCHAR(4),''),
						   COL5 = 0,
						   COL6 = 0,
						   COL7 = ISNULL(@PFNUMBER1,''),
						   COL8 = @nom_pp1,
						   COL9 = @TYPE1,
						   COL42 = CONVERT(varchar(100),@FM1),
						   COL43 = CONVERT(varchar(100),@IM1),
						   COL44 = CONVERT(varchar(100),@OT1)
					
					set @nom_pp1 = @nom_pp1 + 1	
				
				end 


					select	row_number() over (order by DATE_BEGIN) as ID ,
							FM1 = [FM]  ,
							IM1 = [IM],
							OT1 = [OT],
							PFNUMBER1 = [PFNUMBER], 
							T_DOG1= T_DOG,
							TYPE1 = [TYPE], 
							DATE_BEGIN1 = [DATE_BEGIN], 
							DATE_END1 = (CASE WHEN [DATE_END] > @dDate2 THEN @dDate2 ELSE  [DATE_END] END )  , 
							TU_CODE1 = [TU_CODE], 
							OS_CODE1 = [OS_CODE], 
							EX_CODE1 = [EX_CODE], 
							f_is_dop1 = [f_is_dop], 
							P_CODE1 = [P_CODE], 
							f_ud_dop1 = [f_ud_dop] 
					into #TMP04
					FROM #SZV_ALL  WHERE  id_ex IS NOT NULL AND YEAR(@dDate1)<=YEAR(Date_END) and MONTH(@dDate2) >= MONTH(Date_END) and MONTH(@dDate2) >= MONTH(Date_BEGIN) and [TYPE] = @TYPE1 AND PFNUMBER = @PFNUMBER1 and fm = @FM1 and T_DOG = 1
					GROUP BY [FM],[IM],[OT],[PFNUMBER], T_DOG,[TYPE], [DATE_BEGIN], [DATE_END] , [TU_CODE], [OS_CODE], [EX_CODE], [f_is_dop], [P_CODE], [f_ud_dop]
					ORDER BY  [FM],[IM],[OT],[PFNUMBER], T_DOG,[TYPE]
				

					UPDATE #TMP3
					set COL10 = (SELECT distinct convert(varchar(10),DATE_BEGIN1, 104 ) FROM #TMP04 where ID=1 and FM1= @FM1),
						COL11 = (SELECT distinct convert(varchar(10),DATE_END1, 104 ) FROM #TMP04 where ID=1 and FM1= @FM1),
						COL12 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP04 where ID=1 and FM1= @FM1) ,
						COL13 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP04 where ID=1 and FM1= @FM1),
						COL14 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP04 where ID=1 and FM1= @FM1), 
						COL15 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP04 where ID=1 and FM1= @FM1),
					    COL16 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP04 where ID=1 and FM1= @FM1), 
					    COL17 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP04 where ID=1 and FM1= @FM1), 
					    COL18 = (SELECT distinct convert(varchar(10),DATE_BEGIN1 , 104 ) FROM #TMP04 where ID=2 and FM1= @FM1), 
					    COL19 = (SELECT distinct convert(varchar(10),DATE_END1, 104 ) FROM #TMP04 where ID=2 and FM1= @FM1),
					    COL20 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP04 where ID=2 and FM1= @FM1),
					    COL21 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP04 where ID=2 and FM1= @FM1),
						COL22 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP04 where ID=2 and FM1= @FM1), 
						COL23 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP04 where ID=2 and FM1= @FM1),
					    COL24 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP04 where ID=2 and FM1= @FM1), 
					    COL25 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP04 where ID=2 and FM1= @FM1),
					    COL26 = (SELECT distinct convert(varchar(10),DATE_BEGIN1, 104 ) FROM #TMP04 where ID=3 and FM1= @FM1), 
					    COL27 = (SELECT distinct convert(varchar(10),DATE_END1, 104 ) FROM #TMP04 where ID=3 and FM1= @FM1),
					    COL28 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP04 where ID=3 and FM1= @FM1),
					    COL29 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP04 where ID=3 and FM1= @FM1),
						COL30 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP04 where ID=3 and FM1= @FM1), 
						COL31 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP04 where ID=3 and FM1= @FM1),
					    COL32 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP04 where ID=3 and FM1= @FM1), 
					    COL33 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP04 where ID=3 and FM1= @FM1),
					    COL34 = (SELECT distinct convert(varchar(10),DATE_BEGIN1, 104 ) FROM #TMP04 where ID=4 and FM1= @FM1), 
					    COL35 = (SELECT distinct convert(varchar(10),DATE_END1, 104 ) FROM #TMP04 where ID=4 and FM1= @FM1),
					    COL36 = (SELECT distinct convert(varchar(10),TU_CODE1 ) FROM #TMP04 where ID=4 and FM1= @FM1),
					    COL37 = (SELECT distinct convert(varchar(20),OS_CODE1 ) FROM #TMP04 where ID=4 and FM1= @FM1),
						COL38 = (SELECT distinct convert(varchar(10),EX_CODE1 ) FROM #TMP04 where ID=4 and FM1= @FM1), 
						COL39 = (SELECT distinct convert(varchar(100),f_is_dop1 ) FROM #TMP04 where ID=4 and FM1= @FM1),
					    COL40 = (SELECT distinct convert(varchar(10),P_CODE1) FROM #TMP04 where ID=4 and FM1= @FM1), 
					    COL41 = (SELECT distinct convert(varchar(100),f_ud_dop1) FROM #TMP04 where ID=4 and FM1= @FM1)
					from #TMP3	
					WHERE #TMP3.COL9 = @TYPE1 
					and #TMP3.COL7 = @PFNUMBER1 and  #TMP3.COL3 = '700'

					drop table #TMP04	


					set @pf_num11 = @PFNUMBER1
					set @OSOB_SPO_old = @OSOB_SPO
					set @TYPE_OLD1 = @TYPE1
					
			END

			FETCH NEXT FROM @Cur4 INTO @CODE1,@TYPE1,@PFNUMBER1,@FM1,@IM1,@OT1, @OSOB_SPO
		END

		CLOSE @Cur4
		DEALLOCATE @Cur4
		
		
		SELECT DISTINCT * FROM #TMP3 where col5 <> 0 or col6 <> 0  or  ISNULL(COL10,'') <> '' ORDER BY  CODE/*, col2, col4 */, COL8
	

		drop table #TMP3
	
	END		
	
	IF @REP = 4 
	BEGIN 	
		/*Заполнение подраздела 6.8 «Период работы за последние три месяца отчетного периода» раздела 6 Расчета*/
		create table #TMP4(CODE int identity(1,1) ,col1 int,   COL2 VARCHAR(10), COL3 VARCHAR(10), COL4 VARCHAR(10), COL5 VARCHAR(20), COL6 VARCHAR(10), COL7 varchar(100), COL8 VARCHAR(10), COL9 varchar(100), COL10 VARCHAR(14), COL11 INT , COL12 INT, COL13 VARCHAR(100), COL14 varchar(100), COL15 VARCHAR(100) )

		INSERT INTO #TMP4 (COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL12, COL13, COL14, COL15 )
		SELECT 
			   COL2 = convert(varchar(10),(CASE WHEN [DATE_BEGIN] > @dDate2 THEN @dDate2 ELSE [DATE_BEGIN] END) , 104), 
			   COL3 = CONVERT(varchar(10),[DATE_END] , 104),
			   COL4 = CONVERT(VARCHAR(10),ISNULL([TU_CODE],'')),
			   COL5 = CONVERT(VARCHAR(20),ISNULL([OS_CODE],'')),
			   COL6 = CONVERT(VARCHAR(10),ISNULL([EX_CODE],'')),
			   COL7 = CONVERT(VARCHAR(100),ISNULL([f_is_dop],'')),
			   COL8 = CONVERT(VARCHAR(10),ISNULL([P_CODE],'')),
			   COL9 = CONVERT(VARCHAR(100),ISNULL([f_ud_dop],'')),
			   COL10 = CONVERT(VARCHAR(100),ISNULL([PFNUMBER],'')),
			   COL12 = ISNULL([TYPE],0),
			   COL13 = CONVERT(varchar(100),FM),
			   COL14 = CONVERT(varchar(100),IM),
			   COL15 = CONVERT(varchar(100),OT)
		FROM #SZV_ALL  WHERE  id_ex IS NOT NULL AND  YEAR(@dDate1)<=YEAR(Date_END) and MONTH(@dDate2) >= MONTH(Date_END) and MONTH(@dDate2) >= MONTH(Date_BEGIN)
		GROUP BY [FM],[IM],[OT],[PFNUMBER]/*, T_DOG*/,[TYPE], [DATE_BEGIN], [DATE_END] , [TU_CODE], [OS_CODE], [EX_CODE], [f_is_dop], [P_CODE], [f_ud_dop]
		ORDER BY  [FM],[IM],[OT],[PFNUMBER]/*, T_DOG*/,[TYPE]
--RSA_RSV_1_PERS_UCH_szv '20140401', '20140630', 13488 , 4, 413	

		UPDATE #TMP4 
			SET col1 = CODE , COL11 = CODE 

		SELECT * FROM #TMP4 ORDER BY CODE
		drop table #TMP4
		--GROUP BY [TYPE],CODE, [T_DOG],[FM],[IM],[OT],[PFNUMBER],[per],[year],[per_edt],[year_edt]	
		
	END	
	
	
		
		drop table #SZV_ALL
		--drop table #docs_kor_otm
		drop table #docs

END

GO


GRANT EXECUTE ON dbo.[RSA_RSV_1_PERS_UCH_SZV] TO PUBLIC

GO




GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].BB_GZ_REESTR_REPORT_2014') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].BB_GZ_REESTR_REPORT_2014

GO


create    procedure dbo.BB_GZ_REESTR_REPORT_2014 @iLSF int 

as

declare @dDateBeg	datetime,
		@cDepCode	varchar(20),
		@iDepLink int, 
		@dDateEnd datetime


select @iDepLink = Link_Organization, 
		@dDateEnd    = Begin_Date + 1, 
		@dDateBeg  = dbo.DateBeginOfYear(Begin_Date)
from dbo.REPORT_SAVED_FORMS
where Link_Saved_Form = @iLSF


select @cDepCode = isnull(rtrim(ltrim(BUDG)),'')
from dbo.DEPARTMENTS 
where LINK = @iDepLink 

--set @dDateBeg = dbo.DateBeginOfYear(@dDateEnd)
declare @cTableReestr table (	LINK_GC		int,
			 	LINK_OKPD	int,
			 	TYPE		tinyint,
				QUANTITY	numeric(19,4),
				--COST		numeric(19,4),
				SUMMA		numeric(19,4))

declare @cTemp table(LINK_OKPD	int,
			NAME_DOC	varchar(100),
			LINK_DEP	INT,
			NUMBER		varchar(30),
			[DATE]		datetime,
			COMMENT		varchar(1000),		
			C_TYPE		int,
			CON_END		datetime,
			C_QUANTITY	numeric(19,4),
			C_COST		numeric(19,4),
			C_SUMMA		numeric(19,4),
			GZ_QUANTITY	numeric(19,4),
			GZ_COST		numeric(19,4),
			GZ_SUMMA	numeric(19,4),
			OPL_SUMMA	numeric(19,4),
			OPL_SUMMA_B	numeric(19,4),
			OPL_SUMMA_V	numeric(19,4))

declare @cTemp1 table(LINK_GC	int,  
						LINK_OKPD	int,  
						NAME_DOC	varchar(100), 
						LINK_DEP	int, 
						NUMBER	varchar(30), 
						[DATE]	datetime,
						COMMENT	varchar(1000), 
						C_TYPE	int, 
						CON_DATE	datetime,
						[TYPE]	int, 
						QUANTITY numeric(19,4),
						COST numeric(19,4), 
						SUMMA numeric(19,4))
			



-- Выбираем строки реестра госзакупок
insert into @cTableReestr(LINK_GC, LINK_OKPD, QUANTITY,/* COST, */SUMMA, TYPE)
select GR.LINK_CONTRACT, OKPD.LINK, SUM(GRT.QUANTITY * N.COEFF)/*, (case when N.COEFF = 0 then 0 else GRT.COST / N.COEFF end)*/, SUM(GRT.SUMMA) / 1000, GRT.TYPE
from dbo.G_PROV G
inner join dbo.GZ_REESTR GR on GR.LINK = G.LINK
inner join dbo.GZ_REESTR_DOP GRT on GRT.LINK_UP = G.LINK
inner join dbo.NOMENCLATURE N on GRT.NOMENCLATURE = N.LINK 
inner join dbo.OKPD OKPD on N.LINK_OKPD = OKPD.LINK --and not exists (select * from OKPD OKPD1 where OKPD1.LINK_SELF = OKPD.LINK)
where  G.DATE_PROV is not NULL and 
	G.DATE_PROV between @dDateBeg and @dDateEnd and 
	G.DEP = @iDepLink
group by GR.LINK_CONTRACT, OKPD.LINK, GRT.TYPE --, case when N.COEFF = 0 then 0 else GRT.COST / N.COEFF end

--select * from @cTableReestr

insert into @cTemp1
select distinct LINK_GC 	= G.LINK, 
		     LINK_OKPD	= CT.OKPD,  
		     NAME_DOC	= case when CH.GZ_LINK is not null or (rtrim(CH.GZ_NUM) <> '' or CH.GZ_DATE is not null) then 'Госконтракт' else /*rtrim(SO.NAME)*/'Договор' end, 
		     LINK_DEP	= CH.DEP_LINK_P, 
		     NUMBER	= case when CH.GZ_LINK is not null then GZ.NUMBER else case when rtrim(CH.GZ_NUM) <> '' or CH.GZ_DATE is not null then CH.GZ_NUM else case when CH.DOG_LINK is not null then GPD.NUMBER else G.NUMBER end end end, 
		     DATE	= case when CH.GZ_LINK is not null then GZ.DATE else case when rtrim(CH.GZ_NUM) <> ''  or CH.GZ_DATE is not null then CH.GZ_DATE else case when CH.DOG_LINK is not null then GPD.DATE else G.DATE end end end,
		     COMMENT	= case when CH.GZ_LINK is not null and GZ.COMMENT <> '' then GZ.COMMENT else CH.MAINTENANCE end, 
		     C_TYPE	= CH.TYPE, 
		     CON_DATE	= DATE_END,
		     TYPE	= 3, 
		     CT.QUANTITY, 
		     CT.COST, 
		     SUMMA      = CT.SUMMA / 1000
		from dbo.G_PROV G
		inner join dbo.FINANSE_CONTRACT_HEAD CH on CH.Link_G_Prov = G.LINK and CH.GZ = 1 and
							   (CH.DATE_BEGIN between @dDateBeg and @dDateEnd or
								CH.DATE_END between @dDateBeg and @dDateEnd or
								@dDateBeg between CH.DATE_BEGIN and CH.DATE_END or
								@dDateEnd between CH.DATE_BEGIN and CH.DATE_END)
		inner join (	select LINK_UP, OKPD, sum(SUMMA) as SUMMA, sum(QUANTITY) as QUANTITY, case sum(QUANTITY) when 0 then 0 else sum(SUMMA)/sum(QUANTITY) end  as cost
				from dbo.FINANSE_CONTRACT 
				group by LINK_UP, OKPD) CT on CT.LINK_UP = G.LINK
		left  join dbo.G_PROV GZ on GZ.LINK = CH.GZ_LINK
		left  join dbo.S_OBJECTS SO on isnull(GZ.OBJECT, G.OBJECT) = SO.LINK
		left  join dbo.G_PROV GPD on GPD.LINK = CH.DOG_LINK
		where G.DEP = @iDepLink and G.DATE_PROV is not null  
		union all
		select LINK_GC 	= G.LINK, 
		     LINK_OKPD	= NULL,  
		     NAME_DOC	= rtrim(DT.NAME), 
		     LINK_DEP	= CH.DEP_LINK_P, 
		     NUMBER	= G.NUMBER, 
		     DATE	= G.DATE, 
		     COMMENT	= G.COMMENT, 
		     C_TYPE	= CH.TYPE, 
		     CON_DATE	= NULL, 
		     TYPE	= 4, 
		     QUANTITY	= 0, 
		     COST	= 0, 
		     SUMMA	= G.SUMMA / 1000
		from dbo.G_PROV G
		inner join dbo.GZ_NOT_CONTRACT_HEAD CH on CH.LINK = G.LINK
		inner join dbo.BB_NOT_CONTRACT_DOC_TYPE DT on DT.LINK = CH.TYPE_DOC 
		where G.DEP = @iDepLink and 
 			G.[DATE] between @dDateBeg and @dDateEnd and
			G.LINK in (select LINK_GC from @cTableReestr)

--select * from @cTemp1

insert into  @cTemp(NAME_DOC, LINK_DEP, NUMBER, [DATE], CON_END, COMMENT, C_TYPE, LINK_OKPD, 
			C_QUANTITY, C_COST, C_SUMMA, GZ_QUANTITY, GZ_COST, GZ_SUMMA, OPL_SUMMA, OPL_SUMMA_B, OPL_SUMMA_V)

select distinct TC.NAME_DOC, TC.LINK_DEP, TC.NUMBER, TC.DATE, TC.CON_DATE,  TC.COMMENT, TC.C_TYPE, 
	LINK_OKPD	= O.LINK,  
	C_QUANTITY	= isnull(case TC.TYPE when 4 then TR.QUANTITY else TC.QUANTITY end,0),
	C_COST		= isnull(case TC.TYPE when 4 then TR.COST else TC.COST end,0),
	C_SUMMA		= isnull(case TC.TYPE when 4 then TR.SUMMA else TC.SUMMA end,0),
	GZ_QUANTITY 	= isnull(TR.QUANTITY,0), 
	GZ_COST		= isnull(TR.COST,0), 
	GZ_SUMMA	= isnull(TR.SUMMA,0),
	OPL_SUMMA	= isnull(TR.SUMMA1,0),
	OPL_SUMMA_B	= isnull(TR.SUMMA1,0),
	OPL_SUMMA_V	= 0
from @cTemp1 TC
full outer join (select LINK_GC = isnull(TR2.LINK_GC,TR1.LINK_GC),
			LINK_OKPD = isnull(TR2.LINK_OKPD,TR1.LINK_OKPD),
			TR2.QUANTITY, 
		     	COST = case TR2.QUANTITY when 0 then 0 else TR2.SUMMA/TR2.QUANTITY * 1000 end, 
		     	TR2.SUMMA, 
		     	SUMMA1 = TR1.SUMMA 
		 from @cTableReestr TR2 
		 full outer join @cTableReestr TR1 on TR1.LINK_GC = TR2.LINK_GC and TR2.LINK_OKPD = TR1.LINK_OKPD
		 where TR2.TYPE = 2 and TR1.TYPE = 1
		 
		 ) TR 
	on TR.LINK_GC = TC.LINK_GC and (TC.LINK_OKPD = TR.LINK_OKPD or TC.TYPE = 4) 
inner join dbo.OKPD O on O.LINK = ISNULL(TC.LINK_OKPD, TR.LINK_OKPD) --and not exists (select * from OKPD OKPD1 where OKPD1.LINK_SELF = O.LINK)

--select * from @cTemp

select 	CODE/*OKPD_CODE*/	= cast(rtrim(cast(O.CODE as char(12))) + '$' + isnull(@cDepCode,'') + '$' + isnull(rtrim(T.NAME_DOC),'') + '$' + isnull(ltrim(rtrim(T.[NUMBER])),'') + '$' + isnull(ltrim(rtrim(ISNULL(CONVERT(VARCHAR(30),T.[DATE],104),''))) ,'') as varchar(50)),
	---CODE/*OKPD_CODE*/	= O.CODE, 
	COL1/*OKPD_CODE*/	= rtrim(O.CODE), 
	COL2/*DOC_NAME*/ 	= rtrim(isnull(cast(T.NAME_DOC + ' № '  + rtrim(T.[NUMBER]) + ' от ' + ISNULL(CONVERT(VARCHAR(30),T.[DATE],104),'') as varchar(254)),'')),
	COL3/*DOC_COMMENT*/	= rtrim(isnull(replace(T.COMMENT,'
',' '),'')),
	COL4/*CON_TYPE_NAME*/	= rtrim(isnull(cast(ZT.NAME as char(100)),'')),
	COL5/*OKPD_NAME*/	= rtrim(O.NAME),
	COL6/*DEP_NAME*/	= cast(isnull(rtrim(D.NAME) + case when D.INN = '' then '' else ' ИНН ' + RTRIM(D.INN) + CASE WHEN D.INN_DOP = '' THEN '' ELSE '/' + D.INN_DOP END end + ' ' + rtrim(isnull(dbo.GetAddressByKladr(D.KLADR_LINK),'')) + CASE when D.HOUSE is null or D.HOUSE = '' then '' else  ' ,' + D.HOUSE end,'') as varchar(250)),
	COL7/*OKPD_UM*/		= isnull(UM.NAME,''),
	COL8/*C_QUANTITY*/	= case when UM.NAME like '%руб%' then 0 else C_QUANTITY end,
	COL9/*GZ_QUANTITY*/	= case when UM.NAME like '%руб%' then 0 else GZ_QUANTITY end,
	COL10/*C_COST*/		= case when UM.NAME like '%руб%' then 0 else C_COST end,
	COL11/*GZ_COST*/	= case when UM.NAME like '%руб%' then 0 else GZ_COST end,
	COL12/*C_SUMMA*/	= C_SUMMA,
	COL13/*GZ_SUMMA*/	= GZ_SUMMA,
	COL14/*OPL_SUMMA*/	= OPL_SUMMA,
	COL15/*OPL_SUMMA_B*/	= OPL_SUMMA,
	COL16/*OPL_SUMMA_V*/	= 0,
	COL17/*CON_END*/	= ISNULL(CONVERT(VARCHAR(30),T.[CON_END],104),''),
	COL18/*OPL_SUMMA_V*/	= case when C_SUMMA = GZ_SUMMA and C_SUMMA = OPL_SUMMA then 'выполнен' else '' end,
	COL19/*CON_END*/	= ISNULL(case D.DEP_TYPE2 when 1 then 'МП' else '' end ,''),
	COL20/*OKPD_CODE*/	= cast(rtrim(cast(O.CODE as char(10))) + '$' + isnull(@cDepCode,'') + '$' + isnull(rtrim(T.NAME_DOC),'') + '$' + isnull(ltrim(rtrim(T.[NUMBER])),'') + '$' + isnull(ltrim(rtrim(ISNULL(CONVERT(VARCHAR(30),T.[DATE],104),''))) ,'') as varchar(50)),
	COL21/*CON_NUM*/	= '',
	COL22/*CON_DATE*/	= '20060101',
	COL23/*NAME_DOC*/	= rtrim(T.[NAME_DOC]),
	COL24/*DOC_NUM*/	= rtrim(T.[NUMBER]),
	COL25/*DOC_DATE*/	= ISNULL(CONVERT(VARCHAR(30),T.[DATE],104),''),
	COL26/*PDEP_NAME*/	= cast(isnull(rtrim(D.NAME),'') as varchar(250)),
	COL27/*PDEP_ADR*/	= isnull(rtrim(cast(dbo.GetAddressByKladr(D.KLADR_LINK) + CASE when D.HOUSE is null or D.HOUSE = '' then '' else ' ,' + D.HOUSE end   as varchar(250))),''),
	COL28/*PDEP_ADR*/	= @cDepCode
/*	OKPD_CODE1		= case LEVEL_OKPD when 2 then O.CODE else '' end,
	OKPD_CODE2		= case LEVEL_OKPD when 3 then O.CODE  else '' end,
	OKPD_CODE3		= case LEVEL_OKPD when 4 then O.CODE  else '' end,
	OKPD_CODE4		= case LEVEL_OKPD when 5 then O.CODE  else '' end,
	OKPD_CODE5		= case LEVEL_OKPD when 6 then O.CODE  else '' end*/

		

from @cTemp T
inner join dbo.OKPD O on O.LINK = T.LINK_OKPD
left join dbo.DICTIONARY_DIGIT UM on O.UM = UM.LINK 
left join dbo.FB_GZ_TYPE ZT on T.C_TYPE = ZT.TYPE
left join dbo.DEPARTMENTS D on T.LINK_DEP = D.LINK 
order by CODE


GO


grant all on BB_GZ_REESTR_REPORT_2014 to public
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RB_PRINT_0503128G_2015]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RB_PRINT_0503128G_2015]

GO

/*
© Кейсистемс (Keysystems), 2009
*/

CREATE PROCEDURE dbo.[RB_PRINT_0503128G_2015]
	@LSF	bigint,
	@bDeleteEmptyRows BIT = NULL,  --  NULL - данные выбираются не для печати, 1 - удаление пустых строк (поле DEL = 1), 0 - не удалять.
    @data int=1, -- c_nastr не будет создаваться!
	@notNullCol tinyint = 0,
	@AtrInOnePage tinyint = 0,
	@WEB_excel tinyint = 0 -- 1 - вызывается для печати из WEB для excel-генератора
AS

if isnull(@WEB_excel, 0) <> 1
	select '' as col1

declare @varKSiParam int, @iLF int, @iLT INT -- 0 - без подитогов, 1 бит - подитоги по ЭКР, 2 бит - подитоги по ВР, 3 бит - подитоги по ЦСР, 4 бит - подитоги по подразделу, 5 бит - подитоги по раздеру, 6 бит - подитоги по администратору
DECLARE @varKSiNoItog INT, @dBeginDate DATETIME

select @iLF = Link_Form, @dBeginDate = Begin_Date from report_saved_forms where link_saved_form = @LSF

set @varKSiParam = 0

if object_id('tempdb..#Param_Print') is NOT NULL
	select @varKSiParam = convert(int, Value) from #Param_Print where Param = 'Poditog'
   select @varKSiNoItog = convert(int, Value) from #Param_Print where Param = 'NoPoditog'

	create table #all (OrderTable tinyint, CODE varchar(50), COL1 varchar(8000), COL2 varchar(10), COL3 varchar(50), COL4 float, COL5 float, COL6 float, COL7 float, COL8 float, COL9 float, COL10 float, COL11 float, COL12 float, orders int IDENTITY(1,1))
	declare @table varchar(100), @RunStr varchar(8000)

------------------------------------------------------------------------------------------------
--- ТАБЛИЦА РАСХОДЫ С ПОДИТОГАМИ
	create table #rash (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(2000), Col2 varchar(1000), Col3 varchar(1000), Col4 varchar(1000), Col5 varchar(1000), Col6 varchar(1000), Col7 float, Col8 float, Col9 float, Col10 float, Col11 float, Col12 float, Col13 float, Col14 float, Col15 float, Col16 varchar(50))

	insert #rash (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	exec dbo.rn_get_all_adm_table 	@LSF, 1, @bDeleteEmptyRows, @AtrInOnePage, 1

	select * into #rash_itog from #rash where 0 > 1

	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	SELECT 1, '00096000000000000000', '1. Бюджетные обязательства по расходам, всего:', '200', '00096000000000000000', sum(COL7), sum(COL8), sum(COL9), sum(COL10), sum(COL11), sum(COL12), sum(COL13), sum(COL14), sum(COL15)
	from #rash 
	where right(rtrim(CODE),17) = '96000000000000000'

---------------------------------------------
/*col1 - наименование показателя
col2 - код строки
col3 - РЗПР
col4 - ЦСР
col5 - ВР
col6 - ЭКР
col15 - Код = АДМ(3) + РЗПР(4) + ЦСР(7) + ВР(3) + ЭКР(3)
*/
select @iLT = Link_Table from report_tables where Link_Form = @iLF and orders = 2
-- добавляем подитоги
if @varKSiParam & 2 = 2 -- подитоги по целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,14) + '000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,14) + '000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,14) + '000000', left(Col16,14) + '000000'
end

if @varKSiParam & 4 = 4 -- подитоги по подразделу
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,7) + '0000000000000', '', max(Col2),max(Col3), '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,7) + '0000000000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,7) + '0000000000000', left(col16,7) + '0000000000000'
end

if @varKSiParam & 8 = 8 -- подитоги по разделу
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,5) + '000000000000000', '', max(Col2),left(col3,2) + '00', '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,5) + '000000000000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,5) + '000000000000000', left(Col16,5) + '000000000000000',left(col3,2) + '00'
end

if @varKSiParam & 16 = 16 -- подитоги по администратору
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,3) + '00000000000000000', '', max(Col2),'000', '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,3) + '00000000000000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,3) + '00000000000000000', left(Col16,3) + '00000000000000000'
end

if @varKSiParam & 32 = 32 -- обнуляем подпрограмму в целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,12) + '00000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,12) + '00000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,12) + '00000000', left(Col16,12) + '00000000'
end

if @varKSiParam & 64 = 64 -- обнуляем программу в целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,10) + '0000000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,10) + '0000000000'
	from #rash
	where col6 = '000' and col5 <> '000'
	group by left(Code,10) + '0000000000', left(Col16,10) + '0000000000'
end

select @iLT = Link_Table from report_tables where Link_Form = @iLF and orders = 1

exec ro_get_name_spr @iLT, 'COL5=SUBSTRING(CODE,15,3)=000#COL4=SUBSTRING(CODE,8,7)=0000000#COL3=SUBSTRING(CODE,4,4)=0000#RN_VIEW_KBK_ADM_M=LEFT(CODE,3)=000', '#rash_itog', @varKScNameCode = 'CODE', @varKScNameName = 'COL1', @varKSiLSF = @LSF


-----------------------------------------------------------------
-----------------------------------------------------------------
------------------------------------------------------------------------------------------------
--- ТАБЛИЦА 3 РАСХОДЫ следующего года С ПОДИТОГАМИ
	create table #rash3 (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(2000), Col2 varchar(1000), Col3 varchar(1000), Col4 varchar(1000), Col5 varchar(1000), Col6 varchar(1000), Col7 float, Col8 float, Col9 float, Col10 float, Col11 float, Col12 float, Col13 float, Col14 float, Col15 float, Col16 varchar(50))

	insert #rash3 (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	exec dbo.rn_get_all_adm_table 	@LSF, 3, @bDeleteEmptyRows, @AtrInOnePage, 1


	INSERT into #rash_itog 
	select checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16 
	from #rash3 where 0 > 1

	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	SELECT 3, '00097000000000000000', '3. Обязательства финансовых годов, следующих за текущим (отчетным) финансовым годом, всего:', '900', '00097000000000000000', sum(COL7), sum(COL8), sum(COL9), sum(COL10), sum(COL11), sum(COL12), sum(COL13), sum(COL14), sum(COL15)
	from #rash3 
	where right(rtrim(CODE),17) = '97000000000000000'

---------------------------------------------
/*col1 - наименование показателя
col2 - код строки
col3 - РЗПР
col4 - ЦСР
col5 - ВР
col6 - ЭКР
col15 - Код = АДМ(3) + РЗПР(4) + ЦСР(7) + ВР(3) + ЭКР(3)
*/
select @iLT = Link_Table from report_tables where Link_Form = @iLF and orders = 3
-- добавляем подитоги
if @varKSiParam & 2 = 2 -- подитоги по целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,14) + '000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,14) + '000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,14) + '000000', left(Col16,14) + '000000'
end

if @varKSiParam & 4 = 4 -- подитоги по подразделу
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,7) + '0000000000000', '', max(Col2),max(Col3), '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,7) + '0000000000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,7) + '0000000000000', left(col16,7) + '0000000000000'
end

if @varKSiParam & 8 = 8 -- подитоги по разделу
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,5) + '000000000000000', '', max(Col2),left(col3,2) + '00', '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,5) + '000000000000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,5) + '000000000000000', left(Col16,5) + '000000000000000',left(col3,2) + '00'
end

if @varKSiParam & 16 = 16 -- подитоги по администратору
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,3) + '00000000000000000', '', max(Col2),'000', '0000000', '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(col16,3) + '00000000000000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,3) + '00000000000000000', left(Col16,3) + '00000000000000000'
end

if @varKSiParam & 32 = 32 -- обнуляем подпрограмму в целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,12) + '00000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,12) + '00000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,12) + '00000000', left(Col16,12) + '00000000'
end

if @varKSiParam & 64 = 64 -- обнуляем программу в целевой статье
begin
	insert #rash_itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
	select 0, 0, 0, max(link_saved_form), 0, 0, 0, 0, left(Code,10) + '0000000000', '', max(Col2),max(Col3), max(Col4), '000', max(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12), sum(Col13), sum(Col14), sum(Col15), left(Col16,10) + '0000000000'
	from #rash3
	where col6 = '000' and col5 <> '000'
	group by left(Code,10) + '0000000000', left(Col16,10) + '0000000000'
end

select @iLT = Link_Table from report_tables where Link_Form = @iLF and orders = 3

exec ro_get_name_spr @iLT, 'COL5=SUBSTRING(CODE,15,3)=000#COL4=SUBSTRING(CODE,8,7)=0000000#COL3=SUBSTRING(CODE,4,4)=0000#RN_VIEW_KBK_ADM_M=LEFT(CODE,3)=000', '#rash_itog', @varKScNameCode = 'CODE', @varKScNameName = 'COL1', @varKSiLSF = @LSF

-----------------------------------------------------------------
-----------------------------------------------------------------
----------------------------------------------
IF isnull(@varKSiNoItog, 0) = 1
BEGIN
   insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
   select 1, R.CODE, COL1, COL2, CODE, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15
   from #rash R
   where right(rtrim(R.CODE),17) <> '96000000000000000' AND right(rtrim(R.CODE),3) NOT IN ('200','000','210','220','230','240','250','260','300','500','600') 
   order by R.Code

   insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
   select 3, R3.CODE, COL1, COL2, CODE, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15
   from #rash3 R3
   where right(rtrim(R3.CODE),17) <> '97000000000000000' AND right(rtrim(R3.CODE),3) NOT IN ('200','000','210','220','230','240','250','260','300','500','600') 
   order by R3.Code
   
   
END
ELSE BEGIN     
-- убираем целевые которых нет в справочнике
   insert #rash
   select distinct checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16
   from #rash_itog A
   WHERE 
   EXISTS (SELECT * FROM R_SPR_CSR_USER_2011 B WHERE ISNULL(begin_date,'20000101') <= @dBeginDate AND isnull(end_date,'20200101') >= @dBeginDate
        AND SUBSTRING(A.CODE,8,7) = B.code)
-- убираем целевые которых нет в справочнике
   insert #rash3
   select distinct checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16
   from #rash_itog A
   WHERE 
   EXISTS (SELECT * FROM R_SPR_CSR_USER_2011 B WHERE ISNULL(begin_date,'20000101') <= @dBeginDate AND isnull(end_date,'20200101') >= @dBeginDate
        AND SUBSTRING(A.CODE,8,7) = B.code)


   insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
   select 1, R.CODE, COL1, COL2, CODE, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15
   from #rash R
   where right(rtrim(R.CODE),17) <> '96000000000000000'
   order by R.Code

   insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
   select 3, R3.CODE, COL1, '910', CODE, COL7, COL8, COL9, COL10, COL11, COL12, COL13, COL14, COL15
   from #rash3 R3
   where right(rtrim(R3.CODE),17) <> '97000000000000000'
   order by R3.Code	
END 

drop table #rash_itog
drop table #rash
drop table #rash3




-------------------------------------------------------------------------------------------------
-- ИСТОЧНИКИ
	create table #ist (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(1000), Col1 varchar(1000), Col2 varchar(1000), Col3 varchar(1000), Col4 float, Col5 float, Col6 float, Col7 float, Col8 float, Col9 float, Col10 float, Col11 float, Col12 float, Col13 varchar(1000))

	insert #ist (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13)
	exec dbo.rn_get_all_adm_table 	@LSF, 2, @bDeleteEmptyRows, @AtrInOnePage, 1

	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	SELECT 2, '00090000000000000000', '2. Бюджетные обязательства по выплатам источников финансирования дефицита бюджета, всего:', '510', '00090000000000000000', sum(COL4), sum(COL5), sum(COL6), sum(COL7), sum(COL8), sum(COL9), sum(COL10), sum(COL11), sum(COL12)
	from #ist 
	where right(rtrim(COL3),17) = '90000000000000000'

-------------------------------------------------------------------------------------------------
-- ИСТОЧНИКИ следующих годов 2
	create table #ist4 (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(1000), Col1 varchar(1000), Col2 varchar(1000), Col3 varchar(1000), Col4 float, Col5 float, Col6 float, Col7 float, Col8 float, Col9 float, Col10 float, Col11 float, Col12 float, Col13 varchar(1000))

	insert #ist4 (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13)
	exec dbo.rn_get_all_adm_table 	@LSF, 4, @bDeleteEmptyRows, @AtrInOnePage, 1

	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	SELECT 4, '00091000000000000000', 'по выплатам источников финансирования дефицита бюджета:', '920', '00091000000000000000', sum(COL4), sum(COL5), sum(COL6), sum(COL7), sum(COL8), sum(COL9), sum(COL10), sum(COL11), sum(COL12)
	from #ist4 
	where right(rtrim(COL3),17) = '91000000000000000'
-----------------------------------------------------------------------------------------

IF isnull(@varKSiNoItog, 0) = 1
BEGIN
	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	select 2, CODE, COL1, COL2, LEFT(CODE,3) + COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12
	from #ist
	where RIGHT(RTRIM(CODE),17) not in (select RIGHT(RTRIM(CD), 17) from dbo.RO_SELECT_FORM_TOTALS_IST_20(0,@iLF ,1) where link_table=@iLT )
	     or code like '%510%01000000000000000%' or code like '%520%01000000000000000%' or code like '%620%02000000000000000%' or code like '%520%02000000000000000%' or code like '%700%01000000000000000%' or code like '%710%01050000000000500%' or code like '%720%01050000000000600%' or code like '%82%000000000000000%'
	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	select 4, CODE, COL1, COL2, LEFT(CODE,3) + COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12
	from #ist4
	where RIGHT(RTRIM(CODE),17) not in (select RIGHT(RTRIM(CD), 17) from dbo.RO_SELECT_FORM_TOTALS_IST_20(0,@iLF ,1) where link_table=@iLT )
	     or code like '%510%01000000000000000%' or code like '%520%01000000000000000%' or code like '%620%02000000000000000%' or code like '%520%02000000000000000%' or code like '%700%01000000000000000%' or code like '%710%01050000000000500%' or code like '%720%01050000000000600%' or code like '%82%000000000000000%'

END
ELSE BEGIN
	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	select 2, CODE, COL1, COL2, LEFT(CODE,3) + COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12
	from #ist
	where right(rtrim(COL3),17) <> '90000000000000000'
	
	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	select 4, CODE, COL1, COL2, LEFT(CODE,3) + COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12
	from #ist4
	where right(rtrim(COL3),17) <> '91000000000000000'
END           

	create table #itog (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(1000), Col2 varchar(1000), Col3 varchar(1000), Col4 float, Col5 float, Col6 float, Col7 float, Col8 float, Col9 float, Col10 float, Col11 float, Col12 float)

	insert #itog (checked, Upd, del, link_saved_form, link_row, orders, Calc_orders, Print_NULL, Code, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
	exec dbo.rn_get_all_adm_table 	@LSF, 5, @bDeleteEmptyRows, @AtrInOnePage, 1


	insert #all (OrderTable, CODE, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, COL9, COL10, COL11, COL12)
	select 5,max(CODE), max(COL1), max(COL2), '              Х', sum(COL4), sum(COL5), sum(COL6), sum(COL7), sum(COL8), sum(COL9), sum(COL10), sum(COL11), sum(COL12)
	from #itog

	drop table #ist
	drop table #itog

	select * from #all order by OrderTable, left(code,3), orders
	drop table #all

	if isnull(@WEB_excel, 0) <> 1
		select cells as style,style as value from report_print_style where link_form=@iLF order by cells


GO


GRANT EXECUTE ON dbo.[RB_PRINT_0503128G_2015] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SAL_DELETE_CHANGE_PERIOD_VAC]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SAL_DELETE_CHANGE_PERIOD_VAC]

GO



/*
© Кейсистемс (Keysystems), 2005
*/





CREATE      PROCEDURE dbo.SAL_DELETE_CHANGE_PERIOD_VAC
	@varKSintLINK	int
AS
DECLARE @varKStrancount	int,
	@varKSObjectLink	int,
	@varKSEventText	varchar(254)

SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN
	SELECT @varKSEventText = 'Документ "Замена расчетного периода БЛ"' + ' ' + str(LINK_EMPL) + ' ' + rtrim(COMMENT) FROM VAC_PERIOD_CHANGE WITH (UPDLOCK) WHERE LINK = @varKSintLINK
	IF @@RowCount = 0 OR @@ERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 2
	END
	DELETE FROM VAC_PERIOD_CHANGE WHERE LINK = @varKSintLINK
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 7
	END
	

IF @@TRANCOUNT > @varKStrancount
	BEGIN
		SELECT @varKSObjectLink = LINK FROM S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC'
		EXECUTE WF_GENERATEEVENT 'Удаление из справочника', @varKSEventText, @varKSObjectLink, 'VAC_PERIOD_CHANGE',@varKSintLINK
		COMMIT TRAN
	END
RETURN 0









GO


GRANT EXECUTE ON dbo.[SAL_DELETE_CHANGE_PERIOD_VAC] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_UPDATE_GZ_PLAN_TABLE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_UPDATE_GZ_PLAN_TABLE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE	PROCEDURE [dbo].BB_UPDATE_GZ_PLAN_TABLE
	@iLink		int	output,
	@iLinkUp	int,
	@iOKDP		int,
	@iOKPD		int,
	@nQuantity	numeric(19,4),
	@nSumma		numeric(19,2),
	@nSummaFB	numeric(19,2),
	@nSummaFV	numeric(19,2)
as
Declare @iError		int,
	@iRowCount	int,
	@iTranCount	int

SET @iTranCount = @@TRANCOUNT
set implicit_transactions on
	if @iLink is null OR @iLink = 0
	BEGIN
		INSERT INTO dbo.GZ_PLAN_TABLE(LINK_UP, OKDP, OKPD, QUANTITY, SUMMA, SUMMA_FB, SUMMA_FV)
			VALUES (@iLinkUp, @iOKDP, @iOKPD, @nQuantity, @nSumma, @nSummaFB, @nSummaFV)
		SELECT @iError = @@ERROR, @iLink = @@IDENTITY
		IF @iError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END
	ELSE
	BEGIN
		UPDATE 	dbo.GZ_PLAN_TABLE
		SET 	LINK_UP	     = @iLinkUp,
			OKDP = @iOKDP,
			OKPD = @iOKPD,  
			QUANTITY     = @nQuantity, 
			SUMMA  	     = @nSumma, 
			SUMMA_FB     = @nSummaFB, 
			SUMMA_FV     = @nSummaFV
		where LINK = @iLink
		select @iError = @@ERROR, @iRowCount = @@ROWCOUNT
		if @iError <> 0
		begin
			rollback
			return 7
		end
		if @iRowCount = 0
		begin
			rollback
			return 2
		end
	end
if @@TRANCOUNT > @iTranCount
	commit tran
return 0



GO


GRANT EXECUTE ON dbo.[BB_UPDATE_GZ_PLAN_TABLE] TO PUBLIC

GO


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_GZ_REESTR_REPORT_ITOG_2014]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[BB_GZ_REESTR_REPORT_ITOG_2014]

GO


create    procedure dbo.BB_GZ_REESTR_REPORT_ITOG_2014 @Void int,--@table int,
@iLSF int
as

declare @tTemp table (LINK_SELF	int, LINK_SF int ,LINK_COL int, CODE_ROW varchar(20), FLOAT_VAL float, ORD int )
declare @iRecCount int, @iOrder int, @iUmCol int, @iNameCol int

set @iOrder = 0

delete
from #report_dinamics 
where patindex('%$$%',CODE_ROW) > 0 

insert into @tTemp
select O.LINK_SELF, RD.LINK_SF, RD.LINK_COL, O.CODE, SUM(RD.float_val), @iOrder
from dbo.OKPD O
inner join #report_dinamics RD ON O.CODE = left(RD.CODE_ROW,charindex('$',RD.CODE_ROW) - 1)
where RD.Link_SF = @iLSF and charindex('$',RD.CODE_ROW) > 0-- and SUM(RD.float_val) <> 0
group by O.LINK_SELF, RD.LINK_SF, RD.LINK_COL, O.CODE

set @iRecCount = @@rowcount

while @iRecCount > 0
begin 
	insert into @tTemp
	select O.LINK_SELF, T.LINK_SF, T.LINK_COL, O.CODE, SUM(T.float_val), @iOrder + 1
	from dbo.OKPD O
	inner join @tTemp T ON O.LINK = T.LINK_SELF and T.ORD = @iOrder
	group by O.LINK_SELF, T.LINK_SF, T.LINK_COL, O.CODE
	set @iRecCount = @@rowcount
	set @iOrder = @iOrder + 1

end


insert into #report_dinamics (link_sf,link_col,Code_row,float_val,str_val)
select link_sf,link_col,rtrim(Code_row)+'$$', SUM(float_val),'' 
from @tTemp
group by link_sf,link_col,Code_row

set @iNameCol = (
select C.LINK_COL
from dbo.REPORT_SAVED_FORMS SF
inner join dbo.REPORT_TABLES T on T.Link_Form = SF.Link_Form and T.Orders = 1
inner join dbo.REPORT_COLOUMNS C on C.Link_Table = T.Link_Table and C.Orders = 5
where SF.Link_Saved_Form = @iLSF)

set @iUmCol = (
select C.LINK_COL
from dbo.REPORT_SAVED_FORMS SF
inner join dbo.REPORT_TABLES T on T.Link_Form = SF.Link_Form and T.Orders = 1
inner join dbo.REPORT_COLOUMNS C on C.Link_Table = T.Link_Table and C.Orders = 7
where SF.Link_Saved_Form = @iLSF)


insert into #report_dinamics (link_sf,link_col,Code_row,float_val,str_val)
select distinct link_sf,@iNameCol,rtrim(Code_row)+'$$', NULL, O.NAME 
from dbo.OKPD O
inner join @tTemp T ON O.CODE = T.CODE_ROW

insert into #report_dinamics (link_sf,link_col,Code_row,float_val,str_val)
select distinct link_sf,@iUmCol,rtrim(Code_row)+'$$', NULL, UM.NAME 
from dbo.OKPD O
inner join @tTemp T ON O.CODE = T.CODE_ROW
inner join dbo.DICTIONARY_DIGIT UM on O.UM = UM.LINK 

--select * from #report_dinamics
grant execute on BB_GZ_REESTR_REPORT_ITOG_2014 to public
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_EXPORT_PP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_EXPORT_PP]

GO

CREATE PROCEDURE dbo.BB_EXPORT_PP
	@cBuffId	varchar(30) = '',
	@cFormat	varchar(30) = ''

AS

DECLARE @iLinkedKBK	tinyint,
	@iGroupKBK	tinyint,
	
		@DATE_MAX	DATETIME,
		@COUNT_DOC	INT,
		@SUM_TOTAL	NUMERIC (28,4),
		@iCity int,
		@iCityP int
		

select @iCity = BANK_CITY from dbo.DOCUMENTS_PAY_OPTIONS
select @iCityP = BANK_CITY from dbo.DOCUMENTS_PAY_OPTIONS
	
set @iLinkedKBK = isnull(dbo.sa_get_option_by_code('NASTR_PAY_LINKED_KBK'),0)
set @iGroupKBK = isnull(dbo.sa_get_option_by_code('NASTR_PAY_GROUP_KBK'),0)

if left(@cFormat,2) = 'TX'
begin 
	DECLARE @iDepLink	int
	set @iDepLink = isnull(dbo.BK_GetDepZB(),dbo.GetOwnDepLink())

	-- Таблица 2 (FROM)
	SELECT 	BUDG_LEVEL  = case D.BUH_TYPE WHEN 1 then cast(replace(B.CODE_EL,'0','') as char(1)) else '6' end,
			KOD_UBP 	= BUDG,
			NAME_UBP	= left(rtrim(D.prefix) + rtrim(D.FULL_NAME) + case when charindex('(',D.prefix,0) > 0 then ')' else '' end,2000),
			0 as link,
			0 as link_up,
			-- Поля для приема выписки
			KOD_TOFK  = '0000',
			NAME_TOFK = space(2000)
			
	from dbo.DEPARTMENTS D
	left join dbo.KL_ADMIN_BS V WITH (NOLOCK) on V.LINK = D.VED_LINK
	left join dbo.KL_BUDG_TYPE B WITH (NOLOCK) on V.Link_Budg = B.LINK
	where D.LINK = @iDepLink


	-- Таблица 3 (TO)
	SELECT 	KOD_TOFK  = TOFK.CODE,
			NAME_TOFK = TOFK.FULL_NAME,
			0 as link,
			0 as link_up,
			-- Поля для приема выписки
			BUDG_LEVEL  = '00',
			KOD_UBP 	= '00000',
			NAME_UBP	= space(2000)
	from dbo.DEPARTMENTS D
	inner join dbo.TREASURY TOFK on D.TOFK_LINK = TOFK.LINK
	where D.LINK = @iDepLink

	-- Таблица 4 (PP)
	IF exists(select * from dbo.DEPARTMENTS where LINK = @iDepLink AND BUH_TYPE < 4)
		SELECT  LINK 	= 0,
			LINK_UP	= 0,
			LS = space(11),
			[DATE]	= MAX(G.DATE),
			GUID_OTCH = space(36),
			KOD_DOC = '  ',
			VID_OTCH = '1',
			KOL		= COUNT(*),
			SUM_TOTAL	= SUM(G.SUMMA)
		FROM dbo.G_PROV G
		inner join dbo.BufferGetTableByID(@cBuffId) B on B.LINK = G.LINK
	else
		SELECT  LINK 	= 0,
			LINK_UP	= 0,
			LS = space(11),
			[DATE]	= '',
			GUID_OTCH = space(36),
			KOD_DOC = '  ',
			VID_OTCH = '1',
			KOL		= 0,
			SUM_TOTAL	= 0
		where 1>2
	
--	IF OBJECT_ID ('TEMPDB..#SMETA_EXPORT_PP') IS NOT NULL
--			EXECUTE ('DROP TABLE #SMETA_EXPORT_PP')

/*	SELECT 
		@DATE_MAX	=	MAX(G.DATE),
		@COUNT_DOC	=	COUNT(*),
		@SUM_TOTAL	=	SUM(G.SUMMA)
	FROM dbo.G_PROV G
	inner join dbo.BufferGetTableByID(@cBuffId) B on B.LINK = G.LINK
*/
/*
	SELECT  LINK 	= 0,
			LINK_UP	= 0,
			LS = space(11),
			[DATE]	= MAX(G.DATE),
			GUID_OTCH = space(36),
			KOD_DOC = '  ',
			KOL		= COUNT(*),
			SUM_TOTAL	= SUM(G.SUMMA)
--	INTO #SMETA_EXPORT_PP		
	FROM dbo.G_PROV G
	inner join dbo.BufferGetTableByID(@cBuffId) B on B.LINK = G.LINK
*/
/*	INNER JOIN dbo.DEPARTMENTS DEP ON (DEP.LINK = G.DEP
		AND DEP.BUH_TYPE < 4)
*/

/*
	IF @cFormat > 'TXPP120101'
		SELECT T1.*
		FROM #SMETA_EXPORT_PP	T1
		INNER JOIN dbo.DEPARTMENTS DEP ON (DEP.LINK = T.DEP
			AND DEP.BUH_TYPE < 4)
	ELSE
			SELECT T1.*
			FROM #SMETA_EXPORT_PP	T1

	DROP TABLE #SMETA_EXPORT_PP
*/
/*	END		
	ELSE
		SELECT  LINK 	= 0,
				LINK_UP	= 0,
				LS = space(11),
				[DATE]	= MAX(G.DATE),
				GUID_OTCH = space(36),
				KOD_DOC = '  ',
				KOL		= COUNT(*),
				SUM_TOTAL	= SUM(G.SUMMA)
		FROM dbo.G_PROV G
		inner join dbo.BufferGetTableByID(@cBuffId) B on B.LINK = G.LINK
*/
		-- Разница в наименовании полей --
		IF OBJECT_ID ('TEMPDB..#SMETA_EXPORT_PPT') IS NOT NULL
				EXECUTE ('DROP TABLE #SMETA_EXPORT_PPT')

		SELECT  LINK 		 = PP.LINK,
				LINK_UP		 = PP.LINK,
				NOM_PP		 = PP.NUMBER,
				DATE_PP		 = PP.DATE,
				SUM_PP		 = PP.SUMMA,
				VID_PL		 = CASE	PP.KIND WHEN 'почтой'     THEN '1'
											 WHEN 'телеграфом' THEN '2'
											 WHEN 'электронно' THEN '3'
											 WHEN 'срочно' 	   THEN '4'
											 ELSE '0' END,
				VID_OPER	= '01', 
				INN_PAY		= PP.S_INN,
				KPP_PAY		= PP.S_KPP,
				--CNAME_PAY	= PP.S_FNAME,
				CNAME_PAY	= dbo.BB_DEP_NAME_FOR_SHABLON(isnull(APO.SHABLON_D,APOD.SHABLON_D), default, PP.S_ACC_LINK),
				BS_PAY		= case PP.S_ACC_TYPE when 1 then PP.S_ACC_NUM else PP.S_SCH_K end,
				BIC_PAY		= PP.S_BIK,
				NAME_BIC_PAY = PP.S_BANK + case isnull(@iCity,0) when 1 then ' ' + isnull(PP.S_BANK_CITY,'') else '' end,
				BS_KS_PAY	= PP.S_SCH_B,
				INN_RCP		= PP.D_INN,
				KPP_RCP		= PP.D_KPP,
				NAME_RCP	= dbo.BB_DEP_NAME_FOR_SHABLON(CASE WHEN PPA.DOH_CODE is not null or PPA.OKATO is not null or P_REASON is not null or PPA.PERIOD is not null or TREBNUM is not null or TREBDATE is not null or P_TYPE is not null or STATUS is not null THEN isnull

(APO.SHABLON_N, APOD.SHABLON_N) else isnull(APO.SHABLON_S, APOD.SHABLON_S) end, default, PP.D_ACC_LINK),
		
				--NAME_RCP	= PP.D_FNAME,
				BS_RCP		= replace(isnull(PP.D_ACC_NUM,PP.D_SCH_K),'00000000000000000000',''),
				BIC_RCP		= PP.D_BIK,
				NAME_BIC_RCP = PP.D_BANK + case isnull(@iCityP,0) when 1 then ' ' + isnull(PP.D_BANK_CITY,'') else '' end,
				BS_KS_RCP	 = PP.D_SCH_B,
				DATE_PAY	= PP.SROK, 
				ORDER_PAY   = PP.[Order],
				PURPOSE = case PP.BK_IN_TGT when 1 then rtrim(replace(replace(replace(replace(replace(replace(
													case isnull(ltrim(rtrim(PP.BO_NUM)),'') when '' then rtrim(dbo.BB_DDELIM_DEL(isnull(APO.LS_FMT, APOD.LS_FMT),'<БО>')) else isnull(APO.LS_FMT, APOD.LS_FMT) end, 
													'<БО>', isnull(ltrim(rtrim(PP.BO_NUM)),'')),
													'<Счет>', case PP.S_ACC_TYPE when 1 then '' else rtrim(PP.S_ACC_NUM) end),
													'<Перевод_строки>', '
	)'),												'<БК>',rtrim(dbo.BB_BK_FOR_SHABLON(PP.LINK, isnull(APO.SHABLON_BK, APOD.SHABLON_BK),isnull(APO.DELIM, APOD.DELIM),isnull(APO.DELIM5, APOD.DELIM5)))),
														--'<БК>',/*str(P.S_ACC_LINK) + '#' +*/ APO.SHABLON_BK /*+ '#' + APO.DELIM + '#' + APO.DELIM5*/),
													'<Руб>',rtrim(ltrim(str(floor(PP.SUMMA))))),
													'<Коп>', right('00' + rtrim(ltrim(str((PP.SUMMA - floor(PP.SUMMA)) * 100))),2))) + ' ' 
					else '' end + ltrim(replace(replace(PP.TARGETTEXT,char(10),''),char(13),'')) + ' ' + ltrim(dbo.PrintPlatporGetNDSString(PP.LINK,0)),

				PAYSTATUS	= PPA.[STATUS],
				KBK			= rtrim(replace(PPA.DOH_CODE,'.','')) + PPA.SGU_CODE,
				OKATO		= PPA.OKATO,
				OSNPLAT		= PPA.P_REASON,
				NAL_PER		= PPA.[PERIOD],
				NOM_DOK		= PPA.TREBNUM,
				DATE_DOK	= case PPA.ZERODATE when 1 then /*'00.00.0000'*/ '0' else CONVERT(CHAR(10),PPA.TREBDATE,104) end,
				TYPE_PL		= PPA.P_TYPE,
				GUID_FK		= '',
				KOD_TOFK_PAY = PP.S_KAZN_CODE,
				NAME_TOFK_PAY	 = PP.S_KAZN,
				KOD_UBP_PAY	= PP.S_BUDG,
				NAME_UBP_PAY = PP.S_FNAME,
				LS_PAY	 = case PP.S_ACC_TYPE when 1 then '' else PP.S_ACC_NUM end,
				LS_PAY_RCP	 = '',
				PRINT_KPP = str(PP.PRINT_KPP),	
				PRIZ = '1',
				-- Поля для приема выписки
				DATE_PP_IN = PP.DATE,
				DATE_PP_SPS = PP.DATE,
				NOM_PL_PO = '',
				SHIFR_RD_PO = '',
				NOM_RD_PO = '',
				DATE_RD_PO = PP.DATE,
				SUM_OST_PO = '',
				OPER_PO = '',
				DATE_IN_TOFK = PP.DATE,
				[GUID] = '',
				UIN_CODE = LTRIM(RTRIM(ISNULL(ppA.UIN_CODE,'')))--CASE WHEN ISNULL(ppA.UIN_CODE,'') = '' THEN CAST('0' AS VARCHAR(20)) ELSE ppA.UIN_CODE END
				--ppA.UIN_CODE
		INTO #SMETA_EXPORT_PPT	
		FROM dbo.DOCUMENTS_PAY PP
		inner join dbo.BufferGetTableByID(@cBuffId) B on B.LINK = PP.LINK
		LEFT JOIN dbo.DOCUMENTS_PAY_ADD PPA on PP.LINK = PPA.LINK
		left join dbo.BB_PAY_ACC_OPTIONS APO on APO.LINK_ACC = PP.S_ACC_LINK
		left join dbo.DOCUMENTS_PAY_ACC_OPTIONS APOD on APOD.OSN = 1
		inner join dbo.DEPARTMENT_ACCOUNTS DA on APOD.LINK_ACC = DA.LINK and PP.S_ACC_TYPE = DA.TYPE

		SELECT *,
			NAME_RCP AS CNAME_UBP_RCP,
			NOM_DOK AS NUM_DOK
		FROM #SMETA_EXPORT_PPT
--	ELSE
-- СNAME_UBP_RCP
--		SELECT * 
--		FROM #SMETA_EXPORT_PP

	DROP TABLE #SMETA_EXPORT_PPT

	if @iGroupKBK = 1
	-- Таблица 5 (PPST)
		select  LINK = GP.LINK,
				LINK_UP = GP.LINK,
				KBK = left(replace(isnull(KBK1.CODE, KBK.CODE),'.','') + SGU.CODE ,20),
				TYPE_KBK = case isnull(KBK1.[TYPE], KBK.[TYPE]) when 1 then '10'
												 when 2 then '20'
												 when 4 then '31'
												 when 8 then '32'
												 else '' end,
				ADD_KLASS = ISNULL(DCL.CODE,''),
				ADD_KLASS_RCP = '',
				[SUM] = sum(GP2.SUMMA),
				DIR_SUM	= '1',
				MES_FIN	= right('0' + rtrim(ltrim(convert(char(2), month(GP.DATE)))),2),
				REZERV	= '',
				KOD_FIN = case D.BUH_TYPE when '1' then SA.cSource else '' end,
				-- Поля для приема выписки
				NUM_BO = '',
				ОКАТО = ''

		from G_PROV GP 
		inner join dbo.BufferGetTableByID(@cBuffId) B on GP.LINK = B.LINK
		inner join G_PROV1 GP1 on GP1.LINK_UP = GP.LINK
		INNER JOIN G_PROV2 GP2 ON GP2.LINK_UP = GP1.LINK
		INNER JOIN G_PROV_AP GPA1 ON GP2.LINK = GPA1.LINK_UP AND DB_KR = 1
		INNER JOIN dbo.DEPARTMENTS D on GP.DEP = D.LINK
		INNER JOIN dbo.S_ACCOUNTS SA on GPA1.ACCOUNT = SA.LINK
		LEFT JOIN KL_KBK KBK ON GPA1.KBK = KBK.LINK
		LEFT JOIN KL_KBK_LINKED KBKL ON KBKL.LINK = KBK.LINK and @iLinkedKBK = 1
		LEFT JOIN KL_KBK KBK1 ON KBKL.LINK_KBK = KBK1.LINK
		LEFT JOIN KOSGU SGU ON isnull(GPA1.EKR,GPA1.SGU) = SGU.LINK
		LEFT JOIN DOP_CLASSIF DCL ON GPA1.AP2 = DCL.LINK
		group by GP.LINK, right('0' + rtrim(ltrim(convert(char(2), month(GP.DATE)))),2), left(replace(isnull(KBK1.CODE, KBK.CODE),'.','') + SGU.CODE ,20), ISNULL(DCL.CODE,''), isnull(KBK1.[TYPE], KBK.[TYPE]),  D.BUH_TYPE, SA.cSource
	else
		select  LINK = GP2.LINK,
				LINK_UP = GP.LINK,
				KBK = left(replace(isnull(KBK1.CODE, KBK.CODE),'.','') + SGU.CODE ,20),
				TYPE_KBK = case isnull(KBK1.[TYPE], KBK.[TYPE]) when 1 then '10'
												 when 2 then '20'
												 when 4 then '31'
												 when 8 then '32'
												 else '' end,
				ADD_KLASS = ISNULL(DCL.CODE,''),
				ADD_KLASS_RCP = '',
				[SUM] = GP2.SUMMA,
				DIR_SUM	= '1',
				MES_FIN	= right('0' + rtrim(ltrim(convert(char(2), month(GP.DATE)))),2),
				REZERV	= '',
				KOD_FIN = case D.BUH_TYPE when '1' then SA.cSource else '' end,
				-- Поля для приема выписки
				NUM_BO = '',
				ОКАТО = ''

		from G_PROV GP 
		inner join dbo.BufferGetTableByID(@cBuffId) B on GP.LINK = B.LINK
		inner join G_PROV1 GP1 on GP1.LINK_UP = GP.LINK
		INNER JOIN G_PROV2 GP2 ON GP2.LINK_UP = GP1.LINK
		INNER JOIN G_PROV_AP GPA1 ON GP2.LINK = GPA1.LINK_UP AND DB_KR = 1
		INNER JOIN dbo.DEPARTMENTS D on GP.DEP = D.LINK
		INNER JOIN dbo.S_ACCOUNTS SA on GPA1.ACCOUNT = SA.LINK
		LEFT JOIN KL_KBK KBK ON GPA1.KBK = KBK.LINK
		LEFT JOIN KL_KBK_LINKED KBKL ON KBKL.LINK = KBK.LINK and @iLinkedKBK = 1
		LEFT JOIN KL_KBK KBK1 ON KBKL.LINK_KBK = KBK1.LINK
		LEFT JOIN KOSGU SGU ON isnull(GPA1.EKR,GPA1.SGU) = SGU.LINK
		LEFT JOIN DOP_CLASSIF DCL ON GPA1.AP2 = DCL.LINK	


end
else
begin

	select
		P.link, 
		P.link as link_up,
		BK_IN_TGT,
		S_ACC_LINK,
		DATE,

		[NUM_PP] = NUMBER,
		[DATE_PP] = DATE,
		[VID_PL] = 
			CASE	
				WHEN KIND = 'почтой'     THEN '1'
				WHEN KIND = 'телеграфом' THEN '2'
				WHEN KIND = 'электронно' THEN '3'
				WHEN KIND = 'срочно' 	 THEN '4'
				ELSE '0' 
			END,
		[SUM_PP] = summa, 
		[INN_PAY] = P.S_INN,
		[KPP_PAY] = case P.PRINT_KPP when 1 then P.S_KPP else '' end,
		[KOD_BP_PAY] = P.S_BUDG,
		[NAME_BP_PAY] = convert(varchar(120), ltrim(rtrim(S_FNAME))),
		[NAME_PAY] = dbo.BB_DEP_NAME_FOR_SHABLON(isnull(APO.SHABLON_D,APOD.SHABLON_D), default, P.S_ACC_LINK), 
		[NUM_LS_PAY] = S_ACC_NUM,
		[KOD_TOFK_PAY] = P.S_KAZN_CODE,
		[INN_OK_PAY] = case P2.INN_OK_PAY when 1 THEN P.S_KAZN_INN ELSE '' END,
		[NM_OK_PAY] = CASE P2.NM_OK_PAY when 1 THEN convert(varchar(120), P.S_KAZN) ELSE '' END,
		[RS_PAY] = case P.S_ACC_TYPE when 1 then P.S_ACC_NUM else P.S_SCH_K end,
		[BIK_PAY] = P.S_BIK,
		[BANK_PAY] = P.S_BANK + case isnull(@iCity,0) when 1 then ' ' + isnull(P.S_BANK_CITY,'') else '' end,
    	[FILIAL_PAY] = case P2.FILIAL_PAY when 1 THEN P.S_BANK_FILIAL ELSE '' END,
		[KS_PAY] = P.S_SCH_B,
		[INN_RCP]=D_INN,
		[KPP_RCP]= case P.PRINT_KPP when 1 then P.D_KPP else '' end,
		[NAME_RCP]=dbo.BB_DEP_NAME_FOR_SHABLON(CASE WHEN P1.DOH_CODE is not null or P1.OKATO is not null or P_REASON is not null or P1.PERIOD is not null or TREBNUM is not null or TREBDATE is not null or P_TYPE is not null or STATUS is not null THEN isnull(APO.

SHABLON_N, APOD.SHABLON_N) else isnull(APO.SHABLON_S, APOD.SHABLON_S) end, default, P.D_ACC_LINK),
		[INN_OK_RCP]= CASE P2.INN_OK_RCP WHEN 1 THEN P.D_KAZN_INN ELSE '' END,
		[NM_OK_RCP] = CASE P2.NM_OK_RCP WHEN 1 THEN P.D_FNAME ELSE '' END,
		[RS_RCP] = case P.D_ACC_TYPE when 1 then P.D_ACC_NUM else P.D_SCH_K end,
		[LS_RCP] = case P.D_ACC_TYPE when 1 then '' else P.D_ACC_NUM end,
		[BIK_RCP] = P.D_BIK,
		[BANK_RCP]= P.D_BANK + case isnull(@iCityP,0) when 1 then ' ' + isnull(P.D_BANK_CITY,'') else '' end,
		[FILIAL_RCP]= CASE P2.FILIAL_RCP when 1 THEN P.D_BANK_FILIAL ELSE '' END,
		[KS_RCP]= P.D_SCH_B,
		[TIME_PAY] = CASE P2.TIME_PAY WHEN 1 THEN srok ELSE cast (null as datetime) END,
		[ORDER_PAY] = P.[ORDER],
		[PURPOSE] = case P.BK_IN_TGT when 1 then rtrim(replace(replace(replace(replace(replace(replace(
													case isnull(ltrim(rtrim(P.BO_NUM)),'') when '' then rtrim(dbo.BB_DDELIM_DEL(isnull(APO.LS_FMT, APOD.LS_FMT),'<БО>')) else isnull(APO.LS_FMT, APOD.LS_FMT) end, 
													'<БО>', isnull(ltrim(rtrim(P.BO_NUM)),'')),
													'<Счет>', case P.S_ACC_TYPE when 1 then '' else rtrim(P.S_ACC_NUM) end),
													'<Перевод_строки>', '
	)'),												'<БК>',rtrim(dbo.BB_BK_FOR_SHABLON(P.LINK, isnull(APO.SHABLON_BK, APOD.SHABLON_BK),isnull(APO.DELIM, APOD.DELIM),isnull(APO.DELIM5, APOD.DELIM5)))),
														--'<БК>',/*str(P.S_ACC_LINK) + '#' +*/ APO.SHABLON_BK /*+ '#' + APO.DELIM + '#' + APO.DELIM5*/),
													'<Руб>',rtrim(ltrim(str(floor(P.SUMMA))))),
													'<Коп>', right('00' + rtrim(ltrim(str((P.SUMMA - floor(P.SUMMA)) * 100))),2))) + ' ' 
					else '' end + ltrim(replace(replace(P.TARGETTEXT,char(10),''),char(13),'')) + ' ' + ltrim(dbo.PrintPlatporGetNDSString(P.LINK,0)),

		[PRINT_KPP]='0',

		[PAYSTATUS] = P1.STATUS,
		[KBKD] = rtrim(ltrim(replace(P1.doh_code,'.',''))) + ltrim(P1.sgu_code),
		[PAYOKATO] = P1.OKATO,
		[OSNPLAT] = P1.P_REASON, 
		[NAL_PER] = P1.PERIOD,
		[N_DOK] = P1.TREBNUM, 
		[D_DOK] = CASE WHEN ISNULL(ZERODATE, 0) = 1 THEN '0' ELSE CONVERT(CHAR(10), P1.TREBDATE,104) END,
		[TYPE_PL] = P1.P_TYPE,
		[Name_Budg] = --convert(char(20), (
						(select top 1 budg.name --budg.code БРАТЬ БЮДЖЕТ ОТПРАВИТЕЛЯ?
						FROM G_PROV1 GP1 INNER JOIN G_PROV2 GP2 ON (GP1.LINK_UP = P.LINK AND GP2.LINK_UP = GP1.LINK)
						INNER JOIN G_PROV_AP GPA1 ON GP2.LINK = GPA1.LINK_UP AND DB_KR = 0
						LEFT JOIN BI_DICTION_KBK F ON GPA1.KBK = F.LINK
						LEFT JOIN kl_admin_bs adm ON adm.link = f.link_ADM 
						LEFT JOIN kl_budg_type budg ON budg.link = adm.link_budg) /* 2005.12 */

	from dbo.documents_pay P
	inner join dbo.BufferGetTableByID(@cBuffId) B on P.LINK = B.LINK
	LEFT OUTER JOIN DOCUMENTS_PAY_ADD P1 ON P.LINK = P1.LINK
	LEFT OUTER JOIN DOCUMENTS_PAY_ADD2 P2 ON P.LINK = P2.LINK
	left join dbo.BB_PAY_ACC_OPTIONS APO on APO.LINK_ACC = P.S_ACC_LINK
	left join dbo.DOCUMENTS_PAY_ACC_OPTIONS APOD on APOD.OSN = 1
	inner join dbo.DEPARTMENT_ACCOUNTS DA on APOD.LINK_ACC = DA.LINK and P.S_ACC_TYPE = DA.TYPE
		

	-- Если платежка налоговая 
	/*
	  1. Если в проводочной части указана Доходная классификация то
	   в блок PPST выгружаем код дохода = код дохода + сгу (20 символов)
	   и сумму - больше ничего !
	  2. Если в проводочной части указана Расходная классификация
	   то выгружаем поблочно раздел, подраздел и т.д. .
	   поле код дохода - пустой
	*/

	if @iGroupKBK = 1
	SELECT
		LINK = GP1.LINK_UP,
		LINK_UP = GP1.LINK_UP,	
		[MARKER] = 'PPST',
		[GLAVA] = LTRIM(RTRIM(COALESCE(F1.ADM_CODE, F.ADM_CODE, ''))),
		[RAZDEL] =LTRIM(RTRIM(COALESCE(F1.DIV_CODE, F.DIV_CODE, ''))),
		[STATIA] = LTRIM(RTRIM(COALESCE(F1.CSR_CODE, F.CSR_CODE, ''))),
		[VID] = LTRIM(RTRIM(COALESCE(F1.EXP_CODE, F.EXP_CODE, ''))),
	--	[KOD_FP] = '',
		[KOD_FP] = convert(varchar(3), isnull(DC.CODE,'')), 
		[E_KLASS] = LTRIM(RTRIM(ISNULL(KEK.CODE, ''))),
		[NUM_BO] =  LTRIM(RTRIM(ISNULL(P.bo_num,''))),
		[MON_FIN]='',
		[SUM_STR] = sum(GP2.summa),
		[FOND_P] = '',
		[KKIVNF] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 8 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,

		[KKIVF] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 4 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,
		[KDOH] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 2 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,

		[ADD_KLASS] = isnull(DC.CODE,''),	/* 2005.12 */
		[KOD_FIN] = (select top 1 left(code, 1) from s_accounts SA where SA.link = GPA1.Account), /* 2005.12 */
		[REZERV] = convert(varchar(40),'')	/* 2005.12 */
	FROM G_PROV1 GP1 
	inner join dbo.BufferGetTableByID(@cBuffId) B on GP1.LINK_UP = B.LINK
	inner join dbo.documents_pay P on P.LINK = B.LINK
	INNER JOIN G_PROV2 GP2 ON GP2.LINK_UP = GP1.LINK
	INNER JOIN G_PROV_AP GPA1 ON GP2.LINK = GPA1.LINK_UP AND DB_KR = 1
	LEFT OUTER JOIN BI_DICTION_KBK_FULL F ON GPA1.KBK = F.LINK
	LEFT JOIN KL_KBK_LINKED KBKL ON KBKL.LINK = F.LINK and @iLinkedKBK = 1
	LEFT JOIN BI_DICTION_KBK_FULL F1 ON KBKL.LINK_KBK = F1.LINK
	LEFT OUTER JOIN DICTIONARY_ITEM KEK ON GPA1.EKR = KEK.LINK
	LEFT OUTER JOIN KOSGU SGU ON GPA1.SGU = SGU.LINK
	LEFT OUTER JOIN BD_DOP_CLASSIF DC on DC.link = GPA1.AP2
	group by GP1.LINK_UP, LTRIM(RTRIM(COALESCE(F1.ADM_CODE, F.ADM_CODE, ''))),
		LTRIM(RTRIM(COALESCE(F1.DIV_CODE, F.DIV_CODE, ''))),
		LTRIM(RTRIM(COALESCE(F1.CSR_CODE, F.CSR_CODE, ''))),
		LTRIM(RTRIM(COALESCE(F1.EXP_CODE, F.EXP_CODE, ''))),
		convert(varchar(3), isnull(DC.CODE,'')), 
		LTRIM(RTRIM(ISNULL(KEK.CODE, ''))),
		LTRIM(RTRIM(ISNULL(P.bo_num,''))),
		CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 8 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,
		CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 4 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,
		CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 2 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,
		isnull(DC.CODE,''),
		GPA1.Account
else
	SELECT
		LINK = GP2.LINK,
		LINK_UP = GP1.LINK_UP,	
		[MARKER] = 'PPST',
		[GLAVA] = LTRIM(RTRIM(COALESCE(F1.ADM_CODE, F.ADM_CODE, ''))),
		[RAZDEL] =LTRIM(RTRIM(COALESCE(F1.DIV_CODE, F.DIV_CODE, ''))),
		[STATIA] = LTRIM(RTRIM(COALESCE(F1.CSR_CODE, F.CSR_CODE, ''))),
		[VID] = LTRIM(RTRIM(COALESCE(F1.EXP_CODE, F.EXP_CODE, ''))),
	--	[KOD_FP] = '',
		[KOD_FP] = convert(varchar(3), isnull(DC.CODE,'')), 
		[E_KLASS] = LTRIM(RTRIM(ISNULL(KEK.CODE, ''))),
		[NUM_BO] =  LTRIM(RTRIM(ISNULL(P.bo_num,''))),
		[MON_FIN]='',
		[SUM_STR] = GP2.summa,
		[FOND_P] = '',
		[KKIVNF] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 8 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,

		[KKIVF] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 4 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,
		[KDOH] = CASE COALESCE(F1.[TYPE], F.[TYPE]) WHEN 2 THEN REPLACE(COALESCE(F1.CODE, F.CODE, ''),'.','') + SGU.CODE else '' end,

		[ADD_KLASS] = isnull(DC.CODE,''),	/* 2005.12 */
		[KOD_FIN] = (select top 1 left(code, 1) from s_accounts SA where SA.link = GPA1.Account), /* 2005.12 */
		[REZERV] = convert(varchar(40),'')	/* 2005.12 */
	FROM G_PROV1 GP1 
	inner join dbo.BufferGetTableByID(@cBuffId) B on GP1.LINK_UP = B.LINK
	inner join dbo.documents_pay P on P.LINK = B.LINK
	INNER JOIN G_PROV2 GP2 ON GP2.LINK_UP = GP1.LINK
	INNER JOIN G_PROV_AP GPA1 ON GP2.LINK = GPA1.LINK_UP AND DB_KR = 1
	LEFT OUTER JOIN BI_DICTION_KBK_FULL F ON GPA1.KBK = F.LINK
	LEFT JOIN KL_KBK_LINKED KBKL ON KBKL.LINK = F.LINK and @iLinkedKBK = 1
	LEFT JOIN BI_DICTION_KBK_FULL F1 ON KBKL.LINK_KBK = F1.LINK
	LEFT OUTER JOIN DICTIONARY_ITEM KEK ON GPA1.EKR = KEK.LINK
	LEFT OUTER JOIN KOSGU SGU ON GPA1.SGU = SGU.LINK
	LEFT OUTER JOIN BD_DOP_CLASSIF DC on DC.link = GPA1.AP2

end





GO


GRANT EXECUTE ON dbo.[BB_EXPORT_PP] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_PRINT_INV_CARD_F0504031]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_PRINT_INV_CARD_F0504031]

GO

/*
© Кейсистемс (Keysystems), 2005
*/
CREATE      PROCEDURE dbo.BK_PRINT_INV_CARD_F0504031
	@varKSc_BufferName	VARCHAR (100)
AS
BEGIN
	DECLARE	@varKSintLINK	INT,
		@varKSnCALC_RATE	NUMERIC (28,4),
		@varKSdDATE_WORK	DATETIME,
		@varKSdDATE_REST	DATETIME,

		@varKSACCT_CODE	VARCHAR (20),
		@varKSDEP		INT,
		@varKSDEP_CODE	VARCHAR (20),
		@varKSDEP_OKPO	VARCHAR (20),
		@varKSDEP_NAME	VARCHAR (254),
		@varKSEMP		INT,
		@varKSEMP_CODE	VARCHAR (20),
		@varKSEMP_NAME	VARCHAR (254),
		@varKSSUB_CODE	VARCHAR (20),
		@varKSSUB_NAME	VARCHAR (254),
		@varKSKBK	INT,
		@varKSACCT	INT,
		@nBALANSE	NUMERIC (28,4),
		@BEGIN_DATE_USED DATETIME,
		@DATE_CALC_REST_AMORT	DATETIME,
		@DATE_AMORT	DATETIME,
		@SUMMA_AM	NUMERIC (28, 4),
		@REST_SUMMA_AM	NUMERIC (28, 4),
		@PREV_SUMMA_AM	NUMERIC (28, 4),
		@YEAR_AM	INT,
		@LAST_RECNO	INT,
		@ACCOUNT_AM	INT,

		@PRN_MOVE_EMP	INT,

		@dDATE_RECALC DATETIME,
		@nSUM_RECALC NUMERIC (28,4),
		@cINFO_RECALC VARCHAR (254)

	SELECT TOP 1 @varKSintLINK = LINK
		FROM dbo.BufferGetTableByID (@varKSc_BufferName)

--	SELECT @varKSdDATE_WORK = DATEADD (DAY, 1, WORKDATE) FROM USER_INFO
	SELECT @varKSdDATE_WORK = WORKDATE FROM dbo.USER_INFO
	SET @varKSdDATE_REST = DATEADD (DAY, 1, @varKSdDATE_WORK) 

	DECLARE @varKSINV_REST TABLE
			(ACCOUNT INT,
			ACCT_SINT VARCHAR (10),
			ACCT_CODE VARCHAR (20),
			DEP INT,
			SUB INT,
			EMP INT,
			INV INT,
			KBK INT,
			SUMMA NUMERIC (28,4))

	INSERT INTO @varKSINV_REST
	SELECT --*
		T1.ACCOUNT,
		SA.cSinth,
		SA.CODE,
		T1.DEP,
		T1.SUB,
		T1.EMP,
		T1.INV,
		T1.KBK,
		CASE 
			WHEN SA.S_ACTIVE = 1 THEN SUM (T1.D_SUMMA)
			WHEN SA.S_PASSIVE = 1 THEN SUM (T1.K_SUMMA)
		END
	FROM dbo.ARestTableByDate (@varKSdDATE_REST, DEFAULT) T1
	INNER JOIN dbo.S_ACCOUNTS SA ON (T1.ACCOUNT = SA.LINK)
	INNER JOIN dbo.BufferGetTableByID (@varKSc_BufferName) BUF ON (BUF.LINK = T1.INV)
--	WHERE T1.INV = @varKSintLINK
	GROUP BY T1.ACCOUNT, T1.DEP, T1.SUB, T1.EMP, T1.INV, T1.KBK, SA.S_ACTIVE, SA.S_PASSIVE, SA.cSinth, SA.CODE

--SELECT * FROM @varKSINV_REST
--SELECT * FROM dbo.ARestTableByDate ('20140101', DEFAULT) T1
	
	SELECT TOP 1
		@varKSACCT_CODE = ACCT_CODE,
		@varKSDEP = DEP.LINK,
		@varKSDEP_CODE = DEP.CODE,
		@varKSDEP_NAME = DEP.NAME, 
		@varKSDEP_OKPO = DEP.OKPO,
		@varKSEMP = EMP.LINK,
		@varKSEMP_CODE = EMP.TAB,
		@varKSEMP_NAME = EMP.NAME_EMPL,
		@varKSSUB_CODE	= SUB.CODE,
		@varKSSUB_NAME	= SUB.[NAME],
		@nBALANSE = SUMMA,
		@varKSKBK = KBK,
		@varKSACCT = T1.ACCOUNT
	FROM @varKSINV_REST T1
	LEFT OUTER JOIN dbo.DICTIONARY_DEPARTMENT DEP ON (DEP.LINK = T1.DEP)
	LEFT OUTER JOIN dbo.KU_EMPL_PLACING EMP ON (EMP.LINK = T1.EMP)
	LEFT OUTER JOIN dbo.DICTIONARY_SUBDIVISION SUB ON (SUB.LINK = T1.SUB)
	WHERE
		T1.ACCT_SINT = '101'
		OR T1.ACCT_SINT = '102'
		OR T1.ACCT_SINT = '103'
		OR T1.ACCT_SINT = '108'

	IF @varKSDEP IS NULL
		SELECT TOP 1
			@varKSDEP = DEP.LINK,
			@varKSDEP_CODE = DEP.CODE,
			@varKSDEP_NAME = DEP.NAME, 
			@varKSDEP_OKPO = DEP.OKPO
		FROM dbo.DICTIONARY_DEPARTMENT DEP 
		WHERE DEP.LINK = COALESCE (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())

	SELECT @varKSnCALC_RATE = SUM (SUMMA)
	FROM @varKSINV_REST T1
	WHERE T1.ACCT_SINT = '104'

	-- Вычисляем переоценку --
	DECLARE @TAB_RECALL TABLE (REC_NO INT IDENTITY, DATE_OPER2 VARCHAR (10), dDATE_OPER DATETIME,
		JO_NUM2 VARCHAR (20), SUMMA2 NUMERIC (20,2))

	INSERT INTO @TAB_RECALL	
	SELECT CONVERT (VARCHAR (10), DATE_OPER, 104) AS DATE_OPER2, DATE_OPER,
		CONVERT (VARCHAR (20), RTRIM (JO_NUM) + '(баланс)') AS JO_NUM2,
		SUMMA AS SUMMA2
	FROM dbo.BK_GetOperationsByOS (@varKSintLINK, @varKSdDATE_WORK,
		'17.15#17.16#17.17#17.18') -- Переоценка ОС

	IF @@ROWCOUNT = 0
		INSERT INTO @TAB_RECALL	 (DATE_OPER2, JO_NUM2, SUMMA2) VALUES ('', '', 0)
	ELSE
	BEGIN

		SELECT TOP 1 @dDATE_RECALC = dDATE_OPER FROM @TAB_RECALL
		IF @dDATE_RECALC IS NOT NULL AND @dDATE_RECALC <= @varKSdDATE_WORK
		BEGIN
			SET @dDATE_RECALC = DATEADD (DAY, 1, @dDATE_RECALC)
			SELECT @nSUM_RECALC = SUM (D_SUMMA)
			FROM dbo.ARestTableByDate (@dDATE_RECALC, DEFAULT) TR
			INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = TR.ACCOUNT)
			WHERE SA.cSINTH = '101'
				AND TR.INV = @varKSintLINK

			IF ISNULL (@nSUM_RECALC, 0) > 0 
				SET @cINFO_RECALC = 'Стоимость после переоценки на '
					+ CONVERT (VARCHAR (10), @dDATE_RECALC, 104) + ' г. '
		END
	END

	SELECT @varKSDEP AS DEP,
		CONVERT (VARCHAR (10), @varKSdDATE_WORK, 104) AS REP_DATE,
		ISNULL (@varKSDEP_CODE, '') AS DEP_CODE,
		ISNULL (@varKSDEP_OKPO, '') AS DEP_OKPO,
		ISNULL (@varKSDEP_NAME, '') AS DEP_NAME,
		ISNULL (@varKSEMP_CODE, '') AS EMP_CODE,
		ISNULL (@varKSEMP_NAME, '') AS EMP_NAME,
		ISNULL (@varKSSUB_CODE, '') AS SUB_CODE,
		ISNULL (@varKSSUB_NAME, '') AS SUB_NAME,
		
		ISNULL (@cINFO_RECALC, '') AS INFRECALC,
		ISNULL (@nSUM_RECALC, 0) AS SUMRECALC,

		T1.LINK,
		ISNULL (T1.CODE, '') AS INV_CODE,
		ISNULL (T1.NAME, '') AS INV_NAME,
		ISNULL (dbo.BK_GetAcctFullCode1 (@varKSACCT, @varKSKBK, NULL, 1, 0), ISNULL (T1.CODE_ACC, '')) AS ACCT_CODE,
		ISNULL (T1.BALANCE, 0)	 AS FIRST_COST,
		ISNULL (T2.CARD_NO, '') AS CARD_NO,
		ISNULL (T2.PASSPORT, '') AS PASSPORT,
		ISNULL (T2.PLANT_NUM, '') AS PLANT_NUM,
		ISNULL (T2.OTHER_NUM, '') AS OTHER_NUM,
		ISNULL (T2.CODE_OKOF, '') AS CODE_OKOF,
		ISNULL (CONVERT (VARCHAR (10), T2.DATE_PROD, 104), '') AS DATE_PROD,
		ISNULL (T2.FIXING, '') AS FIXING,
		ISNULL (T2.LOCATION, '') AS LOCATION,
		ISNULL (T2.MANUFACT, '') AS MANUFACT,		
		ISNULL (CONVERT (VARCHAR (10), T2.DATE_BEGIN, 104), '') AS DATE_BEGIN,
		ISNULL (T2.DOC_NUM, '') AS DOC_BEGIN,
		CASE
			WHEN T2.D_DT_CALC IS NULL THEN ISNULL (T2.PERIOD_USED, 0)
			ELSE (ISNULL (T2.PER_USED, 0)
--				+ ROUND((CONVERT (NUMERIC (19,2), ISNULL((T2.D_DT_CALC - T2.DATE_BEGIN), 0)) / 365.25), 0)
				+ DATEDIFF (MONTH, T2.DATE_BEGIN, T2.D_DT_CALC) - 1)/ 12
		END AS PER_USED,
		ISNULL (T2.D_GRP_CODE, ISNULL (T2.CODE_RATE, ISNULL (T4.CODE, ''))) AS CODE_RATE,
		CASE
			WHEN T2.WEAR_FLAG = 2 THEN CONVERT (NUMERIC (10,2), 0)
			ELSE ISNULL (ND.DEPRE_RATE, 0)
		END AS DEPRE_Y_R,
		CASE
			WHEN T2.WEAR_FLAG = 2 THEN CONVERT (NUMERIC (10,2), 0)
			ELSE CONVERT (NUMERIC (10,2), ISNULL (ND.DEPRE_RATE/12, 0)) 
		END AS DEPRE_M_R,
		CASE
			WHEN T2.WEAR_FLAG = 2 THEN CONVERT (NUMERIC (28,2), 0)
			ELSE CONVERT (NUMERIC (28,2), ISNULL (@nBALANSE * ND.DEPRE_RATE / 100, 0))
		END AS SUM_Y_N,
		CASE
			WHEN T2.WEAR_FLAG = 2 THEN CONVERT (NUMERIC (28,2), 0)
			ELSE CONVERT (NUMERIC (28,2), ISNULL (ND.DEPRE_RATE / 100 / 12 * @nBALANSE, 0))
		END AS SUM_M_N,
		ISNULL (@varKSnCALC_RATE, 0) AS SUM_RATE,
		ISNULL (EMP.NAME_EMPL, '') AS FIL_NAME,
		ISNULL (EMP.POST_NAME, '') AS FIL_POST,
		ISNULL (CONVERT (VARCHAR (10), DATE_FILLING, 104), '') AS FIL_DATE,
		ISNULL (dbo.DateMonthName (month (dbo.CalcLastDateWearOS (T1.LINK)))
			+ SPACE (1) + LTRIM (STR (dbo.CalcLastYearWearOS (T1.LINK))), '') AS LAST_DATE,
		T1.NOTICE AS COMMENT,
		T2.ALOCATION
	FROM dbo.INVENTORY_CARD T1
	LEFT OUTER JOIN dbo.BV_INVENTORY_CARD_DOP T2 ON (T2.LINK_UP = T1.LINK)
	LEFT OUTER JOIN dbo.ASSETS_GROUP_OKOF T3 ON (T3.LINK = T2.LINK_OKOF)
	LEFT OUTER JOIN dbo.DEPRE_GROUP T4 ON (T4.LINK = T3.DEPRE_GROUP)
	LEFT OUTER JOIN dbo.KU_EMPL_PLACING EMP ON (EMP.LINK = T2.LINK_EMP_F)
	LEFT OUTER JOIN dbo.BK_GetNormDepreTableByOS (@varKSintLINK) ND ON (ND.INV = T1.LINK)
	WHERE T1.LINK = @varKSintLINK

	DECLARE @TAB_MODERN TABLE (REC_NO INT IDENTITY, DATE_OPER1 VARCHAR (10),
		JO_NUM1 VARCHAR (20), SUMMA1 NUMERIC (20,2))

	INSERT INTO @TAB_MODERN
	SELECT CONVERT (VARCHAR (10), DATE_OPER, 104) AS DATE_OPER1,
		JO_NUM AS JO_NUM1,
		SUMMA AS SUMMA1
	FROM dbo.BK_GetOperationsByOS (@varKSintLINK, @varKSdDATE_WORK, '17.20') -- Реконструкция, модернизация

	IF @@ROWCOUNT = 0
		INSERT INTO @TAB_MODERN (DATE_OPER1, JO_NUM1, SUMMA1) VALUES ('', '', 0)

	SELECT * FROM @TAB_MODERN

	SELECT * FROM @TAB_RECALL	

	--- Поступление НФА ---
	DECLARE @TAB_INPUT TABLE (REC_NO INT IDENTITY, DATE_OPER1 VARCHAR (10),
		JO_NUM1 VARCHAR (20), SUMMA1 NUMERIC (20,2))

	INSERT INTO @TAB_INPUT	
	SELECT 	CONVERT (VARCHAR (10), DATE_OPER, 104) AS DATE_OPER1,
		JO_NUM AS JO_NUM1,
		SUMMA AS SUMMA1
	FROM dbo.BK_GetOperationsByOS (@varKSintLINK, @varKSdDATE_WORK,
		'17.01#17.02#17.03#17.05#17.06#17.12#17.13') -- Поступление НФА 

	IF @@ROWCOUNT = 0
		INSERT INTO @TAB_INPUT (DATE_OPER1, JO_NUM1, SUMMA1) VALUES ('', '', 0)

	SELECT TOP 1 * FROM @TAB_INPUT

	SELECT @PRN_MOVE_EMP = ISNULL (dbo.XK_GET_NASTR_INT ('INV_CARD_OPT_PRN_MOVE_EMP'), 0)

	SELECT IDENTITY (INT) AS REC_NO,
		ISNULL (T1.DOC_NUM, '') AS DOC_NUM2,
		CONVERT (VARCHAR (10), T1.DATE_OPER, 104) AS DATE_OPER2,
		T1.JO_NUM AS JO_NUM2,
		T1.SUMMA AS SUMMA2,
		ISNULL (dbo.sd_GetEmplName (GAP.EMP), '') AS MOV_EMPL2
	INTO #TAB_MOVED
	FROM dbo.BK_GetOperationsByOS (@varKSintLINK, @varKSdDATE_WORK, '17.07') T1 -- Внутреннее перемещение НФА
	LEFT OUTER JOIN dbo.G_PROV_AP GAP ON (GAP.LINK_UP = T1.LINK_G2
				AND ((@PRN_MOVE_EMP = 1 AND GAP.DB_KR = 0)
					OR (@PRN_MOVE_EMP = 0 AND GAP.DB_KR = 1)))
--	LEFT OUTER JOIN dbo.G_PROV_AP GAP ON (GAP.LINK_UP = T1.LINK_G2 AND GAP.DB_KR = 1) -- поменял в 10604

	IF @@ROWCOUNT = 0
		INSERT INTO #TAB_MOVED (DOC_NUM2, DATE_OPER2, JO_NUM2, SUMMA2, MOV_EMPL2) VALUES ('', '', '', 0, '')

	SELECT * FROM #TAB_MOVED
	DROP TABLE #TAB_MOVED

	DECLARE @TAB_OUTPUT TABLE (REC_NO INT IDENTITY, DATE_OPER3 VARCHAR (10),
		JO_NUM3 VARCHAR (20), SUMMA3 NUMERIC (20,2))

	INSERT INTO @TAB_OUTPUT	
	SELECT 	CONVERT (VARCHAR (10), DATE_OPER, 104) AS DATE_OPER3,
		JO_NUM AS JO_NUM3,
		SUMMA AS SUMMA3
	FROM dbo.BK_GetDateTableOutOS (@varKSintLINK, @varKSdDATE_WORK)

	IF @@ROWCOUNT = 0
		INSERT INTO @TAB_OUTPUT (DATE_OPER3, JO_NUM3, SUMMA3) VALUES ('', '', 0)

	SELECT TOP 1 * FROM @TAB_OUTPUT

	SELECT ISNULL (NAME, '') AS NAME_C,
		ISNULL (BASIC_OBJ, '') AS BASIC_OBJ,
		ISNULL (ATTR1, '') AS ATTR1,
		ISNULL (ATTR2, '') AS ATTR2,
		ISNULL (ATTR3, '') AS ATTR3,
		ISNULL (ATTR4, '') AS ATTR4
	INTO #TAB_CHAR
	FROM dbo.BV_DICTIONARY_SHORT_DESC
	WHERE LINK_UP = @varKSintLINK

	IF @@ROWCOUNT = 0
		INSERT INTO #TAB_CHAR (NAME_C, BASIC_OBJ, ATTR1, ATTR2, ATTR3, ATTR4)
			VALUES ('', '', '', '', '', '')

	SELECT * FROM #TAB_CHAR
	DROP TABLE #TAB_CHAR

	SELECT ISNULL (BASIC_OBJ, '') AS BASIC_OBJ1,
		ISNULL (NAME_PREC, '') AS NAME_PREC,
		ISNULL (NAME_UM, '') AS NAME_UM,
		ISNULL (CODE_UM, '') AS CODE_UM,
		ISNULL (WEIGTH, 0) AS WEIGTH
	INTO #TAB_DRAG
	FROM dbo.BV_DICTIONARY_PRECIOUS_CONTENT
	WHERE LINK_UP = @varKSintLINK

	IF @@ROWCOUNT = 0
		INSERT INTO #TAB_DRAG (BASIC_OBJ1, NAME_PREC, NAME_UM, CODE_UM, WEIGTH)
			VALUES ('', '', '', '', 0)

	SELECT * FROM #TAB_DRAG
	DROP TABLE #TAB_DRAG

	DECLARE @TAB_AMORT TABLE (REC_NO INT IDENTITY,
			SUM_AM NUMERIC (28,4),
			YEAR_AM INT)

	SELECT @BEGIN_DATE_USED = DATE_BEGIN FROM dbo.BV_INVENTORY_CARD_DOP WHERE LINK_UP = @varKSintLINK

	IF @BEGIN_DATE_USED IS NULL
		SET @BEGIN_DATE_USED = @varKSdDATE_WORK
	
--SET @BEGIN_DATE_USED = '20060101'

	SET @DATE_CALC_REST_AMORT = dbo.DateEndOfYear (@BEGIN_DATE_USED)
	SET @YEAR_AM = YEAR (@DATE_CALC_REST_AMORT)
	SET @PREV_SUMMA_AM = 0

	SELECT
		@ACCOUNT_AM = LINK
	FROM dbo.S_ACCOUNTS
	WHERE CODE = '104'	
		AND ZABALANS = 0

	WHILE @YEAR_AM <= YEAR (@varKSdDATE_WORK)
	BEGIN
		SET @DATE_AMORT = DATEADD (DAY, 1, @DATE_CALC_REST_AMORT)

		SET @REST_SUMMA_AM = (SELECT
									SUM (T1.K_SUMMA)
								FROM dbo.ARestTableByDate (@DATE_AMORT, @ACCOUNT_AM) T1
								WHERE T1.INV = @varKSintLINK
								)

/*
	--- !!! ЭТОТ ВАРИАНТ ДЛЯ ВЫВОДА СУММЫ АМОРТИЗАЦИИ, НАЧИСЛЕННОЙ ЗА ГОД!!!

		IF ISNULL (@REST_SUMMA_AM, 0) <> 0
		BEGIN
			SET @SUMMA_AM = @REST_SUMMA_AM - @PREV_SUMMA_AM
			SET @PREV_SUMMA_AM = @REST_SUMMA_AM

			IF @SUMMA_AM > 0
			BEGIN
				INSERT INTO @TAB_AMORT (SUM_AM, YEAR_AM) VALUES (@SUMMA_AM, @YEAR_AM)
				SET @LAST_RECNO = @@IDENTITY
			END
		END

*/
	--- !!! ЭТОТ ВАРИАНТ ДЛЯ ВЫВОДА СУММЫ АМОРТИЗАЦИИ НАРАСТАЮЩИМ ИТОГОМ !!!

		IF ISNULL (@REST_SUMMA_AM, 0) <> 0
		BEGIN
			IF @REST_SUMMA_AM <> @PREV_SUMMA_AM
			BEGIN
				INSERT INTO @TAB_AMORT (SUM_AM, YEAR_AM) VALUES (@REST_SUMMA_AM, @YEAR_AM)
				SET @LAST_RECNO = @@IDENTITY

				SET @PREV_SUMMA_AM = @REST_SUMMA_AM
			END
		END


/*
		IF @SUMMA_AM IS NOT NULL
		BEGIN
			INSERT INTO @TAB_AMORT (SUM_AM, YEAR_AM) VALUES (@SUMMA_AM, @YEAR_AM)
			SET @LAST_RECNO = @@IDENTITY
		END
*/
		SET @DATE_CALC_REST_AMORT = DATEADD (YEAR, 1, @DATE_CALC_REST_AMORT)
		SET @YEAR_AM = YEAR (@DATE_CALC_REST_AMORT)
	END

	IF @LAST_RECNO IS NULL
		INSERT INTO @TAB_AMORT (SUM_AM, YEAR_AM) VALUES (0, 0)		

	SELECT * FROM @TAB_AMORT ORDER BY YEAR_AM

	EXEC dbo.BUFFERCLEAR @varKSc_BufferName
END

GO


GRANT EXECUTE ON dbo.[BK_PRINT_INV_CARD_F0504031] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RSA_4FSS_09022012_PREPARE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RSA_4FSS_09022012_PREPARE]

GO

CREATE PROCEDURE dbo.RSA_4FSS_09022012_PREPARE
	@Res float output, @varcStr varchar(250), @vardBegin datetime = '20050101', @vardEnd datetime = '20051231', @variCol int, @variRow int, @variLSF int
AS 

EXEC dbo.BufferClear

DECLARE @OUT_VAL NUMERIC(20), @START_DATE DATETIME, @END_DATE DATETIME, @DEP_LINK INT

DECLARE --Для выравнивания погрешности
	@C3N NUMERIC(18,6), @C4N NUMERIC(18,6), @C5N NUMERIC(18,6), @C6N NUMERIC(18,6),
	@C3NS NUMERIC(18,6), @C4NS NUMERIC(18,6), @C5NS NUMERIC(18,6), @C6NS NUMERIC(18,6)


select @DEP_LINK = Link_Organization from report_saved_forms where link_saved_form =  @variLSF
set @res = 0
SELECT @START_DATE = @vardBegin, @END_DATE = @vardEnd

DECLARE @BYearDate	datetime
SET @BYearDate = dbo.DateBeginOfYear (@START_DATE)

declare @EndYear datetime
Set @EndYear = dbo.DateEndOfYear(@START_DATE)

DECLARE @nYEAR INT, @nMONTH1 INT, @nMONTH2 INT, @nMONTH3 INT

SELECT 
	@nYEAR = YEAR(@START_DATE),
	@nMONTH1 = MONTH(@START_DATE),
	@nMONTH2 = MONTH(@START_DATE)+1,
	@nMONTH3 = MONTH(@START_DATE)+2

create table #SPR_ESN ([MONTH_BASE] TINYINT, SUMMA_BASE numeric(18,6) default 0.00, DED_M numeric(18,6) default 0.00, INV_M numeric(18,6) default 0.00, SUMMA numeric(18,6) default 0.00, WAY_CALC int default 0.00, REF_PHYS_PERS int default 0, KATEG TINYINT)

Insert InTo #SPR_ESN ([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, KATEG)
Select [MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, KATEG
from dbo.SA_ESN_VIEW(@nYEAR, @nMONTH3, @DEP_LINK, 0) WHERE WAY_CALC = 2
---Суммы по договорникам
INSERT INTO #SPR_ESN 
	([MONTH_BASE], SUMMA_BASE, DED_M, INV_M, SUMMA, WAY_CALC, REF_PHYS_PERS, KATEG)
SELECT 
	MONTH(G.[DATE]) AS MONTH_BASE, GT.SUMMA_BASE, 0, 0, GT.SUMMA, P.WAY_CALC, GT.PERS_LINK,
	KATEG = (CASE WHEN I.LINK IS NULL THEN (F.ENVD + 1) ELSE 3 END)
FROM 
	dbo.SDOC G
	INNER JOIN dbo.SDOC_DGH_TABLE GT ON G.LINK = GT.LINK_UP
	INNER JOIN dbo.PAYS P ON P.LINK = GT.LINK_PAY
	INNER JOIN dbo.SAL_SFIN F ON F.LINK = GT.LINK_VKR
	LEFT JOIN dbo.pers_invalid I ON GT.PERS_LINK = I.PERS_LINK 
	AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH(G.[DATE]),@nYEAR)) BETWEEN I.DATE_BEGIN AND COALESCE(I.DATE_END,'29990101')
WHERE
	G.[OBJECT] =(SELECT LINK FROM S_OBJECTS WHERE CODE = 'DOCUMENTS_DGH')
	AND GT.[OBJECT] = 3
	AND FLAG_JC = 1
	AND P.WAY_CALC = 2
	AND YEAR(G.[DATE]) = @nYEAR
	AND MONTH(G.[DATE]) <= @nMONTH3
	AND LINK_DEP = @DEP_LINK


/*РАЗДЕЛ 2.1*/
DECLARE @BDate datetime, @EndDate datetime, @EDate datetime, @NAvgCount int

SELECT @BDate = @START_DATE, @EndDate = @END_DATE
SET @EDate = dateadd(year,1,convert(varchar, YEAR(@BDate))+'0101')

CREATE TABLE #RES2(CODE_STR VARCHAR(10), BASE_FSS NUMERIC(18,6), CNT_FSS INT, CNT_FEM INT , NUM_PP Varchar(50) default '')

--ОСТАТКИ ПО СЧЁТУ 303.02 НА НАЧАЛО ГОДА
CREATE TABLE #REST_30302_BY ([DATE] DATETIME, REST NUMERIC(18,2))

DECLARE @Cur1 CURSOR, @LINK_ACC INT
SET @Cur1 = CURSOR FORWARD_ONLY

FOR SELECT LINK FROM dbo.S_ACCOUNTS WHERE CODE LIKE '303.02%'

OPEN @Cur1
FETCH NEXT FROM @Cur1 INTO @LINK_ACC
WHILE (@@fetch_status <> -1)
BEGIN

	IF (@@fetch_status <> -2)
	BEGIN

		INSERT INTO #REST_30302_BY ([DATE], REST)
		SELECT @BYearDate, REST = coalesce(sum(K_SUMMA)-sum(D_SUMMA),0) 
		FROM dbo.ARestGroupedTableByDate (@BYearDate, @LINK_ACC, DEFAULT)
		WHERE DEP_LINK = @DEP_LINK
	END

	FETCH NEXT FROM @Cur1 INTO @LINK_ACC
END

CLOSE @Cur1
DEALLOCATE @Cur1

--ОСТАТКИ ПО СЧЁТУ 303.02 НА КОНЕЦ ОТЧЕТНОГО КВАРТАЛА
DECLARE @QV_DATE DATETIME
SET @QV_DATE = @END_DATE+1

SET @Cur1 = CURSOR FORWARD_ONLY

FOR SELECT LINK FROM dbo.S_ACCOUNTS WHERE CODE LIKE '303.02%'

OPEN @Cur1
FETCH NEXT FROM @Cur1 INTO @LINK_ACC
WHILE (@@fetch_status <> -1)
BEGIN

	IF (@@fetch_status <> -2)
	BEGIN

		INSERT INTO #REST_30302_BY ([DATE], REST)
		SELECT @END_DATE, REST = coalesce(sum(K_SUMMA)-sum(D_SUMMA),0) 
		FROM dbo.ARestGroupedTableByDate (@QV_DATE, @LINK_ACC, DEFAULT)
		WHERE DEP_LINK = @DEP_LINK
	END

	FETCH NEXT FROM @Cur1 INTO @LINK_ACC
END

CLOSE @Cur1
DEALLOCATE @Cur1

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0101', SUM(REST), 0, 0 FROM #REST_30302_BY WHERE [DATE] = @BYearDate HAVING SUM(REST) > 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0112', -SUM(REST), 0, 0 FROM #REST_30302_BY WHERE [DATE] = @BYearDate HAVING SUM(REST) < 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0109', -SUM(REST), 0, 0 FROM #REST_30302_BY WHERE [DATE] = @END_DATE HAVING SUM(REST) < 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0119', SUM(REST), 0, 0 FROM #REST_30302_BY WHERE [DATE] = @END_DATE HAVING SUM(REST) > 0



--- Номера платежек 
CREATE TABLE #PLAT (VID TINYINT, Y INT, MON TINYINT, SUMMA NUMERIC(18,2), Y_p INT, MON_p TINYINT, NUMBER VARCHAR(10))

	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'

	INSERT INTO BUFFER (link, id)
	select link, 'DT' from s_accounts where cSinth = '303' and cAnalit = '02' --С 290экр НЕ ДОЛЖЕН БРАТЬСЯ

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '304' and cAnalit = '05'

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '201' and (cAnalit = '11' or cAnalit = '21' or cAnalit = '27')

	INSERT INTO #PLAT (VID, Y, MON, SUMMA,Y_P,MON_P,NUMBER)
	SELECT  1,
		Y = CONVERT(INT,YEAR(p.DATE_PROV)), 
		MON = CONVERT(INT,MONTH(p.DATE_PROV)),
		P.SUMMA,  
		Y_P = CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,3,'.')), 
		MON_P = CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')),
		P.NUMBER	
	from 
		dbo.AProvByBufferConditionsShortDate(@START_DATE, @END_DATE, 'DT', 'KT') P	
		inner join dbo.DOCUMENTS_PAY_ADD PA on P.link = PA.link
		inner join dbo.g_prov G on G.link = PA.link
		LEFT JOIN dbo.KOSGU DG ON DG.LINK = P.DT_EKR
	WHERE
		P.DEP_LINK = @DEP_LINK
		AND
		G.DEP = @DEP_LINK
		--AND
		--CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')) <= @M
		--AND
		--CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,3,'.')) = @Y
		AND
		DG.CODE <> '290'

	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'
	
	
	
INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '01163', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT WHERE Y >= @nYEAR and MON = @nMONTH1), 
		'', 
		0   

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '01164', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT WHERE Y >= @nYEAR and MON = @nMONTH2), 
		'', 
		0   

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '01165', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT WHERE Y >= @nYEAR and MON = @nMONTH3), 
		'', 
		0   

--- Сведения по номерам платежек
SELECT  VID,
		Y , 
		MON ,
		NUMBER	
INTO #PLAT_PP
FROM #PLAT 
GROUP  BY VID , Y , MON, NUMBER

DROP TABLE #PLAT

BEGIN 
	declare @Cur cursor , @VID tinyint , @Y INT, @MON TINYINT, @NUMBER VARCHAR(10)

	SET @Cur = CURSOR FORWARD_ONLY
	FOR 
		select VID, Y, MON, NUMBER from #PLAT_PP order by VID, Y, MON, NUMBER
	OPEN @Cur
	FETCH NEXT FROM @Cur INTO @VID, @Y, @MON, @NUMBER
	
	WHILE (@@fetch_status <> -1)
	BEGIN
		
		IF (@@fetch_status <> -2)
		BEGIN	
			if  @Y = @nYEAR and @MON = @nMONTH1
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER)) end )
				where code_str = '01163' 

			if  @Y = @nYEAR and @MON = @nMONTH2
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER)) end )
				where code_str = '01164'

			if  @Y = @nYEAR and @MON = @nMONTH3
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER)) end )
				where code_str = '01165'				

		end
		FETCH NEXT FROM @Cur INTO @VID, @Y, @MON, @NUMBER
	end

CLOSE @Cur
DEALLOCATE @Cur

END 

drop table #PLAT_PP

-- exec dbo.RI_REPORT_FORMULA_ALL_CALCULATE '2014-01-01 00:00:00','2014-03-31 00:00:00',2,1,2745
/*declare @Res float
set @Res = 0
 exec dbo.RSA_4FSS_09022012_PREPARE @Res output, '', '20140101', '20140331', 2, 1, 2745
*/

/********СРЕДНЕСПИСОЧНАЯ ЧИСЛЕННОСТЬ**********/

/* Среднесписочная численность работающих инвалидов */
Set @NAvgCount = convert(numeric(18,0), dbo.sa_ssch_empls(@START_DATE, @END_DATE, @DEP_LINK, 0, 1, 1, DEFAULT))

INSERT INTO #RES2
SELECT '3', 0, @NAvgCount, 0, ''

/* Среднесписочная численность мужчин и женщин */
Set @NAvgCount = convert(numeric(18,0), dbo.sa_ssch_empls(@START_DATE, @END_DATE, @DEP_LINK, 0, 1, 0, DEFAULT))
INSERT INTO #RES2
SELECT '1', 0, @NAvgCount, 0, ''

/* Среднесписочная численность женщин */
INSERT INTO #RES2
SELECT '2', 0, convert(numeric(18,0), dbo.sa_ssch_empls(@START_DATE, @END_DATE, @DEP_LINK, 2, 1, 0, DEFAULT)), 0 , ''

/* Среднесписочная численность работающих во вредных условиях */
INSERT INTO #RES2
SELECT '4', 0, convert(numeric(18,0), dbo.sa_ssch_empls(@START_DATE, @END_DATE, @DEP_LINK, 0, 1, 2, DEFAULT)), 0 , ''


--Р1.ТАБЛИЦА 1
--Начислено ЕСН. На НАч квартала
INSERT INTO #RES2 --код=табл. 02, строка 3_1
SELECT '0121', ISNULL(SUM(SUMMA),0), 0, 0 , '' FROM #SPR_ESN WHERE MONTH_BASE < @nMONTH1  

--Начислено ЕСН. 1 мес
INSERT INTO #RES2 --код=табл. 02, строка 3_3
SELECT '0123', ISNULL(SUM(SUMMA),0), 0, 0 , '' FROM #SPR_ESN WHERE MONTH_BASE = @nMONTH1

--Начислено ЕСН. 2 мес
INSERT INTO #RES2 --код=табл. 02, строка 3_4
SELECT '0124', ISNULL(SUM(SUMMA),0), 0, 0, '' FROM #SPR_ESN WHERE MONTH_BASE = @nMONTH2
--
--Начислено ЕСН. 3 мес
INSERT INTO #RES2 --код=табл. 02, строка 3_5
SELECT '0125', ISNULL(SUM(SUMMA),0), 0, 0, '' FROM #SPR_ESN WHERE MONTH_BASE = @nMONTH3

--Р1.ТАБЛИЦА 2

DECLARE 
	@P02010 INT, --Количество больничных
	@P02013 NUMERIC(18,2),  --Количество больничных дней 
	@P02014 NUMERIC(18,2), --Сумма по больничным за счет ФСС

	@P02020 INT, --Количество больничных по внешнему совместительству
	@P02023 NUMERIC(18,2),  --Количество больничных дней по внешнему совместительству
	@P02024 NUMERIC(18,2), --Сумма по больничным за счет ФСС по внешнему совместительству
	
	@P02030 INT, --Количество больничных По беременности и родам
	@P02033 NUMERIC(18,2),  --Количество По беременности и родам дней
	@P02034 NUMERIC(18,2), --Сумма По беременности и родам за счет ФСС

	@P02040 INT, -- Количество больничных по беременности и родам по внешнему совместительству
	@P02043 NUMERIC(18,2),  --Количество дней по беременности и родам по внешнему совместительству
	@P02044 NUMERIC(18,2),  --Сумма по беременности и родам за счет ФСС по внешнему совместительству

	-- Ежемесячное пособие по уходу за ребенком по основному месту работы за первым
	@P02080 INT, --количество получателей
	@P02083 NUMERIC(18,2),  -- количество произведенных выплат
	@P02084 NUMERIC(18,2), -- сумма расходов

	-- Ежемесячное пособие по уходу за ребенком по основному месту работы за вторым и последующим
	@P02090 INT, --количество получателей
	@P02093 NUMERIC(18,2),  -- количество произведенных выплат
	@P02094 NUMERIC(18,2) -- сумма расходов

---	
SELECT 
	@P02010 = COUNT(DISTINCT (CASE WHEN COALESCE(A.DEKRET,0) = 1 THEN NULL ELSE A.LINK END) ),
	@P02020 = COUNT( DISTINCT CASE WHEN STATUS_EMPL = 3 AND COALESCE(A.DEKRET,0) = 0 THEN A.LINK ELSE NULL END), 
	@P02030 = COUNT(DISTINCT (CASE WHEN COALESCE(A.DEKRET,0) = 1 THEN A.LINK ELSE NULL END) ), 
	@P02040 = COUNT( DISTINCT CASE WHEN STATUS_EMPL = 3 AND COALESCE(A.DEKRET,0) = 1 THEN A.LINK ELSE NULL END) 
FROM 
	DBO.DOCUMENTS_ADD_ARCHE A INNER JOIN dbo.SD_EMPL E ON A.REF_EMPL = E.LINK
	INNER JOIN DBO.SDOC_ADIS_TABLE1 T ON T.LINK_UP = A.LINK AND T.PAYER = 0
	inner join dbo.DIS d on d.link = a.ref_arhe 
WHERE 
	A.LINK_DEP = @DEP_LINK 
	AND A.FLAG_JC = 1 --НАЧИСЛЕННЫЕ
	AND YEAR(A.[DATE]) = YEAR(@BYearDate) --НАЧИСЛЕННЫЕ В ЗАДАННОМ ГОДУ
	AND MONTH(A.[DATE]) <= MONTH(@END_DATE) --НАЧИСЛЕННЫЕ ПО ЗАДАННЫЙ МЕСЯЦ
	and isnull(D.REF_DOC,0) = 0

---	
SELECT 
	@P02013 = SUM( (CASE WHEN COALESCE(A.DEKRET,0) = 1 THEN 0 ELSE 1 END) * ISNULL(A.FSS_DAYS,0)), --(DATEDIFF(DAY,T.DATE1,T.DATE2)+1) ),	
	@P02023 = SUM( (CASE WHEN STATUS_EMPL = 3 THEN 1 ELSE 0 END) * (CASE WHEN COALESCE(A.DEKRET,0) = 1 THEN 0 ELSE 1 END)  * ISNULL(A.FSS_DAYS,0)),--* (DATEDIFF(DAY,T.DATE1,T.DATE2)+1) ),	
	--по беременности и родам записывать все оплачиваемые дни, а не только те, которые входят в оплачиваемый период
	@P02033 = SUM(  COALESCE(A.DEKRET,0)  * ISNULL(A.FSS_DAYS,0)),--* (DATEDIFF(DAY,T.DATE1,T.DATE2)+1) ),	
	--по беременности и родам записывать все оплачиваемые дни, а не только те, которые входят в оплачиваемый период
	@P02043 = SUM( (CASE WHEN STATUS_EMPL = 3  AND COALESCE(A.DEKRET,0) = 1 THEN 1 ELSE 0 END)  * ISNULL(A.FSS_DAYS,0))--* (DATEDIFF(DAY,T.DATE1, T.DATE2)+1) )	
FROM 
	DBO.DOCUMENTS_ADD_ARCHE A INNER JOIN dbo.SD_EMPL E ON A.REF_EMPL = E.LINK 
WHERE 
	LINK_DEP = @DEP_LINK 
	AND FLAG_JC = 1 --НАЧИСЛЕННЫЕ
	AND YEAR(DATE) = YEAR(@BYearDate) --НАЧИСЛЕННЫЕ В ЗАДАННОМ ГОДУ
	AND MONTH(DATE) <= MONTH(@END_DATE) --НАЧИСЛЕННЫЕ ПО ЗАДАННЫЙ МЕСЯЦ

SELECT P.F4FSS, E.[STATUS], CNT_EMPL = COUNT(DISTINCT J.LINK_EMPL), CNT = COUNT( J.LINK_EMPL),SUMMA = SUM(SUMMA), CNT_DAYS = SUM([DAYS])
INTO #ATR_4FSS
FROM 
	dbo.ATRIBUT_F4FSS A
	INNER JOIN dbo.PAYS P ON A.LINK = P.F4FSS
	INNER JOIN dbo.CALCULATE_JURNAL J ON P.LINK = J.LINK_PAYS
	INNER JOIN DBO.SA_EMPLS_INFO(@END_DATE, DEFAULT) E ON E.EMPL_LINK = J.LINK_EMPL 	
WHERE
	Year(period_begin) = @nYEAR and Month(period_begin) <= @nMONTH3
	and J.LINK_DEP = @DEP_LINK
	and P.[OBJECT] = 1	
	and P.F4FSS > 1
	AND J.LINK_EKR = (SELECT LINK FROM KOSGU WHERE CODE = '213')	
GROUP BY 	
	P.F4FSS, E.[STATUS]

--ВЫПЛАТА ПОСОБИЙ По временной нетрудоспособности
-----Число дней на больничном
INSERT INTO #RES2 --код=табл. 02, строка 01
SELECT '0201', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 2),0), --ISNULL(@P02014,0), 
	@P02013, @P02010, ''
	

-----Число дней на больничном по внешнему совместительству
INSERT INTO #RES2 --код=табл. 02, строка 02
SELECT '0202', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 2 AND [STATUS] = 3),0),--ISNULL(@P02024,0), 
	@P02023, @P02020, ''

-----Число дней по берем и родам
INSERT INTO #RES2 --код=табл. 02, строка 03
SELECT '0203', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 3),0),--@P02034, 
	@P02033, @P02030, ''


-----Число дней по берем и родам по внешнему совместительству
INSERT INTO #RES2 --код=табл. 02, строка 04
SELECT '0204', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 3 AND [STATUS] = 3),0),--@P02044, 
	@P02043, @P02040, ''

INSERT INTO #RES2
SELECT '0205', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 4),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 4),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 4),0)	, ''

INSERT INTO #RES2
SELECT '0206', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 5),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 5),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 5),0)	, ''

---- Ежемесячное пособие по уходу за ребенком по основному месту работы
INSERT INTO #RES2
SELECT '0208',
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 6),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 6),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 6),0)	, ''

INSERT INTO #RES2
SELECT '0209',
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 7),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 7),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 7),0)	, ''

INSERT INTO #RES2
SELECT '0210', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 8),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 8),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 8),0)	, ''

INSERT INTO #RES2
SELECT '0211', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 9),0),
	ISNULL((SELECT SUM(CNT) FROM #ATR_4FSS WHERE F4FSS = 9),0),	
	ISNULL((SELECT SUM(CNT_EMPL) FROM #ATR_4FSS WHERE F4FSS = 9),0)	, ''	

--Р1.ТАБЛИЦА 3

Declare @StBase2 table (link int)
Insert into @StBase2 (link)
select distinct link_pays from tax_ref where link_tax = (select top 1 link from pays where object = 3 and way_calc = 2)

DECLARE @LINK_EKR213 INT
SET @LINK_EKR213 = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '213')

DECLARE @ESN_213 INT --Начислять страховые взносы на доходы с 213 ЭКР                                                    
SET @ESN_213 = dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_5')

--Фактическая база для договорников
SELECT GT.PERS_LINK, MONTH(G.[DATE]) AS MONTH_BASE, SUMMA_BASE = sum(GT.SUMMA_BASE)
INTO #DGH_FAKT_BASE
FROM 
	dbo.DOCUMENTS_DGH G INNER JOIN dbo.DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
WHERE 
	FLAG_JC = 1
	AND GT.WAY_CALC  = 2
	AND YEAR(G.[DATE]) = @nYEAR
	AND MONTH(G.[DATE]) <= @nMONTH3 
GROUP BY GT.PERS_LINK, MONTH(G.[DATE])

CREATE TABLE #DGH_CJ (PERS_LINK INT, PERIOD_BEGIN DATETIME, SUMMA NUMERIC(18,6))
INSERT INTO #DGH_CJ (PERS_LINK, PERIOD_BEGIN, SUMMA)
SELECT PERS_LINK, PERIOD_BEGIN, SUM(SUMMA)
FROM dbo.CALCULATE_JURNAL CJ
	INNER JOIN DBO.PERSON P1 ON P1.LINK = CJ.PERS_LINK
	INNER JOIN DBO.PAYS P ON P.LINK = CJ.LINK_PAYS
WHERE
	yEAR(CJ.period_begin) = @nYEAR
	AND CJ.LINK_DEP = @DEP_LINK
	AND P.[OBJECT] = 1
GROUP BY
	PERS_LINK, PERIOD_BEGIN


---------
SELECT MON, SUMMA_ALL = SUM(SUMMA_ALL), SUMMA_NO = SUM(SUMMA_NO)
INTO #SALARY_SUM2
FROM 
(
select 
	MON = Month(CJ.PERIOD_BEGIN),
	SUMMA_ALL = SUM(SUMMA),
	SUMMA_NO = SUM(CASE WHEN B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0 THEN SUMMA ELSE 0 END) --на которые не начисляются страховые взносы
from 
	dbo.CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
	INNER JOIN DBO.EMPL E ON E.LINK = CJ.LINK_EMPL
	LEFT JOIN @StBase2 B ON B.LINK = cj.LINK_PAYS
where 	
	Year(CJ.period_begin) = @nYEAR and Month(CJ.period_begin) <= @nMONTH3 
	and CJ.LINK_DEP = @DEP_LINK
	and P.[OBJECT] = 1
GROUP BY
	Month(CJ.PERIOD_BEGIN)
UNION ALL	
select 
	MON = Month(CJ.PERIOD_BEGIN),
	SUMMA_ALL = SUM(SUMMA),
	SUMMA_NO = SUM(SUMMA - ISNULL(B.SUMMA_BASE,0)) --на которые не начисляются страховые взносы
from 
	#DGH_CJ CJ
	LEFT JOIN #DGH_FAKT_BASE B ON B.PERS_LINK = CJ.PERS_LINK AND B.MONTH_BASE = Month(CJ.PERIOD_BEGIN)
where 	
	Month(CJ.period_begin) <= @nMONTH3 
GROUP BY
	Month(CJ.PERIOD_BEGIN)
) AS T
GROUP BY 
	MON
	
--Суммы выплат и иных вознаграждений, начисленных в пользу физических лиц, в соответствии со ст.7 Федерального закона от 24 июля 2009 г. № 212-ФЗ
INSERT INTO #RES2 SELECT '030103', SUM(SUMMA_ALL), 0, 0, '' FROM #SALARY_SUM2
INSERT INTO #RES2 SELECT '030104', SUM(SUMMA_ALL), 0, 0, '' FROM #SALARY_SUM2 WHERE MON = @nMONTH1
INSERT INTO #RES2 SELECT '030105', SUM(SUMMA_ALL), 0, 0, '' FROM #SALARY_SUM2 WHERE MON = @nMONTH2
INSERT INTO #RES2 SELECT '030106', SUM(SUMMA_ALL), 0, 0, '' FROM #SALARY_SUM2 WHERE MON = @nMONTH3


--select * from #RES2 where CODE_STR in ('030103', '030104', '030105', '030106')
DECLARE @TMP_VAL NUMERIC(18,2)
--Суммы, не подлежащие обложению страховыми взносами в соответствии со ст.9 Федерального закона от 24 июля 2009 г. № 212-ФЗ
--INV_M теперь содержит только льготы (100 тыс инвалидам теперь нет)
SET @TMP_VAL = ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN ) ,0) + ISNULL( (SELECT SUM(SUMMA_NO) FROM #SALARY_SUM2),0)
INSERT INTO #RES2 VALUES('030203', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN  WHERE MONTH_BASE = @nMONTH1) ,0) + ISNULL( (SELECT SUM(SUMMA_NO) FROM #SALARY_SUM2 WHERE MON = @nMONTH1),0)
INSERT INTO #RES2 VALUES('030204', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN  WHERE MONTH_BASE = @nMONTH2) ,0) + ISNULL( (SELECT SUM(SUMMA_NO) FROM #SALARY_SUM2 WHERE MON = @nMONTH2),0)
INSERT INTO #RES2 VALUES('030205', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(DED_M) + SUM(INV_M) FROM #SPR_ESN  WHERE MONTH_BASE = @nMONTH3) ,0) + ISNULL( (SELECT SUM(SUMMA_NO) FROM #SALARY_SUM2 WHERE MON = @nMONTH3),0)
INSERT INTO #RES2 VALUES('030206', @TMP_VAL, 0, 0, '')

--select * from #RES2 where CODE_STR in ('030203', '030204', '030205', '030206')

DECLARE @LIMIT NUMERIC(18,2)

SELECT @LIMIT = MAX(S.PREDEL)
FROM 
	dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2
WHERE 
	DATE = (SELECT TOP 1 [DATE] FROM dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2 AND DATE < @END_DATE ORDER BY [DATE] DESC) 
	AND
	S.PERCENT1 > 0

SET @LIMIT = ISNULL(@LIMIT,0)


--  тариф, применяемый  свыше установленного предела величины базы (%)
DECLARE 
	@PERCENT1 NUMERIC(18,2),
	@PERCENT1_IN NUMERIC(18,2)
--	@PERCENT_FSS NUMERIC(18,2)

-- Рабочие 	
SELECT @PERCENT1 = S.PERCENT1
FROM 
	dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2
WHERE 
	predel = @LIMIT
	and tarif =1
	and 
	DATE = (SELECT TOP 1 [DATE] FROM dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2 AND DATE < @END_DATE ORDER BY [DATE] DESC) 
	AND
	S.PERCENT1 > 0
-- нивалиды
SELECT @PERCENT1_IN = S.PERCENT1
FROM 
	dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2
WHERE 
	predel = @LIMIT
	and tarif =3
	and 
	DATE = (SELECT TOP 1 [DATE] FROM dbo.STAVKI S INNER JOIN DBO.PAYS P ON S.LINK_PAYS = P.LINK AND P.OBJECT = 3 AND P.WAY_CALC = 2 AND DATE < @END_DATE ORDER BY [DATE] DESC) 
	AND
	S.PERCENT1 > 0

SET @PERCENT1 = ISNULL(@PERCENT1,0)
SET @PERCENT1_IN = ISNULL(@PERCENT1_IN,0)

SELECT MON = 1, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END INTO #SPR_ESN1 FROM #SPR_ESN WHERE MONTH_BASE <= 1 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 2, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 2 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 3, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 3 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 4, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 4 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 5, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 5 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 6, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 6 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 7, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 7 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 8, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 8 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 9, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 9 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 10, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 10 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 11, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 11 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1 SELECT MON = 12, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE MONTH_BASE <= 12 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS

SELECT DISTINCT T.REF_PHYS_PERS, M.M, SUMMA = ISNULL(T1.SUMMA,0) - ISNULL(T2.SUMMA,0)
INTO #SPR_ESN2
FROM 
	#SPR_ESN1 T INNER JOIN dbo.months_ex(@BYearDate, @END_DATE) M ON 1=1
	LEFT JOIN #SPR_ESN1 T1 ON T1.REF_PHYS_PERS = T.REF_PHYS_PERS AND T1.MON = M.M
	LEFT JOIN #SPR_ESN1 T2 ON T2.REF_PHYS_PERS = T.REF_PHYS_PERS AND T2.MON = M.M - 1

--Суммы, превышающие предельную величину базы для начисления страховых взносов, установленную в соответствии со ст. 8 Федерального закона от 24 
INSERT INTO #RES2 SELECT '030303', SUM(SUMMA), 0, 0, '' FROM #SPR_ESN2 WHERE M <= @nMONTH3
INSERT INTO #RES2 SELECT '030304', SUM(SUMMA), 0, 0, '' FROM #SPR_ESN2 WHERE M = @nMONTH1
INSERT INTO #RES2 SELECT '030305', SUM(SUMMA), 0, 0, '' FROM #SPR_ESN2 WHERE M = @nMONTH2
INSERT INTO #RES2 SELECT '030306', SUM(SUMMA), 0, 0, '' FROM #SPR_ESN2 WHERE M = @nMONTH3

--из них: сумма выплат и иных вознаграждений физическим лицам, являющимся инвалидами I, II, III группы
SELECT MON = 1, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END INTO #SPR_ESN1KATEG3 FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 1 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 2, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 2 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 3, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 3 AND @nMONTH3 >= 3 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 4, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 4 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 5, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 5 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 6, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 6 AND @nMONTH3 >= 6 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 7, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 7 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 8, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 8 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 9, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 9 AND @nMONTH3 >= 9 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 10, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 10 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 11, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 11 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS
INSERT INTO #SPR_ESN1KATEG3 SELECT MON = 12, REF_PHYS_PERS, SUMMA = CASE WHEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) > @LIMIT THEN (SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M)) - @LIMIT ELSE 0 END FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE <= 12 AND @nMONTH3 >= 12 GROUP BY REF_PHYS_PERS

SELECT DISTINCT T.REF_PHYS_PERS, M.M, SUMMA = ISNULL(T1.SUMMA,0) - ISNULL(T2.SUMMA,0)
INTO #SPR_ESN2KATEG3
FROM 
	#SPR_ESN1KATEG3 T INNER JOIN dbo.months_ex(@BYearDate, @END_DATE) M ON 1=1
	LEFT JOIN #SPR_ESN1KATEG3 T1 ON T1.REF_PHYS_PERS = T.REF_PHYS_PERS AND T1.MON = M.M
	LEFT JOIN #SPR_ESN1KATEG3 T2 ON T2.REF_PHYS_PERS = T.REF_PHYS_PERS AND T2.MON = M.M - 1
WHERE
	(ISNULL(T1.SUMMA,0) - ISNULL(T2.SUMMA,0)) > 0


SET @TMP_VAL = ISNULL( (SELECT SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN WHERE KATEG = 3) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M <= @nMONTH3),0)
INSERT INTO #RES2 VALUES('030503', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN  WHERE KATEG = 3 AND MONTH_BASE = @nMONTH1) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH1),0)
INSERT INTO #RES2 VALUES('030504', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN  WHERE KATEG = 3 AND MONTH_BASE = @nMONTH2) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH2),0)
INSERT INTO #RES2 VALUES('030505', @TMP_VAL, 0, 0, '')

SET @TMP_VAL = ISNULL( (SELECT SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN  WHERE KATEG = 3 AND MONTH_BASE = @nMONTH3) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH3),0)
INSERT INTO #RES2 VALUES('030506', @TMP_VAL, 0, 0, '')

--select * from #RES2 where code_str in ('030503','030504', '030505','030506')
--ВЫРАВНИВАНИЕ ПОГРЕШНОСТИ ПО ОСНОВНОМУ ТАРИФУ
/*
--Способ заполнения страховых взносов
Выриант №1. Сумма всзносов по организации рассчитывается  по формулам расчёта для 4-ФСС от общих сумм дохода и необлагаемых сумм. 
Выриант №2. Сумма взносов по организации рассчитывается как сумма взносов, начисленных по физлицам. 
Выриант №3. Сумма взносов по организации рассчитывается как сумма взносов, начисленных по физлицам. 
Но при этом для того, чтобы выполнялись контрольные соотношения по форме, выполняется подгон необлагаемых сумм.
*/
DECLARE @SALARY_OPTIONS_OPT5_1 INT 
SET @SALARY_OPTIONS_OPT5_1 = dbo.SA_GET_OPTION_BY_CODE('SALARY_OPTIONS_OPT5_1')

--select @PERCENT1 , @PERCENT1_IN

--select * from 	#RES2
--	WHERE
--		CODE_STR IN ('030104', '030204', '030304', '030504')

IF ISNULL(@PERCENT1,0) > 0
BEGIN

	--Вычисление погрешности для накопительной части	
	SELECT 
		@C3N = CONVERT(NUMERIC(18,2), 
			(
				SUM( --Стр 4 (030403)  = 
					(CASE WHEN CODE_STR = '030103' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030203' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030303' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030503' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030403)  = 
					(CASE WHEN CODE_STR = '030503' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100				
				- (SELECT SUM(BASE_FSS) FROM #RES2 WHERE CODE_STR in ('0121','0123', '0124','0125'))
			) / @PERCENT1/100
		),
		@C3NS = CONVERT(NUMERIC(18,2),
			(
				SUM( --Стр 4 (030403)  = 
					(CASE WHEN CODE_STR = '030103' THEN BASE_FSS  ELSE 0 END) 
					-(CASE WHEN CODE_STR = '030203' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030303' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030503' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов
				) * @PERCENT1/100
				+
				SUM( --Стр 4 (030403)  = 
					(CASE WHEN CODE_STR = '030503' THEN BASE_FSS  ELSE 0 END) 
				) * @PERCENT1_IN/100				
			)
		),		
		@C4N = CONVERT(NUMERIC(18,2), 
			(
				SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030104' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030204' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030304' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030504' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030504' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100				
				- (SELECT SUM(BASE_FSS) FROM #RES2 WHERE CODE_STR = '0123')
			) / @PERCENT1/100	
		),
		@C4NS = CONVERT(NUMERIC(18,2), 
			(
				SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030104' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030204' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030304' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030504' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов			
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030403)  = 
					(CASE WHEN CODE_STR = '030504' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100			
			)
		),		
		@C5N = CONVERT(NUMERIC(18,2),
			(
				SUM( --Стр 4 (030405)  = 
					(CASE WHEN CODE_STR = '030105' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030205' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030305' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030505' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030505' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100
				- (SELECT SUM(BASE_FSS) FROM #RES2 WHERE CODE_STR = '0124')
			) / @PERCENT1/100			
		),
		@C5NS = CONVERT(NUMERIC(18,2),
			(
				SUM( --Стр 4 (030405)  = 
					(CASE WHEN CODE_STR = '030105' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030205' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030305' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030505' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов			
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030505' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100				
			)
		),		
		@C6N = CONVERT(NUMERIC(18,2),
			(
				SUM( --Стр 4 (030405)  = 
					(CASE WHEN CODE_STR = '030106' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030206' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030306' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030506' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030506' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100				
				- (SELECT SUM(BASE_FSS) FROM #RES2 WHERE CODE_STR = '0125')
			) / @PERCENT1/100							
		),
		@C6NS = CONVERT(NUMERIC(18,2),
			(
				SUM( --Стр 4 (030405)  = 
					(CASE WHEN CODE_STR = '030106' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030206' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030306' THEN BASE_FSS  ELSE 0 END)
					-(CASE WHEN CODE_STR = '030506' THEN BASE_FSS  ELSE 0 END) -- за минусом базы инвалидов			
				) * @PERCENT1/100
				+ SUM( --Стр 4 (030404)  = 
					(CASE WHEN CODE_STR = '030506' THEN BASE_FSS  ELSE 0 END) -- база инвалидов
				) * @PERCENT1_IN/100				
			)
		)		
	FROM #RES2
	WHERE
		CODE_STR IN ('030103', '030203', '030303', '030503','030104', '030204', '030304', '030504','030105', '030205', '030305', '030505','030106', '030206', '030306', '030506')

	IF @SALARY_OPTIONS_OPT5_1 = 1
	BEGIN
		--Начислено ЕСН. 1 мес
		UPDATE #RES2
		SET BASE_FSS = ISNULL(@C4NS,0)			 
		WHERE 
			CODE_STR = '0123'
		
		UPDATE #RES2
		SET BASE_FSS = ISNULL(@C5NS,0)		 
		WHERE 
			CODE_STR = '0124'
			
		UPDATE #RES2
		SET BASE_FSS = ISNULL(@C6NS,0)		 
		WHERE 
			CODE_STR = '0125'
	
	END

	IF @SALARY_OPTIONS_OPT5_1 = 3
	BEGIN
	
		UPDATE #RES2
		SET BASE_FSS = BASE_FSS + ISNULL(@C3N,0)			 
		WHERE 
			CODE_STR = '030203'
		
		UPDATE #RES2
		SET BASE_FSS = BASE_FSS + ISNULL(@C4N,0)			 
		WHERE 
			CODE_STR = '030204'
			
		UPDATE #RES2
		SET BASE_FSS = BASE_FSS + ISNULL(@C5N,0)			 
		WHERE 
			CODE_STR = '030205'
			
		UPDATE #RES2
		SET BASE_FSS = BASE_FSS + ISNULL(@C6N,0)			 
		WHERE 
			CODE_STR = '030206'
	
	END

end


-- Тоже выводим по физлицу в таблицу 3.1
CREATE TABLE #RAZD31 (LINK INT, COL5 NUMERIC(18,2), COL6 NUMERIC(18,2), COL7 NUMERIC(18,2), COL8 NUMERIC(18,2))

INSERT INTO #RAZD31 (LINK, COL5, COL6, COL7, COL8)
SELECT DISTINCT 
	P.REF_PHYS_PERS,
	S5 = ISNULL(S51.SUMMA,0) - ISNULL(S52.SUMMA,0),
	S6 = ISNULL(S61.SUMMA,0) - ISNULL(S62.SUMMA,0),
	S7 = ISNULL(S71.SUMMA,0) - ISNULL(S72.SUMMA,0),
	S8 = ISNULL(S81.SUMMA,0) - ISNULL(S82.SUMMA,0)
FROM 
	#SPR_ESN P

	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN WHERE KATEG = 3 GROUP BY REF_PHYS_PERS) S51 ON S51.REF_PHYS_PERS = P.REF_PHYS_PERS
	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M <= @nMONTH3 GROUP BY REF_PHYS_PERS) S52 ON S52.REF_PHYS_PERS = P.REF_PHYS_PERS

	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE = @nMONTH1 GROUP BY REF_PHYS_PERS) S61 ON S61.REF_PHYS_PERS = P.REF_PHYS_PERS
	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH1 GROUP BY REF_PHYS_PERS) S62 ON S62.REF_PHYS_PERS = P.REF_PHYS_PERS

	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE = @nMONTH2 GROUP BY REF_PHYS_PERS) S71 ON S71.REF_PHYS_PERS = P.REF_PHYS_PERS
	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH2 GROUP BY REF_PHYS_PERS) S72 ON S72.REF_PHYS_PERS = P.REF_PHYS_PERS

	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA_BASE) - SUM(DED_M) - SUM(INV_M) FROM #SPR_ESN WHERE KATEG = 3 AND MONTH_BASE = @nMONTH3 GROUP BY REF_PHYS_PERS) S81 ON S81.REF_PHYS_PERS = P.REF_PHYS_PERS
	LEFT JOIN (SELECT REF_PHYS_PERS, SUMMA = SUM(SUMMA) FROM #SPR_ESN2KATEG3 WHERE M = @nMONTH3 GROUP BY REF_PHYS_PERS) S82 ON S82.REF_PHYS_PERS = P.REF_PHYS_PERS
	
WHERE KATEG = 3

DECLARE @Table_Razd31 VARCHAR(100)
EXEC dbo.X_GET_TABLE_NAME @Table_Razd31 OUTPUT
EXEC ('select * INTO ' + @Table_Razd31 + ' from #RAZD31')
EXEC dbo.BufferPush -116, @Table_Razd31



---P2.ТАБЛИЦА 7
--ОСТАТКИ ПО СЧЁТУ 303.06 НА НАЧАЛО ГОДА
CREATE TABLE #REST_30306_BY ([DATE] DATETIME, REST NUMERIC(18,2))

DECLARE @Cur2 CURSOR, @LINK_ACC2 INT
SET @Cur2 = CURSOR FORWARD_ONLY

FOR SELECT LINK FROM dbo.S_ACCOUNTS WHERE CODE LIKE '303.06%'

OPEN @Cur2
FETCH NEXT FROM @Cur2 INTO @LINK_ACC2
WHILE (@@fetch_status <> -1)
BEGIN

	IF (@@fetch_status <> -2)
	BEGIN

		INSERT INTO #REST_30306_BY ([DATE], REST)
		SELECT @BYearDate, REST = coalesce(sum(K_SUMMA)-sum(D_SUMMA),0) 
		FROM dbo.ARestGroupedTableByDate (@BYearDate, @LINK_ACC2, DEFAULT)
		WHERE DEP_LINK = @DEP_LINK
	END

	FETCH NEXT FROM @Cur2 INTO @LINK_ACC2
END

CLOSE @Cur2
DEALLOCATE @Cur2

--ОСТАТКИ ПО СЧЁТУ 303.06 НА КОНЕЦ ОТЧЕТНОГО КВАРТАЛА
--DECLARE @QV_DATE DATETIME
--SET @QV_DATE = @END_DATE+1

SET @Cur2 = CURSOR FORWARD_ONLY

FOR SELECT LINK FROM dbo.S_ACCOUNTS WHERE CODE LIKE '303.06%'

OPEN @Cur2
FETCH NEXT FROM @Cur2 INTO @LINK_ACC2
WHILE (@@fetch_status <> -1)
BEGIN

	IF (@@fetch_status <> -2)
	BEGIN

		INSERT INTO #REST_30306_BY ([DATE], REST)
		SELECT @END_DATE, REST = coalesce(sum(K_SUMMA)-sum(D_SUMMA),0) 
		FROM dbo.ARestGroupedTableByDate (@QV_DATE, @LINK_ACC2, DEFAULT)
		WHERE DEP_LINK = @DEP_LINK
	END

	FETCH NEXT FROM @Cur2 INTO @LINK_ACC2
END

CLOSE @Cur2
DEALLOCATE @Cur2

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0701', SUM(REST), 0, 0 FROM #REST_30306_BY WHERE [DATE] = @BYearDate HAVING SUM(REST) > 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0710', -SUM(REST), 0, 0 FROM #REST_30306_BY WHERE [DATE] = @BYearDate HAVING SUM(REST) < 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0709', -SUM(REST), 0, 0 FROM #REST_30306_BY WHERE [DATE] = @END_DATE HAVING SUM(REST) < 0

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '0715', SUM(REST), 0, 0 FROM #REST_30306_BY WHERE [DATE] = @END_DATE HAVING SUM(REST) > 0







--Используется в хранимке SA_4FSS_28022011_PREPARE_INV

--Р3.ТАБЛИЦА 9

Declare @StBase5 table (link int)
Insert into @StBase5 (link)
select distinct link_pays from tax_ref where link_tax = (select top 1 link from pays where object = 3 and way_calc = 5)

--Фактическая база для договорников
SELECT GT.PERS_LINK, MONTH(G.[DATE]) AS MONTH_BASE, SUMMA_BASE = sum(CASE WHEN GT.WAY_CALC  = 5 THEN GT.SUMMA_BASE ELSE 0 END)
INTO #DGH_FAKT_BASE2
FROM 
	dbo.DOCUMENTS_DGH G 
	--INNER JOIN dbo.DOCUMENTS_DGH_T1 T1 ON T1.LINK = G.LINK
	--INNER JOIN dbo.REESTR_DGH R ON R.LINK = T1.LINK_DOG  --AND FLAG_TRAVMA = 1	
	INNER JOIN dbo.DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK --AND T1.PERS_LINK = GT.PERS_LINK 
WHERE 
	G.LINK_DEP = @DEP_LINK
	AND FLAG_JC = 1
	--AND GT.WAY_CALC  = 5
	AND YEAR(G.[DATE]) = @nYEAR
	AND MONTH(G.[DATE]) <= @nMONTH3 
GROUP BY   GT.PERS_LINK,  MONTH(G.[DATE]) /*, GT.WAY_CALC*/


SELECT MON, SUMMA_ALL = SUM(SUMMA_ALL), SUMMA_NO = SUM(SUMMA_NO), SUMMA_ALL_I = SUM(SUMMA_ALL_I), SUMMA_NO_I = SUM(SUMMA_NO_I)
INTO #SALARY_SUM
FROM 
(
select 
	MON = Month(CJ.PERIOD_BEGIN),
	SUMMA_ALL = SUM(SUMMA),
	SUMMA_NO = SUM(CASE WHEN B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0 THEN SUMMA ELSE 0 END), --на которые не начисляются страховые взносы
	SUMMA_ALL_I = SUM(CASE WHEN I.LINK IS NOT NULL AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN COALESCE(I.DATE_BEGIN,CJ.PERIOD_BEGIN) AND  COALESCE(I.DATE_END,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) THEN SUMMA ELSE 0 END),
	SUMMA_NO_I = SUM(CASE WHEN (B.LINK IS NULL OR CJ.LINK_EKR = @LINK_EKR213 AND @ESN_213 = 0) AND I.LINK IS NOT NULL AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN COALESCE(I.DATE_BEGIN,CJ.PERIOD_BEGIN) AND  COALESCE(I.DATE_END,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) THEN SUMMA ELSE 0 END)
from 
	dbo.CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
	INNER JOIN DBO.EMPL E ON E.LINK = CJ.LINK_EMPL
	LEFT JOIN @StBase5 B ON B.LINK = cj.LINK_PAYS
	LEFT JOIN DBO.PERS_INVALID I ON I.PERS_LINK = E.PERS_LINK 
			AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN I.DATE_BEGIN AND ISNULL(I.DATE_END,'29990101')
			--AND COALESCE(I.DATE_BEGIN,@BYearDate) <= @EndYear AND COALESCE(I.DATE_END,@EndYear) >= @BYearDate
where 	
	Year(period_begin) = @nYEAR and Month(period_begin) <= @nMONTH3 
	and CJ.LINK_DEP = @DEP_LINK
	and P.[OBJECT] = 1
GROUP BY
	Month(CJ.PERIOD_BEGIN)
UNION ALL	
select 
	MON = Month(CJ.PERIOD_BEGIN),
	SUMMA_ALL = SUM(CJ.SUMMA),
	SUMMA_NO = SUM( CJ.SUMMA - ISNULL(B.SUMMA_BASE,0)), --на которые не начисляются страховые взносы
	SUMMA_ALL_I = SUM(CASE WHEN I.LINK IS NOT NULL AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN COALESCE(I.DATE_BEGIN,CJ.PERIOD_BEGIN) AND  COALESCE(I.DATE_END,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) THEN SUMMA ELSE 0 END),
	SUMMA_NO_I = SUM(CASE WHEN I.LINK IS NOT NULL AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN COALESCE(I.DATE_BEGIN,CJ.PERIOD_BEGIN) AND  COALESCE(I.DATE_END,dbo.DateEndOfMonth(CJ.PERIOD_BEGIN)) THEN SUMMA - ISNULL(B.SUMMA_BASE,0) ELSE 0 END)
from 
	#DGH_CJ CJ
	INNER JOIN #DGH_FAKT_BASE2 B ON B.PERS_LINK = CJ.PERS_LINK AND B.MONTH_BASE = Month(CJ.PERIOD_BEGIN)
	LEFT JOIN DBO.KU_PERS_INVALID I ON I.PERS_LINK = CJ.PERS_LINK 
		AND dbo.DateEndOfMonth(CJ.PERIOD_BEGIN) BETWEEN I.DATE_BEGIN AND ISNULL(I.DATE_END,'29990101')
		--AND COALESCE(I.DATE_BEGIN,@BYearDate) <= @EndYear AND COALESCE(I.DATE_END,@EndYear) >= @BYearDate
where 	
	Month(period_begin) <= @nMONTH3 
GROUP BY
	Month(CJ.PERIOD_BEGIN)
) AS T
GROUP BY 
	MON
------------------------

--Льготы по травматизму
DECLARE @LINK_S_OBJ INT
SET @LINK_S_OBJ = (SELECT TOP 1 LINK FROM dbo.S_OBJECTS WHERE CODE = 'DOCUMENTS_CLOSE_MONTH')

CREATE TABLE #TRAVM_LGOTY (I TINYINT, M TINYINT, SUMMA NUMERIC(18,2))
--скидки по травматизму
INSERT INTO #TRAVM_LGOTY (I, M, SUMMA)
SELECT I = (CASE WHEN ISNULL(I.PERS_LINK,0) = 0 THEN 0 ELSE 1 END), MONTH(D.[DATE]), SUM(SUMMA)
FROM
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DOT_SKIDKI S ON S.LINK_UP = D.LINK
	LEFT JOIN dbo.pers_invalid I ON S.LINK_PERS = I.PERS_LINK 
		AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH(D.[DATE]),YEAR(D.[DATE]))) BETWEEN I.DATE_BEGIN AND COALESCE(I.DATE_END,'29990101')	
WHERE
	D.[OBJECT] = @LINK_S_OBJ AND D.FLAG_JC = 1 AND D.LINK_DEP = @DEP_LINK
	AND YEAR(D.[DATE]) = @nYEAR AND MONTH(D.[DATE]) <= @nMONTH3
GROUP BY
	ISNULL(I.PERS_LINK,0), MONTH(D.[DATE])
	
----Вычеты по травматизму	
INSERT INTO #TRAVM_LGOTY (I, M, SUMMA)
SELECT I = (CASE WHEN ISNULL(I.PERS_LINK,0) = 0 THEN 0 ELSE 1 END), MONTH(D.[DATE]), SUM(SUMMA)
FROM
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DOT_VYCHET S ON S.LINK_UP = D.LINK
	LEFT JOIN dbo.pers_invalid I ON S.LINK_PERS = I.PERS_LINK 
		AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,MONTH(D.[DATE]),YEAR(D.[DATE]))) BETWEEN I.DATE_BEGIN AND COALESCE(I.DATE_END,'29990101')	
WHERE
	D.[OBJECT] = @LINK_S_OBJ AND D.FLAG_JC = 1 AND D.LINK_DEP = @DEP_LINK
	AND YEAR(D.[DATE]) = @nYEAR AND MONTH(D.[DATE]) <= @nMONTH3
GROUP BY
	ISNULL(I.PERS_LINK,0), MONTH(D.[DATE])	

--Данные для таблицы 6
CREATE TABLE #TABLE6 (MON TINYINT, SUMMA3 NUMERIC(18,2), SUMMA4 NUMERIC(18,2), SUMMA5 NUMERIC(18,2) )
INSERT INTO #TABLE6 (MON, SUMMA3, SUMMA4, SUMMA5)
SELECT 
	M.NUM, 
	SUMMA3 = /*ROUND(*/ ISNULL( (SELECT SUM(SUMMA_ALL)-SUM(SUMMA_NO) FROM #SALARY_SUM WHERE MON = M.NUM) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #TRAVM_LGOTY WHERE M = M.NUM),0) /*,0)*/,
	SUMMA4 = /*ROUND(*/ ISNULL( (SELECT SUM(SUMMA_ALL_I)-SUM(SUMMA_NO_I) FROM #SALARY_SUM WHERE MON = M.NUM) ,0) - ISNULL((SELECT SUM(SUMMA) FROM #TRAVM_LGOTY WHERE I = 1 AND M = M.NUM),0) /*,0)*/,
	SUMMA5 = /*ROUND(*/ ISNULL( (SELECT SUM(SUMMA_NO) FROM #SALARY_SUM WHERE MON = M.NUM) ,0) + ISNULL((SELECT SUM(SUMMA) FROM #TRAVM_LGOTY WHERE M = M.NUM),0) /*,0)*/
FROM
	dbo.MONTHS M
	
	
INSERT INTO #RES2 SELECT '060103', ISNULL( (SELECT SUM(SUMMA3) FROM #TABLE6) ,0) , 0, 0, ''
INSERT INTO #RES2 SELECT '060104', ISNULL( (SELECT SUM(SUMMA4) FROM #TABLE6) ,0), 0, 0, ''
INSERT INTO #RES2 SELECT '060105', ISNULL( (SELECT SUM(SUMMA5) FROM #TABLE6) ,0), 0, 0, ''
---
INSERT INTO #RES2 SELECT '060303', ISNULL( (SELECT SUM(SUMMA3) FROM #TABLE6 WHERE MON = @nMONTH1) ,0) , 0, 0, ''
INSERT INTO #RES2 SELECT '060304', ISNULL( (SELECT SUM(SUMMA4) FROM #TABLE6 WHERE MON = @nMONTH1) ,0), 0, 0, ''
INSERT INTO #RES2 SELECT '060305', ISNULL( (SELECT SUM(SUMMA5) FROM #TABLE6 WHERE MON = @nMONTH1) ,0), 0, 0, ''
---
INSERT INTO #RES2 SELECT '060403', ISNULL( (SELECT SUM(SUMMA3) FROM #TABLE6 WHERE MON = @nMONTH2) ,0) , 0, 0, ''
INSERT INTO #RES2 SELECT '060404', ISNULL( (SELECT SUM(SUMMA4) FROM #TABLE6 WHERE MON = @nMONTH2) ,0), 0, 0, ''
INSERT INTO #RES2 SELECT '060405', ISNULL( (SELECT SUM(SUMMA5) FROM #TABLE6 WHERE MON = @nMONTH2) ,0), 0, 0, ''
---
INSERT INTO #RES2 SELECT '060503', ISNULL( (SELECT SUM(SUMMA3) FROM #TABLE6 WHERE MON = @nMONTH3) ,0) , 0, 0, ''
INSERT INTO #RES2 SELECT '060504', ISNULL( (SELECT SUM(SUMMA4) FROM #TABLE6 WHERE MON = @nMONTH3) ,0), 0, 0, ''
INSERT INTO #RES2 SELECT '060505', ISNULL( (SELECT SUM(SUMMA5) FROM #TABLE6 WHERE MON = @nMONTH3) ,0), 0, 0, ''

--Р3.ТАБЛИЦА 10
select 
	MON = Month(CJ.PERIOD_BEGIN),
	SUMMA = SUM(SUMMA)
INTO 
	#SALARY_SUM1
from 
	dbo.CALCULATE_JURNAL CJ inner join dbo.pays p on p.link = cj.LINK_PAYS
where 	
	Year(period_begin) = @nYEAR and Month(period_begin) <= @nMONTH3 
	and CJ.LINK_DEP = @DEP_LINK
	and CJ.LINK_PAYS = (select top 1 link from pays where object = 3 and way_calc = 5)
GROUP BY
	Month(CJ.PERIOD_BEGIN)

INSERT INTO #RES2 SELECT '1021', SUM(SUMMA), 0, 0, '' FROM #SALARY_SUM1 WHERE MON < @nMONTH1
INSERT INTO #RES2 SELECT '1023', SUM(SUMMA), 0, 0, '' FROM #SALARY_SUM1 WHERE MON = @nMONTH1
INSERT INTO #RES2 SELECT '1024', SUM(SUMMA), 0, 0, '' FROM #SALARY_SUM1 WHERE MON = @nMONTH2
INSERT INTO #RES2 SELECT '1025', SUM(SUMMA), 0, 0, '' FROM #SALARY_SUM1 WHERE MON = @nMONTH3

--- Номера платежек 
CREATE TABLE #PLAT1(VID TINYINT, Y INT, MON TINYINT, SUMMA NUMERIC(18,2), Y_p INT, MON_p TINYINT, NUMBER VARCHAR(10))

	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'

	INSERT INTO BUFFER (link, id)
	select link, 'DT' from s_accounts where cSinth = '303' and cAnalit = '06' --С 290экр НЕ ДОЛЖЕН БРАТЬСЯ

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '304' and cAnalit = '05'

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '201' and (cAnalit = '11' or cAnalit = '21' or cAnalit = '27')

	INSERT INTO #PLAT1 (VID, Y, MON, SUMMA,Y_P,MON_P,NUMBER)
	SELECT  1,
		Y = CONVERT(INT,YEAR(p.DATE_PROV)), 
		MON = CONVERT(INT,MONTH(p.DATE_PROV)),
		P.SUMMA,  
		Y_P = CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,3,'.')), 
		MON_P = CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')),
		P.NUMBER	
	from 
		dbo.AProvByBufferConditionsShortDate(@START_DATE, @END_DATE, 'DT', 'KT') P	
		inner join dbo.DOCUMENTS_PAY_ADD PA on P.link = PA.link
		inner join dbo.g_prov G on G.link = PA.link
		LEFT JOIN dbo.KOSGU DG ON DG.LINK = P.DT_EKR
	WHERE
		P.DEP_LINK = @DEP_LINK
		AND
		G.DEP = @DEP_LINK
		--AND
		--CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')) <= @M
		--AND
		--CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,3,'.')) = @Y
		AND
		DG.CODE <> '290'

	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'
	
	
	
INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '10123', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT1 WHERE Y >= @nYEAR and MON = @nMONTH1), 
		'', 
		0   

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '10124', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT1 WHERE Y >= @nYEAR and MON = @nMONTH2), 
		'', 
		0   

INSERT INTO #RES2 (CODE_STR, BASE_FSS, CNT_FSS, CNT_FEM)
SELECT '10125', 
		(SELECT ISNULL(SUM(SUMMA),0) FROM #PLAT1 WHERE Y >= @nYEAR and MON = @nMONTH3), 
		'', 
		0   

--- Сведения по номерам платежек
SELECT  VID,
		Y , 
		MON ,
		NUMBER	
INTO #PLAT_PP1
FROM #PLAT1 
GROUP  BY VID , Y , MON, NUMBER

DROP TABLE #PLAT1

BEGIN 
	declare @Cur_1 cursor , @VID1 tinyint , @Y1 INT, @MON1 TINYINT, @NUMBER1 VARCHAR(10)

	SET @Cur_1 = CURSOR FORWARD_ONLY
	FOR 
		select VID, Y, MON, NUMBER from #PLAT_PP1 order by VID, Y, MON, NUMBER
	OPEN @Cur_1
	FETCH NEXT FROM @Cur_1 INTO @VID1, @Y1, @MON1, @NUMBER1
	
	WHILE (@@fetch_status <> -1)
	BEGIN
		
		IF (@@fetch_status <> -2)
		BEGIN	
			if  @Y1 = @nYEAR and @MON1 = @nMONTH1
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER1)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER1)) end )
				where code_str = '10123' 

			if  @Y1 = @nYEAR and @MON1 = @nMONTH2
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER1)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER1)) end )
				where code_str = '10124'

			if  @Y1 = @nYEAR and @MON1 = @nMONTH3
				UPDATE #RES2
					set NUM_PP = (case when NUM_PP is null or NUM_PP= '' then ltrim(RTRIM(@NUMBER1)) else ltrim(RTRIM(NUM_PP))+','+ ltrim(RTRIM(@NUMBER1)) end )
				where code_str = '10125'				

		end
		FETCH NEXT FROM @Cur_1 INTO @VID1, @Y1, @MON1, @NUMBER1
	end

CLOSE @Cur_1
DEALLOCATE @Cur_1

END 

drop table #PLAT_PP1

-- exec dbo.RI_REPORT_FORMULA_ALL_CALCULATE '2014-01-01 00:00:00','2014-03-31 00:00:00',2,1,2745
/*declare @Res float
set @Res = 0
 exec dbo.RSA_4FSS_09022012_PREPARE @Res output, '', '20140101', '20140331', 2, 1, 2745
*/






INSERT INTO #RES2
SELECT '1101', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 10),0),
	ISNULL((SELECT SUM(CNT_DAYS) FROM #ATR_4FSS WHERE F4FSS = 10),0),	
	0, ''

INSERT INTO #RES2
SELECT '1102', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 10 AND [STATUS] = 3),0),
	ISNULL((SELECT SUM(CNT_DAYS) FROM #ATR_4FSS WHERE F4FSS = 10 AND [STATUS] = 3),0),	
	0, ''	
	
INSERT INTO #RES2
SELECT '1104', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 11),0),
	ISNULL((SELECT SUM(CNT_DAYS) FROM #ATR_4FSS WHERE F4FSS = 11),0),	
	0, ''

INSERT INTO #RES2
SELECT '1105', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 11 AND [STATUS] = 3),0),
	ISNULL((SELECT SUM(CNT_DAYS) FROM #ATR_4FSS WHERE F4FSS = 11 AND [STATUS] = 3),0),	
	0, ''		

INSERT INTO #RES2
SELECT '1107', 
	ISNULL((SELECT SUM(SUMMA) FROM #ATR_4FSS WHERE F4FSS = 12),0),
	ISNULL((SELECT SUM(CNT_DAYS) FROM #ATR_4FSS WHERE F4FSS = 12),0),	
	0, ''

DECLARE  @SPO4 INT
SELECT @SPO4 = (SELECT distinct LINK FROM dbo.SA_SZV4_SPR WHERE code = 'О4' AND spr_code = 'SPO_USL_TRUDA' )




----- Таблица результатов по спецоценке
--Р2.ТАБЛИЦА 10
select [KOL_ALL] = SUM(S.NUM_STAKE),
		[KOL_SPO_ALL] = SUM(CASE WHEN S.COD_SPO_USL_TRUD IS NOT NULL THEN S.NUM_STAKE ELSE 0 END ),
		[KOL_SPO_3] =  SUM(CASE WHEN (ISNULL(S.COD_SPO_USL_TRUD, 0) <> 0 
							AND S.COD_SPO_USL_TRUD = @SPO4 
							)  
					   THEN  S.NUM_STAKE 
					   ELSE 0 END) ,	   
		[KOL_SPO_4] = SUM(CASE WHEN (ISNULL(S.COD_SPO_USL_TRUD, 0) <> 0 
							AND S.COD_SPO_USL_TRUD <> @SPO4 
							)  
					   THEN  S.NUM_STAKE 
					   ELSE 0 END) 	  
	
INTO 
	#STAF_ALL
from 
	dbo.staff s inner join dbo.staff_head sh on s.link_up = sh.LINK
where 	
	sh.DEP_LINK = @DEP_LINK
	and @vardEnd between s.date_begin and s.date_end 




INSERT INTO #RES2 SELECT '100103', KOL_ALL, 0, 0, '' FROM #STAF_ALL 
INSERT INTO #RES2 SELECT '100104', KOL_SPO_ALL, 0, 0, '' FROM #STAF_ALL 
INSERT INTO #RES2 SELECT '100105', KOL_SPO_3, 0, 0, '' FROM #STAF_ALL 
INSERT INTO #RES2 SELECT '100106', KOL_SPO_4, 0, 0, '' FROM #STAF_ALL 


/* Завершаем - списываем значения во временную таблицу */
DECLARE @Table_Razd1 VARCHAR(100)
EXEC dbo.X_GET_TABLE_NAME @Table_Razd1 OUTPUT
EXEC ('select * INTO ' + @Table_Razd1 + ' from #RES2 order by code_str')
EXEC dbo.BufferPush -115, @Table_Razd1


DROP TABLE #RES2
DROP TABLE #SPR_ESN
DROP TABLE #ATR_4FSS
DROP TABLE #DGH_FAKT_BASE
DROP TABLE #SALARY_SUM2
DROP TABLE #SPR_ESN1
DROP TABLE #SPR_ESN2
DROP TABLE #SPR_ESN1KATEG3
DROP TABLE #SPR_ESN2KATEG3
DROP TABLE #RAZD31
DROP TABLE #DGH_FAKT_BASE2
DROP TABLE #SALARY_SUM
DROP TABLE #SALARY_SUM1
DROP TABLE #TRAVM_LGOTY
DROP TABLE #TABLE6





GO


GRANT EXECUTE ON dbo.[RSA_4FSS_09022012_PREPARE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_REP_VEDOM_PREPARE_DATA]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_REP_VEDOM_PREPARE_DATA]

GO

CREATE PROCEDURE dbo.SD_REP_VEDOM_PREPARE_DATA 
	@nLink INT = NULL, @BUFFER_ID VARCHAR(20) = NULL
AS

BEGIN

DECLARE @str VARCHAR(7000), 
		@nMode INT,
		@SortMode INT,
		@GroupMode INT,
		@WrapMode INT,
		@FIOShort tinyint

DECLARE @SPISOK_VEDOM TABLE (LINK INT)
INSERT INTO @SPISOK_VEDOM (LINK)
SELECT LINK FROM DBO.BUFFER WITH (NOLOCK) WHERE ID = @BUFFER_ID

IF @nLink IS NOT NULL AND NOT EXISTS (SELECT * FROM @SPISOK_VEDOM WHERE LINK = @nLink)
	INSERT INTO @SPISOK_VEDOM (LINK) VALUES (@nLink)

IF @BUFFER_ID IS NOT NULL
	SET @nLink = NULL
IF COALESCE((SELECT COUNT(*) FROM @SPISOK_VEDOM),0) =1
	SET @nLink = (SELECT LINK FROM @SPISOK_VEDOM)
		
/* Читаем настройки сортировки  1 - по фио, 2 - по табельному номеру, 3 - по коду должности */
SELECT top 1 @SortMode = ISNULL(CONVERT(INT,VALUE),1) 
FROM S_OPTIONS 
WHERE OBJECT = (SELECT top 1 LINK FROM S_OBJECTS WHERE CODE = 'VEDOM_OPTIONS_VEDOM_SORT') AND SID IS NULL

/* Читаем настройки переноса */
SELECT top 1 @WrapMode = ISNULL(CONVERT(INT,VALUE),0)
FROM S_OPTIONS 
WHERE OBJECT = (SELECT top 1 LINK FROM S_OBJECTS WHERE CODE = 'VEDOM_OPTIONS_VEDOM_PERENOS') AND SID IS NULL

/* Читаем настройки группировки */
SELECT top 1 @GroupMode = (CASE WHEN ISNULL(CONVERT(INT,VALUE),0) = 0 THEN @WrapMode else ISNULL(CONVERT(INT,VALUE),0) END)
FROM S_OPTIONS 
WHERE OBJECT = (SELECT top 1 LINK FROM S_OBJECTS WHERE CODE = 'VEDOM_OPTIONS_VEDOM_GROUP') AND SID IS NULL

SET @str = DBO.OBJECT_VAR_GET_OBJECT_VALUE('SALARY_QUERY_PAYROLL_N3','QUERY_NASTR_VALUE',1)
/* Выбирается вариант сортировки */
SET @nMode = CASE WHEN @str = 'ФИО' THEN 2 ELSE 1 END 

CREATE TABLE #SDOC_VEDOM_TABLE1 (LINK_UP INT, LINK_EMPL INT, LINK_SFIN INT, LINK_EKR INT, ORDERS INT, DISBURS NUMERIC(18,2), 
		CODE_EKR VARCHAR(3), CODE_KBK VARCHAR(30), CODE_DT VARCHAR(13), CODE_KT VARCHAR(13), NOTE VARCHAR(254))

INSERT INTO 
	#SDOC_VEDOM_TABLE1 (LINK_UP, LINK_EMPL, LINK_EKR, CODE_EKR, ORDERS, DISBURS , NOTE )
SELECT 
	LINK_UP, LINK_EMPL, LINK_EKR , CODE_EKR = k.CODE, ORDERS = MAX(ORDERS), DISBURS = SUM(DISBURS) , ltrim(rtrim(NOTE))
FROM 
	dbo.SDOC_VEDOM_TABLE1 D
	left join dbo.KOSGU K on k.link = d.LINK_EKR
WHERE 
	(D.LINK_UP = @nLink AND @nLink IS NOT NULL
	OR
	D.LINK_UP IN (SELECT LINK FROM @SPISOK_VEDOM))
	AND DISBURS > 0
GROUP BY 
	LINK_UP, LINK_EMPL,LINK_EKR,k.CODE, NOTE


--Для каждой ведомости определяются КБК и корреспондирующие счета
--Но только если указан конкретный источник и ЭКР в ведомости
DECLARE @CUR_ACC CURSOR, @LINK_VEDOM INT, @KBK_CODE VARCHAR(30), @EKR_CODE VARCHAR(3), @DT_CODE VARCHAR(40), @KT_CODE VARCHAR(40)

SET @CUR_ACC = CURSOR FORWARD_ONLY
FOR SELECT LINK FROM @SPISOK_VEDOM
OPEN @CUR_ACC
FETCH NEXT FROM @CUR_ACC INTO @LINK_VEDOM
WHILE (@@FETCH_STATUS <> -1)
BEGIN
	IF (@@FETCH_STATUS <> -2)
	BEGIN

		EXEC dbo.[SA_VEDOM_ACCOUNTS] @LINK_VEDOM = @LINK_VEDOM, @KBK_CODE = @KBK_CODE OUTPUT, @EKR_CODE = @EKR_CODE OUTPUT, @DT_CODE = @DT_CODE OUTPUT, @KT_CODE = @KT_CODE OUTPUT
		
		UPDATE #SDOC_VEDOM_TABLE1
		SET CODE_KBK = @KBK_CODE ,  CODE_EKR = ISNULL(@EKR_CODE,CODE_EKR), CODE_DT = @DT_CODE, CODE_KT = @KT_CODE
		WHERE LINK_UP = @LINK_VEDOM
	END
	FETCH NEXT FROM @CUR_ACC INTO @LINK_VEDOM
END

CLOSE @CUR_ACC
DEALLOCATE @CUR_ACC


------------------------------------------------------------------
DECLARE @res TABLE (
		LINK_DOC INT,DOC_DATE DATETIME, DOC_DATE1 varchar(10), EXCH_DATE datetime, DOC_NUM VARCHAR(60), 
		KASSIR VARCHAR(120), KASS_POST VARCHAR(254), KASS_PHONE VARCHAR(40),
		DIV_NAME VARCHAR(254), DIV_CODE VARCHAR(10),
		TI_NAME VARCHAR(254), TI_CODE VARCHAR(10),
		VR_NAME VARCHAR(254), VR_CODE VARCHAR(10),
		NAME_PAYR VARCHAR(254),
		NAME_PAY VARCHAR(120), CODE_PAY VARCHAR(10),
		DATE_BEGIN DATETIME, DATE_END DATETIME, 
		[MONTH] VARCHAR(20) , MON int, [YEAR] VARCHAR(4), 
		NPP INT IDENTITY,
		LINK_EMPL INT, 
		TN VARCHAR(15), 
		FIO VARCHAR(254),
		S_FIO VARCHAR(100),
		FM VARCHAR(50), 
		IM VARCHAR(50), 
		OT VARCHAR(50), 
		INN VARCHAR(12),
		SUMMA NUMERIC(15,2),
		SUMMA1 VARCHAR(18), 
		ACCT VARCHAR(254), 
		ACCT_V VARCHAR(254), 
		BANK_LINK INT, BANK_NAME VARCHAR(254), BIK VARCHAR(9), DEP_ACCT VARCHAR(30), DEP_ACC_M VARCHAR(20),
		CARD_LINK INT, CARD_NAME VARCHAR(254), CARD_CODE VARCHAR(3), CARD_POSTF VARCHAR(2),
		NOSB VARCHAR(4), NFSB VARCHAR(5), NDOG_SB VARCHAR(20), DATE_DOGSB datetime,
		POST_CODE VARCHAR(10),
		POST VARCHAR(254),
		OKLAD NUMERIC(15,0),
		STAKE NUMERIC(5,2),
		DAYS_W numeric (3,0),
		HOURS_W numeric (3,0),
		DAYS_H numeric (3,0),
		HOURS_H numeric (3,0),
		SERNUM VARCHAR(20),
		SUM_ALL NUMERIC(20,2), COUNT_OP INT,
		DEP_NAME VARCHAR(254), FULLNAME VARCHAR(2000),
		PASSPORT VARCHAR(254),
		ADDRESS VARCHAR(254),
		PINDEX VARCHAR(10),
		PHONE VARCHAR(20),
		FD_CODE varchar(2),
		FD_DATE varchar(8),
		FD_ROVD varchar(254),
		SUBDIV_CODE varchar(20),
		SUBDIV varchar(254),
		BIRTHDAY varchar(8),
		ADDR varchar(254),
		shild int,
		REGION  VARCHAR(120), ABR_REGION  VARCHAR(12),
		RAION   VARCHAR(120), ABR_RAION  VARCHAR(12),
		GOROD	VARCHAR(50), ABR_GOROD  VARCHAR(12),
		NAS_PUNKT   VARCHAR(120), ABR_NAS_PUNKT  VARCHAR(12),
		ULICA	VARCHAR(120), ABR_ULICA  VARCHAR(12),
		DOM	VARCHAR(5), KORPUS VARCHAR(5), KVARTIRA VARCHAR(5),
		DEP_INN VARCHAR(12), DEP_KPP VARCHAR(9), DEP_OKPO VARCHAR(20), DEP_OGRN VARCHAR(13),
		EXRT INT, EXRT_D INT, LINK_DEP INT, FRMT_LINK INT,
		DD VARCHAR(2), MM VARCHAR(2), YYYY VARCHAR(4),
		CODE_EKR VARCHAR(3), LINK_EKR INT,
		EKR_ANALIT VARCHAR(3),
		CODE_KBK VARCHAR(30),
		CODE_DT VARCHAR(13),
		CODE_KT VARCHAR(13),
		NOTE VARCHAR(254),
/*+*/	RND varchar(16), [DATE] varchar(8), [TIME] varchar(8)
	)

	DECLARE 
		@ORGNAME VARCHAR(254), @DEP_LINK INT, @ORGFULLNAME VARCHAR(2000),
		@DOC_DATE DATETIME, @DOC_DATE1 varchar(10) ,@EXCH_DATE datetime, @DOC_NUM VARCHAR(60), 
		@DOC_DT_BEG DATETIME, @DOC_DT_END DATETIME,
		@KASSIR VARCHAR(254), @KASS_POST VARCHAR(254),@KASS_PHONE VARCHAR(40),
		@DIV_NAME VARCHAR(254), @DIV_CODE VARCHAR(10),
		@TI_NAME VARCHAR(254), @TI_CODE VARCHAR(10),
		@VR_NAME VARCHAR(254), @VR_CODE VARCHAR(10),
		@NAME_PAY VARCHAR(254), @CODE_PAY VARCHAR(10), @NAME_PAYR VARCHAR(254),
		@DATE_BEGIN DATETIME, @DATE_END DATETIME,
		@Month VARCHAR(20), @MON int, @Year VARCHAR(4),
		@DEP_ACCT VARCHAR(30),@DEP_ACC_M VARCHAR(20),
		@CARD_LINK int, @DEP_INN VARCHAR(12), @DEP_KPP VARCHAR(9), @DEP_OKPO VARCHAR(20), @DEP_OGRN VARCHAR(13),
		@TYPE_DAYS  int 

	SET @TYPE_DAYS = (select top 1 link  from TYP_DAYS  where name = 'Выходные и праздничные'	)
	SELECT  top 1 
			@ORGNAME 	= LEFT(DEP.[NAME],254),
			@ORGFULLNAME  = LEFT(DEP.[FULL_NAME],2000),
			@DEP_LINK 	= DEP.LINK,
			@DEP_INN = LEFT(INN,12), @DEP_KPP = LEFT(KPP,9), @DEP_OKPO = LEFT(OKPO,20), @DEP_OGRN = LEFT(OGRN,13) , @DEP_ACC_M = DEP.MAIN_LINK,
			@EXCH_DATE = getdate()
	FROM dbo.DICTIONARY_DEPARTMENT DEP, USER_DEP UI WHERE DEP.LINK = UI.DEP_LINK

	---		
	SELECT top 1 
		@DOC_DATE = S.[DATE],
		@DOC_DATE1 = convert(varchar(10), S.[DATE], 103) ,
		@DOC_DT_BEG = S.DATE_CALC, 
		@DOC_DT_END = S.[DATE],
		@DOC_NUM = LEFT(S.NUMBER,60),
		@KASSIR = LEFT(ISNULL(dbo.sd_GetEmplName(SD.REF_KASSIR), 0),254),
		@KASS_POST = LEFT(dbo.ku_GetEmplPostName(SD.REF_KASSIR,DEFAULT),254),
		@KASS_PHONE = LEFT((SELECT top 1 PHONE_WORK from KU_EMPL_PLACING WHERE LINK = SD.REF_KASSIR),40),
		@DIV_NAME = LEFT(ISNULL(F.NAME_FKR_D, ''),254), 
		@DIV_CODE = LEFT(ISNULL(F.CODE_FKR_D, ''),10),
		@TI_NAME = LEFT(ISNULL(F.NAME_FKR_T, ''),254), 
		@TI_CODE = LEFT(ISNULL(F.CODE_FKR_T, ''),0),
		@VR_NAME = LEFT(ISNULL(F.NAME_FKR_E, ''),254), 
		@VR_CODE = LEFT(ISNULL(F.CODE_FKR_E, ''),0),
		@NAME_PAY = LEFT(ISNULL(P.NAME, ''),254), 
		@CODE_PAY = LEFT(ISNULL(P.CODE, ''),10),  
		@NAME_PAYR = LEFT(ISNULL(SD.NAME_PR, ''),254),
		@DATE_BEGIN = dbo.ConvertDMY2Date(1, MONTH(S.DATE_CALC), YEAR(S.DATE_CALC)),
		@Year = YEAR(S.DATE_CALC),
		@Month = (SELECT top 1 m.mon FROM MONTHS M WHERE M.NUM = MONTH(S.DATE_CALC)),
		@MON = MONTH(S.DATE_CALC),
		@CARD_LINK = SD.LINK_CARD
	FROM 
		dbo.SDOC S 
		INNER JOIN dbo.SDOC_VEDOM SD ON S.LINK = SD.LINK_UP
		LEFT JOIN dbo.PAYS P On SD.LINK_PAY = P.LINK
		LEFT JOIN dbo.DICTIONARY_ITEM DI on DI.link = SD.LINK_EKR
		LEFT OUTER JOIN BI_DICTION_VKR F ON SD.LINK_VKR = F.LINK_KBK
	WHERE 
		@nLink IS NOT NULL AND S.LINK = @nLink
		OR
		S.LINK = (SELECT TOP 1 LINK FROM @SPISOK_VEDOM)

	----
	SET 	@DATE_END = dbo.DateEndOfMonth(@DATE_BEGIN)

/*+*/
--Ищем xml формат по названию, для xml нужна замена кавычек в названии организации на &quot;
declare @isxml bit
if exists (
		select top 1 * FROM
		dbo.SDOC S
		INNER JOIN dbo.SDOC_VEDOM SD ON S.LINK = SD.LINK_UP
		LEFT JOIN dbo.cards C ON SD.LINK_CARD = C.LINK and SD.LINK_CARD = @CARD_LINK
		LEFT JOIN dbo.S_BANK_FORMATS F ON F.LINK = C.FRMT_LINK
		where s.LINK = @nLink and f.NAME like '%xml%'
		)
set @isxml = 1
/*+*/
--Выводить вместо подписи лицевой счёт
DECLARE @VEDOM_OPTIONS_2_12 INT
SET @VEDOM_OPTIONS_2_12 = dbo.SA_GET_OPTION_BY_CODE ('VEDOM_OPTIONS_2_12')

SELECT LINK_EMPL, LINK_DOC, LINK_EKR, SUM(SUMMA) AS SUMM
	INTO #SUM_EKR
	FROM DBO.CALCULATE_JURNAL
	WHERE LINK_DOC IN (SELECT LINK_UP FROM #SDOC_VEDOM_TABLE1 )
	GROUP BY LINK_EMPL, LINK_DOC, LINK_EKR 

	INSERT INTO @res
	(LINK_DOC,DOC_DATE, DOC_DATE1, EXCH_DATE, DOC_NUM, 
  	 KASSIR, KASS_POST,KASS_PHONE,
	 DIV_NAME, DIV_CODE,TI_NAME, TI_CODE,VR_NAME, VR_CODE,
  	 NAME_PAYR,
	 NAME_PAY,CODE_PAY,
  	 DATE_BEGIN, DATE_END, 
	 [MONTH], MON, [YEAR],
  	 LINK_EMPL,TN,FIO, FM, IM, OT, S_FIO, INN,
 	 SUMMA, SUMMA1, 
	 ACCT,ACCT_V, BANK_LINK, BANK_NAME, BIK, DEP_ACCT,DEP_ACC_M,
 	 NOSB, NFSB, NDOG_SB, DATE_DOGSB,
	 CARD_LINK, CARD_NAME, CARD_CODE, CARD_POSTF,
 	 POST_CODE,
	 POST,
	 OKLAD ,
	 STAKE ,
	 DAYS_W,
	 HOURS_W,
	 DAYS_H,
	 HOURS_H,
	 SERNUM,
	 DEP_NAME, FULLNAME,
	 PASSPORT,
	 ADDRESS,PINDEX,PHONE,
 	 FD_CODE,FD_DATE,FD_ROVD,
	 SUBDIV_CODE,	
	 SUBDIV,
	 BIRTHDAY,
	 ADDR,
	REGION, ABR_REGION, RAION, ABR_RAION, 
	GOROD, ABR_GOROD, NAS_PUNKT, ABR_NAS_PUNKT,
	ULICA, ABR_ULICA, DOM, KORPUS, KVARTIRA,
	DEP_INN, DEP_KPP, DEP_OKPO, DEP_OGRN, 
	EXRT, EXRT_D, LINK_DEP, FRMT_LINK,
	DD, MM, YYYY, CODE_EKR, LINK_EKR, 
	EKR_ANALIT, CODE_KBK, CODE_DT, CODE_KT, NOTE
/*+*/, RND, [DATE], [TIME]
)
	

	SELECT 
		@nLink, 
		@DOC_DATE, @DOC_DATE1, @EXCH_DATE,  LEFT(@DOC_NUM,60), 
		LEFT(@KASSIR,120), LEFT(@KASS_POST,254),
		LEFT(@KASS_PHONE,40),
		LEFT(@DIV_NAME,254), LEFT(@DIV_CODE,10),
		LEFT(@TI_NAME,254), LEFT(@TI_CODE,10),
		LEFT(@VR_NAME,254), LEFT(@VR_CODE,10),
		LEFT(@NAME_PAYR,254),
		LEFT(@NAME_PAY,120), LEFT(@CODE_PAY,10),
		@DATE_BEGIN, @DATE_END, 
		@Month, @MON,  @Year,
		D.LINK_EMPL, 
        LEFT(E.TAB,15),
		LEFT(ISNULL((SELECT LTRIM(RTRIM(E.FM)) + ' ' + LTRIM(RTRIM(E.IM)) + ' ' +  LTRIM(RTRIM(E.OT))),'Не заполнено'),254),
		LEFT(E.FM,50), LEFT(E.IM,50), LEFT(E.OT,50),
		LEFT(E.FIO,100), LEFT(E.INN,12),
		ISNULL(EKR.SUMM,ISNULL(DISBURS, 0)),
		LEFT(dbo.sa_convert_numeric_to_char(ISNULL(EKR.SUMM,ISNULL(DISBURS, 0)), 2, '.', ','),18),
		[acct] = LEFT(ISNULL(PE.LIC_SCHET, '0'),254), 
		ACCT_V = CASE WHEN @VEDOM_OPTIONS_2_12 = 0 THEN '0' ELSE LEFT(ISNULL(PE.LIC_SCHET, '0'),254) END, 
		PE.BANK_LINK,
		[BANK_NAME] = (SELECT top 1 LEFT([NAME],254) FROM dbo.BANKS WHERE LINK = PE.BANK_LINK),
		[BANK_BIK] =  (SELECT top 1 LEFT(BIK,9) FROM dbo.BANKS WHERE LINK = PE.BANK_LINK),
		[DEP_ACCT]  = (SELECT TOP 1 LEFT(CODE,30) FROM DICTIONARY_ACCOUNTS 
                      WHERE REF_LINK_B = PE.BANK_LINK 
						AND [TYPE_NAME] = 'РАСЧЕТНЫЙ' 
						AND REF_LINK_D = @DEP_LINK),
		[DEP_ACC_M]	 = (SELECT TOP 1 LEFT(CODE,20) FROM DICTIONARY_ACCOUNTS 
                      WHERE link = @DEP_ACC_M
						AND REF_LINK_D = @DEP_LINK),			
						
		[OSB] = ISNULL((SELECT top 1 LEFT(OSB,4) FROM dbo.BANKS WHERE LINK = PE.BANK_LINK),''),
		[FILIAL] = 
			CASE WHEN NOT LTRIM(RTRIM(ISNULL(PE.FILIAL,''))) = '' 
				THEN PE.FILIAL
				ELSE ISNULL((SELECT top 1 LEFT(FILIAL,5) FROM dbo.BANKS WHERE LINK = PE.BANK_LINK),'')
			END,
		[DOGOVOR] = 
			CASE WHEN NOT LTRIM(RTRIM(ISNULL(PE.DOGOVOR,''))) = '' 
				THEN PE.DOGOVOR
				ELSE ISNULL((SELECT top 1 LEFT(DOGOVOR,20) FROM dbo.BANKS WHERE LINK = PE.BANK_LINK),'')
			END,		
		[DATE_DOG] = ISNULL(PE.DATE_DOG,(SELECT top 1 DATE_DOG FROM dbo.BANKS WHERE LINK = PE.BANK_LINK)),
		PE.CARD_LINK, 
		[CARD_NAME] = (SELECT top 1 LEFT([NAME],254) FROM dbo.CARDS WHERE LINK = PE.CARD_LINK),
		[CARD_CODE] = (SELECT top 1 LEFT(CODE,3) FROM dbo.CARDS WHERE LINK = PE.CARD_LINK),
		[POSTFIX] =  (SELECT top 1 LEFT(POSTFIX,2) FROM dbo.CARDS WHERE LINK = PE.CARD_LINK),
		LEFT(E.POST_CODE,10),
		LEFT(E.POST_NAME,254),
		OKLAD = (select  sum(summa)	
				    FROM KJ_MONEY_PERIOD MP 
					INNER JOIN PAYS P ON MP.PAY_LINK=P.LINK
					where
					convert(datetime,'20120808') between mp.date_begin and isnull(mp.date_end,'20990101')
					and	
					P.WAY_CALC = 1
					and MP.EMPL_LINK = d.link_empl
					group by
					MP.EMPL_LINK
				   )	,
		STAKE =  (select TOP 1 num_stake from DBO.SA_EMPLS_INFO(@DOC_DT_BEG, default) where empl_link = d.link_empl ),
		DAYS_W = (dbo.SA_GET_EMPL_WD (D.LINK_EMPL, 0, DEFAULT, dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG))), DEFAULT, 0)),
		HOURS_W = (dbo.SA_GET_EMPL_WH (D.LINK_EMPL, 0, DEFAULT,  dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG))), DEFAULT, 0)) ,
		DAYS_H = (dbo.SA_GET_EMPL_WD (D.LINK_EMPL, 0, DEFAULT,  dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG))), DEFAULT, @TYPE_DAYS)) ,
		HOURS_H = (dbo.SA_GET_EMPL_WH (D.LINK_EMPL, 0, DEFAULT,  dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG)), dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,month(@DOC_DT_BEG),year(@DOC_DT_BEG))), DEFAULT, @TYPE_DAYS)),
/*+*/	replace(LEFT(ISNULL(P.DOC_NUM, ''),20),' ',''),
/*+*/	case when @isxml = 1 then replace(LEFT(@ORGNAME,254),'"','&quot;') else LEFT(@ORGNAME,254) end, case when @isxml = 1 then replace(@ORGFULLNAME,'"','&quot;') else @ORGFULLNAME end,
		LEFT(dbo.PrintSalaryGetPassportString(P.DOC_NUM, P.DOC_WHOM, P.DOC_DATE),254),
		LEFT(dbo.GetAddressByFace(P.LINK, 0),254),
		'',
		LEFT(ISNULL(P.PHONE_OFIC, ''),10),
		[FD_CODE] = (CASE WHEN FD.CODE = '21' THEN '8' 
				  WHEN FD.CODE = '01' THEN '1'
					ELSE LEFT(FD.CODE,2) END), 
		[FD_DATE] = LEFT(CONVERT(VARCHAR,P.DOC_DATE,3),8),
		[FD_ROVD] = LEFT(P.DOC_WHOM,254),
		[SUBDIV]  = LEFT(COALESCE(E.SUBDIV_CODE,''),20),
		[SUBDIV]  = LEFT(COALESCE(E.SUBDIV_NAME,''),254),
		[BIRTHDAY] = LEFT(CONVERT(VARCHAR,P.BIRTHDATE,3),8),
		[ADDR]   = LEFT(dbo.GetAddressByKladr2(P.ADR_OFIC_LINK)+ ' '	+ ltrim(rtrim(house_ofic))+'-'+ltrim(rtrim(flat_ofic)),254),
		REGION = LEFT(RTRIM(LTRIM(Left(dbo.SA_GET_WORD_NUM(ADDRESS2,3,','),len(dbo.SA_GET_WORD_NUM(ADDRESS2,3,','))-len(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,3,',')),1,' '))) ) )),120), 
		ABR_REGION = LEFT(RTRIM(LTRIM(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,3,',')),1,' ')) )), 12),
		RAION = LEFT(RTRIM(LTRIM(Left(dbo.SA_GET_WORD_NUM(ADDRESS2,4,','),len(dbo.SA_GET_WORD_NUM(ADDRESS2,4,','))-len(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,4,',')),1,' '))) ) )), 120),
		ABR_RAION = LEFT(RTRIM(LTRIM(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,4,',')),1,' ')) )), 12),
		GOROD = LEFT(RTRIM(LTRIM(Left(dbo.SA_GET_WORD_NUM(ADDRESS2,5,','),len(dbo.SA_GET_WORD_NUM(ADDRESS2,5,','))-len(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,5,',')),1,' '))) ) )),50),
		ABR_GOROD = LEFT(RTRIM(LTRIM(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,5,',')),1,' ')) )), 12),
		NAS_PUNKT = LEFT(RTRIM(LTRIM(Left(dbo.SA_GET_WORD_NUM(ADDRESS2,6,','),len(dbo.SA_GET_WORD_NUM(ADDRESS2,6,','))-len(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,6,',')),1,' '))) ) )), 120),
		ABR_NAS_PUNKT = LEFT(RTRIM(LTRIM(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,6,',')),1,' ')) )),12),
		ULICA = LEFT(RTRIM(LTRIM(Left(dbo.SA_GET_WORD_NUM(ADDRESS2,7,','),len(dbo.SA_GET_WORD_NUM(ADDRESS2,7,','))-len(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,7,',')),1,' '))) ) )),120),
		ABR_ULICA = LEFT(RTRIM(LTRIM(REVERSE(dbo.SA_GET_WORD_NUM(REVERSE(dbo.SA_GET_WORD_NUM(ADDRESS2,7,',')),1,' ')) )), 12),
		DOM = LEFT(dbo.SA_GET_WORD_NUM(ADDRESS2,8,','), 5),
		KORPUS = LEFT(dbo.SA_GET_WORD_NUM(ADDRESS2,9,','), 5),
		KVARTIRA = LEFT(dbo.SA_GET_WORD_NUM(ADDRESS2,10,','),5),
		LEFT(@DEP_INN,12), LEFT(@DEP_KPP,9), LEFT(@DEP_OKPO,20), LEFT(@DEP_OGRN,13),
		EXRT = COALESCE(F.LastFileNumber,1),
		EXRT_D = COALESCE(FE.NUM_EXPORT,1),
		DOC.LINK_DEP,
		C.FRMT_LINK,
		DD = RIGHT('0' + CONVERT(VARCHAR(2),DAY(GETDATE())),2),
		MM = RIGHT('0' + CONVERT(VARCHAR(2),MONTH(GETDATE())),2),
		YYYY = CONVERT(VARCHAR(4),YEAR(GETDATE())),
		CODE_EKR = COALESCE(SGU.CODE,''), 
		EKR.LINK_EKR,  --Для вывода итогов по ЭКР
		EKR_ANALIT = D.CODE_EKR,
		D.CODE_KBK,
		D.CODE_DT,
		D.CODE_KT,
		REPLACE(D.NOTE,';',' '),
/*+*/	RND = convert(varchar(16), left(replace(cast(CONVERT(binary(8), RAND(), 0) as uniqueidentifier),'-',''), 16)),
/*+*/	[DATE] = convert(varchar(8),getdATE(),112), --YYYYMMDD
/*+*/	[TIME] = replace(convert(varchar(8),getdATE(),108),':','') --HHMMSS
	FROM
		dbo.SDOC DOC 
		INNER JOIN #SDOC_VEDOM_TABLE1 D on DOC.link = D.link_up
		INNER JOIN dbo.SD_EMPL E ON E.LINK = D.LINK_EMPL
		INNER JOIN (Select *, dbo.GET_ADDRESS9PARTS(dbo.PERSON.LINK, 0) ADDRESS2 from dbo.PERSON) P ON E.PERS_LINK = P.LINK
		LEFT OUTER JOIN dbo.FACE_DOCUMENT FD ON P.DOC_LINK = FD.LINK	
		LEFT OUTER JOIN dbo.SA_PERSON_ECARD_ACTUAL PE ON (PE.PERS_LINK = P.LINK AND PE.CARD_LINK = @CARD_LINK)
		LEFT JOIN dbo.cards C ON PE.CARD_LINK = C.LINK
		LEFT JOIN dbo.S_BANK_FORMATS F ON F.LINK = C.FRMT_LINK
		LEFT JOIN dbo.S_BANK_FORMAT_EXPORT FE ON F.LINK = FE.LINK_UP AND FE.LINK_DEP = DOC.LINK_DEP
		LEFT JOIN #SUM_EKR EKR ON EKR.LINK_EMPL = D.LINK_EMPL AND EKR.LINK_EKR = D.LINK_EKR AND DOC.link = EKR.LINK_DOC 
					AND EXISTS (SELECT * FROM DBO.S_BANK_FORMAT_FILES FF WHERE GRP_EKR = 1 AND FF.LINK_FMT = F.LINK)
		LEFT JOIN DBO.KOSGU SGU ON SGU.LINK = EKR.LINK_EKR
	WHERE 
		ISNULL(EKR.SUMM,ISNULL(D.DISBURS, 0)) > 0 
	ORDER BY CASE 
		WHEN @GroupMode = 1 THEN E.SUBDIV_CODE
		ELSE '' END,
	CASE 	
		WHEN @SortMode = 1 THEN E.FM
		WHEN @SortMode = 2 THEN E.TAB
		WHEN @SortMode = 3 THEN E.POST_CODE
		ELSE CAST(D.ORDERS AS VARCHAR(10))
	END

	UPDATE @res SET 
		PINDEX = LTRIM(RTRIM(LEFT(ADDRESS, 7))),
		ADDRESS= LTRIM(RTRIM(RIGHT(ADDRESS, LEN(ADDRESS)-7)))
	WHERE LEFT(ADDRESS, 1) IN (	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

	UPDATE @res SET SUM_ALL = (SELECT SUM(SUMMA) FROM @res)
	UPDATE @res SET COUNT_OP = (SELECT COUNT(*)  FROM @res)

	CREATE TABLE #SUM_EKR1 (LINK_EKR INT, SUMMA NUMERIC(20,2), CNT INT )
	INSERT INTO #SUM_EKR1 (LINK_EKR, SUMMA, CNT)
	SELECT LINK_EKR, SUM(SUMM) AS SUMM, COUNT(LINK_EKR) as CNT_EKR FROM #SUM_EKR
	GROUP BY LINK_EKR

	SELECT R.*, 
		NPP_G= (Case when @GroupMode = 1 then (Select count(NPP) from @res RC where COALESCE(RC.SUBDIV_CODE,'') = COALESCE(R.SUBDIV_CODE,'') and RC.NPP <= R.NPP) else R.NPP end),
		GRP_EKR = CASE WHEN EK.SUMMA IS NULL THEN 0 ELSE 1 END,
		ITOG_EKR = COALESCE(EK.SUMMA,0),
		KOL_ST_EKR = COALESCE(EK.CNT,0)
	FROM 
		@res R LEFT JOIN #SUM_EKR1 EK ON R.LINK_EKR = EK.LINK_EKR
	ORDER BY CODE_EKR, NPP

	SELECT NDOG_SB, NOSB, NFSB, COUNT(*) AS COUNT_OP, SUM(SUMMA) AS SUMMA_ALL 
	INTO #RES1
	FROM @res
	GROUP BY NDOG_SB, NOSB, NFSB
	ORDER BY 1, 2, 3
	
	SELECT @ORGNAME AS ORGNAME, * FROM #RES1
	ORDER BY 1, 2, 3, 4

END



GO


GRANT EXECUTE ON dbo.[SD_REP_VEDOM_PREPARE_DATA] TO PUBLIC

GO
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FB_CREATE_LIMIT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[FB_CREATE_LIMIT]
GO

CREATE PROCEDURE dbo.FB_CREATE_LIMIT	@dDate	datetime, 
					@cBuffId char(100)


AS
BEGIN
DECLARE @tTempAssign TABLE 
	(DepAcc	int,
	 DateDoc datetime,
	 NumDoc varchar(30),
	 PolAcc	int,
	 FYear		int,
	 Kap		tinyint,
	 VKR		int,
	 EKR		int,
	 DopCl		int,
	 REG		int,
	 P1	 [numeric](19, 2),
	 P2	 [numeric](19, 2),
	 P3	 [numeric](19, 2),
	 P4	 [numeric](19, 2),
	 P5	 [numeric](19, 2),
	 P6	 [numeric](19, 2),
	 P7	 [numeric](19, 2),
	 P8	 [numeric](19, 2),
	 P9	 [numeric](19, 2),
	 P10	 [numeric](19, 2),
	 P11	 [numeric](19, 2),
	 P12	 [numeric](19, 2),
	 Y2	 [numeric](19, 2),
	 Y3	 [numeric](19, 2))

declare @iLimType 	tinyint,
	@iLimPer 	tinyint,
	@iAssPer 	tinyint,
	@iBegPer	int,
	@iEndPer	int,
	@iOwnDep	int,
	@Cur1		cursor,
	@iDocCount	int,
	@nAllSumma 	numeric(19,2),
	
	@iDepAcc	int,
	@iPolAcc	int,
	@iFYear		int,
	@iKap		tinyint,
	
	@iPerNum	tinyint,
	@iDocLink	int,
	@cNumber	char(30),
	@nSumma 	numeric(19,2),
	@iParam		tinyint,
	@dDateDoc	datetime
	
select @dDate = case isnull(LIM_DATE,0) when 1 then null else @dDate end from dbo.FINANS_ASSIGN_OPTIONS	

	 
select @iDocCount = 0, @nAllSumma = 0
	
set @iOwnDep = isnull(dbo.BK_GetDepZB(), dbo.GetOwnDepLink())	
SELECT	@iAssPer = max(FIN_SMETA_PER) FROM dbo.WorkMode
SELECT	@iLimType = max(FIN_LIM_TYPE), @iLimPer = max(FIN_LIM_PER) FROM WorkMode
if @iAssPer < @iLimPer 
begin
	select TXT = 'Период ведения лимитов меньше периода ведения ассигнований. Формирование невозможно!'
	return -1
end
insert into @tTempAssign
select GP.ACC, 
	isnull(@dDate,GP.[DATE]),
	case @iLimType when 0 then GP.NUMBER else null end,
	FH.ACCOUNT, FH.FYEAR,
	FH.PARAM & 0x2,
	F.VKR, 
	F.EKR, 
	F.DOP_CL, 
	F.REG,
	P1 = sum(P1), 
	P2 = sum(P2), 
	P3 = sum(P3), 
	P4 = sum(P4), 
	P5 = sum(P5), 
	P6 = sum(P6), 
	P7 = sum(P7), 
	P8 = sum(P8), 
	P9 = sum(P9), 
	P10 = sum(P10), 
	P11 = sum(P11), 
	P12 = sum(P12), 
	Y2 = sum(Y2), 
	Y3 = sum(Y3)
from dbo.FINANSE F 
inner join dbo.FINANSE_HEAD FH on F.LINK_UP = FH.LINK
inner join dbo.G_PROV GP on GP.DEP = @iOwnDep and FH.LINK = GP.LINK
inner join dbo.BufferGetTableByID(@cBuffId) B on GP.LINK = B.LINK
where not(P1 = 0 and P2 = 0 and P3 = 0 and P4 = 0 and P5 = 0 and P6 = 0 and P7 = 0 and P8 = 0 and P9 = 0 and P10 = 0 and P11 = 0 and P12 = 0 and Y2 = 0 and Y3 = 0)
group by GP.ACC, FH.ACCOUNT, FH.PER_NUM, FH.FYEAR, F.VKR, F.EKR, F.DOP_CL, F.REG, FH.PARAM & 0x2, isnull(@dDate,GP.[DATE]),case @iLimType when 0 then GP.NUMBER else null end


	
if @iLimPer = 1
	update @tTempAssign
	set P1 = P1 + P2 + P3 + P4 + P5 + P6 + P7 + P8 + P9 + P10 + P11 + P12,
	P2 = 0, P3 = 0, P4 = 0, P5 = 0, P6 = 0, P7 = 0, P8 = 0, P9 = 0, P10 = 0, P11 = 0, P12 = 0   
if @iLimPer = 2
	update @tTempAssign
	set P1 = P1 + P2 + P3, P2 = 0, P3 = 0, 
	    P4 = P4 + P5 + P6, P5 = 0, P6 = 0, 
	    P7 = P7 + P8 + P9, P8 = 0, P9 = 0, 
	    P10 = P10 + P11 + P12, P11 = 0, P12 = 0   
if @iLimType = 0
begin 
	set @iBegPer = 0
	set @iEndPer = 0
end
else
begin 
	set @iBegPer = 1
	if @iLimPer = 1
		set @iEndPer = 1
	if @iLimPer = 2
		set @iEndPer = 10
	if @iLimPer = 3
		set @iEndPer = 12
end	

SET @Cur1 = CURSOR FORWARD_ONLY FOR
select distinct DepAcc, PolAcc, FYear, Kap, DateDoc, NumDoc 
from @tTempAssign

open @Cur1
fetch next from @Cur1 into @iDepAcc, @iPolAcc, @iFYear, @iKap, @dDateDoc, @cNumber

while @@FETCH_STATUS = 0
begin
	set @iPerNum = @iBegPer
	while @iPerNum <= @iEndPer
	begin
		if @iLimType = 1
			exec dbo.X_DOCUMENT_GET_NEXT_NUMBER 'FINANS_LIMIT', @cNumber output, @iOwnDep 
		
		if exists(select * 
			  from dbo.FINANSE_HEAD F, dbo.G_PROV G, dbo.S_OBJECTS S 
			  where F.FYEAR = @iFYear 
				and F.PER_NUM = @iPerNum 
				and F.LINK = G.LINK 
				AND G.OBJECT = S.LINK 
				AND S.CODE = 'FINANS_LIMIT' 
				and F.ACCOUNT = @iPolAcc
				and G.ACC = @iDepAcc
				and F.PARAM & 0x1 = 0)
			set @iParam = 1 + @iKap
		else
			set @iParam = 0 + @iKap
		--print @iLimPer
		set @nSumma = 0
		select @nSumma = case  	when @iLimPer = 1 or @iPerNum = 0 then sum(P1 + P2 + P3 + P4 + P5 + P6 + P7 + P8 + P9 + P10 + P11 + P12)
					when @iLimPer = 2 and @iPerNum = 1 then sum(P1 + P2 + P3)
					when @iLimPer = 2 and @iPerNum = 4 then sum(P4 + P5 + P6)
					when @iLimPer = 2 and @iPerNum = 7 then sum(P7 + P8 + P9)
					when @iLimPer = 2 and @iPerNum = 10 then sum(P10 + P11 + P12)
					when @iPerNum = 3 and @iPerNum = 1 then sum(P1)
					when @iPerNum = 3 and @iPerNum = 2 then sum(P2)
					when @iPerNum = 3 and @iPerNum = 3 then sum(P3)
					when @iPerNum = 3 and @iPerNum = 4 then sum(P4)
					when @iPerNum = 3 and @iPerNum = 5 then sum(P5)
					when @iPerNum = 3 and @iPerNum = 6 then sum(P6)
					when @iPerNum = 3 and @iPerNum = 7 then sum(P7)
					when @iPerNum = 3 and @iPerNum = 8 then sum(P8)
					when @iPerNum = 3 and @iPerNum = 9 then sum(P9)
					when @iPerNum = 3 and @iPerNum = 10 then sum(P10)
					when @iPerNum = 3 and @iPerNum = 11 then sum(P11)
					when @iPerNum = 3 and @iPerNum = 12 then sum(P12) end
		from @tTempAssign
		where DepAcc = @iDepAcc and PolAcc = @iPolAcc and FYear = @iFYear and Kap = @iKap 
				and (@dDate is null or @dDate is not null and DateDoc = @dDateDoc)
				and (@iLimType = 1 or @iLimType = 0 and NumDoc = @cNumber)
		
		set @iDocLink = null

		exec dbo.FB_SAVE_FINANS @iDocLink output, @cNumber, @dDateDoc, null, @nSumma, '', @iFYear, @iPolAcc, @iPerNum, @iParam, null, null, 'FINANS_LIMIT', @iDepAcc
		
		insert into dbo.FINANSE (LINK_UP, VKR, EKR, DOP_CL, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, Y2, Y3)
		select @iDocLink, VKR, EKR, DopCl, REG, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, Y2, Y3
		from (select VKR, EKR, DopCl, REG,  
			P1 = case when @iPerNum = 0 then sum(P1)
				  when @iLimPer = 1 then sum(P1 + P2 + P3 + P4 + P5 + P6 + P7 + P8 + P9 + P10 + P11 + P12)
				  when @iLimPer = 2 and @iPerNum = 1 then sum(P1 + P2 + P3)
				  when @iLimPer = 2 and @iPerNum = 4 then sum(P4 + P5 + P6)
				  when @iLimPer = 2 and @iPerNum = 7 then sum(P7 + P8 + P9)
				  when @iLimPer = 2 and @iPerNum = 10 then sum(P10 + P11 + P12)
				  when @iPerNum = 3 and @iPerNum = 1 then sum(P1)
				  when @iPerNum = 3 and @iPerNum = 2 then sum(P2)
				  when @iPerNum = 3 and @iPerNum = 3 then sum(P3)
				  when @iPerNum = 3 and @iPerNum = 4 then sum(P4)
				  when @iPerNum = 3 and @iPerNum = 5 then sum(P5)
				  when @iPerNum = 3 and @iPerNum = 6 then sum(P6)
				  when @iPerNum = 3 and @iPerNum = 7 then sum(P7)
				  when @iPerNum = 3 and @iPerNum = 8 then sum(P8)
				  when @iPerNum = 3 and @iPerNum = 9 then sum(P9)
				  when @iPerNum = 3 and @iPerNum = 10 then sum(P10)
				  when @iPerNum = 3 and @iPerNum = 11 then sum(P11)
				  when @iPerNum = 3 and @iPerNum = 12 then sum(P12) else 0 end,
			P2 = case when @iPerNum = 0 then sum(P2) else 0 end,
			P3 = case when @iPerNum = 0 then sum(P3) else 0 end,
			P4 = case when @iPerNum = 0 then sum(P4) else 0 end,
			P5 = case when @iPerNum = 0 then sum(P5) else 0 end,
			P6 = case when @iPerNum = 0 then sum(P6) else 0 end,
			P7 = case when @iPerNum = 0 then sum(P7) else 0 end,
			P8 = case when @iPerNum = 0 then sum(P8) else 0 end,
			P9 = case when @iPerNum = 0 then sum(P9) else 0 end,
			P10 = case when @iPerNum = 0 then sum(P10) else 0 end,
			P11 = case when @iPerNum = 0 then sum(P11) else 0 end,
			P12 = case when @iPerNum = 0 then sum(P12) else 0 end,
			Y2 = sum(Y2),
			Y3 = sum(Y3) 
		from @tTempAssign
		where DepAcc = @iDepAcc and PolAcc = @iPolAcc and FYear = @iFYear and Kap = @iKap 
				and (@dDate is null or @dDate is not null and DateDoc = @dDateDoc)
				and (@iLimType = 1 or @iLimType = 0 and NumDoc = @cNumber)
				
		group by VKR, EKR, DopCl, REG) T
		where T.P1 <> 0 or T.P2 <> 0 or T.P3 <> 0 or T.P4 <> 0 or T.P5 <> 0 or T.P6 <> 0 or T.P7 <> 0 or T.P8 <> 0 or T.P9 <> 0 or T.P10 <> 0 or T.P11 <> 0 or T.P12 <> 0 or T.Y2 <> 0 or T.Y3 <> 0
		if @@rowcount <> 0 
			select @iDocCount = @iDocCount + 1, @nAllSumma = @nAllSumma + @nSumma
		else
			delete from dbo.G_PROV where LINK = @iDocLink


		if @iLimPer = 2
			set @iPerNum = @iPerNum + 3
		else
			set @iPerNum = @iPerNum + 1
		exec FB_SAVE_G_PROV1_DOC_LIMIT @iDocLink,1
	end

	fetch next from @Cur1 into @iDepAcc, @iPolAcc, @iFYear, @iKap, @dDateDoc, @cNumber
end


select TXT = 'Сформировано ' + ltrim(rtrim(str(@iDocCount))) + ' документа(ов) на сумму ' + ltrim(rtrim(str(@nAllSumma))) + ' руб.'

RETURN
END


GO

grant all on FB_CREATE_LIMIT to public
GO


GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[XD_FORM_BO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[XD_FORM_BO]
GO





CREATE    PROCEDURE dbo.XD_FORM_BO
	@varKSparLINK	 int
AS
/* Определить что за объект */
DECLARE @LinkObjCode VARCHAR(30),
		@LinkObjName VARCHAR(254),
		@iLBO		 bit,
		@cDocInfo	 VARCHAR(254),
		@LinkAcc int,
		@LinkDep int
declare @tLog table (txt varchar(254), NEW_ROW tinyint, nSTATUS tinyint, nTAB tinyint, ord int identity(1,1))

SELECT @LinkObjCode = CODE, 
	   @LinkObjName = NAME
FROM S_OBJECTS WHERE LINK = (SELECT OBJECT FROM G_PROV WHERE LINK = @varKSparLINK)

/* Найти соответствие в журнале документов оснований */


SELECT @cDocInfo = CONVERT(VARCHAR(254), dbo.JurnalProvGetDocKind (LINK, OBJECT) + 
					' № ' + LTRIM(RTRIM(NUMBER))+' от ' + CONVERT(VARCHAR(10),DATE,104)
		   	+ ' '+ ISNULL(LTRIM(RTRIM(CONVERT(VARCHAR(100), COMMENT))),''))
FROM dbo.G_PROV WHERE LINK = @varKSparLINK


insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
values('Формирование обязательств по документу ' + @cDocInfo,1,0,0)		

/* Определяем счет - если в документе его нет, то берем тот счет что указан для организации по умолчанию */

SELECT @LinkAcc = ACC,@LinkDep = DEP FROM G_PROV WHERE LINK = @varKSparLINK
IF @LinkAcc IS NULL
  SELECT @LinkAcc = MAIN_LINK FROM DEPARTMENTS WHERE LINK = @LinkDep 
IF @LinkAcc IS NULL
BEGIN
	insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
	values('Не сформированы обязательства. Некорректрый счет организации.',1,2,1)
	select txt, NEW_ROW, nSTATUS, nTAB from @tLog order by ord
	return 0
		
END

BEGIN TRAN

DECLARE @LinkOsnov int
SELECT @LinkOsnov = LINK FROM dbo.BD_OSNOV WHERE DOC_LINK = @varKSparLINK

IF EXISTS(SELECT * FROM JURN_BO WHERE LINK_DOC = @LinkOsnov)
BEGIN
	/* Грохаем проводки по принятым БО*/
	/*update G_PROV
	set date_prov = null
	--set date_prov = date
	WHERE LINK IN (SELECT GP1.LINK_UP FROM G_PROV1 GP1
	 WHERE GP1.LINK IN (SELECT GP2.LINK_UP FROM G_PROV2 GP2 
	   WHERE GP2.LINK IN (SELECT PROV_LINK FROM BD_JURN_BO WHERE AP1 = @LinkOsnov)))*/

	update G
	set date_prov = null
	from dbo.G_PROV G
	inner join G_PROV1 G1 on G1.LINK_UP = G.LINK
	inner join G_PROV2 G2 on G2.LINK_UP = G1.LINK
	inner join JURN_BO BO on BO.LINK_PO_PROV = G2.LINK and BO.LINK_DOC = @LinkOsnov
	
	DELETE FROM G_PROV
	from dbo.G_PROV G
	inner join G_PROV1 G1 on G1.LINK_UP = G.LINK
	inner join G_PROV2 G2 on G2.LINK_UP = G1.LINK
	inner join JURN_BO BO on BO.LINK_PO_PROV = G2.LINK and BO.LINK_DOC = @LinkOsnov
	
	/*WHERE LINK IN (SELECT GP1.LINK_UP FROM G_PROV1 GP1
	 WHERE GP1.LINK IN (SELECT GP2.LINK_UP FROM G_PROV2 GP2 
	   WHERE GP2.LINK IN (SELECT PROV_LINK FROM BD_JURN_BO WHERE AP1 = @LinkOsnov)))*/

	/* Грохаем из журнала зарегистрированные по данному обязаетльству БО */
	DELETE FROM JURN_BO WHERE LINK_DOC = @LinkOsnov

END
--	print @LinkOsnov
--	print @varKSparLINK




IF @@ROWCOUNT = 0
BEGIN	
  IF NOT EXISTS(SELECT * FROM dbo.OSNOV_VID WHERE OBJECT = @LinkObjCode)
	INSERT INTO dbo.OSNOV_VID(NAME,TYPE,OBJECT,[SYSTEM]) 	
	VALUES(@LinkObjName,1,@LinkObjCode,1)
	
	INSERT INTO dbo.OSNOV(TYPE_LINK,LINK_G_PROV) 
	SELECT TOP 1 LINK AS TYPE_LINK, @varKSparLINK AS LINK_G_PROV FROM dbo.OSNOV_VID WHERE OBJECT = @LinkObjCode
	SET @LinkOsnov = @@IDENTITY
END


DECLARE @Curs CURSOR,
        @dDate_Prov datetime,
     	@nSUMMA numeric(18,2),
		@iIstFin tinyint,
		@iCode varchar(8),  
		@iKBK int,
        @iSGU int,
		@iDOP int,
		@iDO  tinyint,
		@cComment varchar(254),
		@iLinkProv int,
		@iLinkBO int,
		@cEKRLimBO varchar(250),
		@iSign tinyint,
		@cDtCode varchar(10),
		@cKtCode varchar(10),
		@cProvErr varchar(100)

set @cEKRLimBO = isnull((select BO_EKR from  dbo.FINANS_LIMIT_OPTIONS), '251')

SET @Curs = CURSOR FORWARD_ONLY FOR 
SELECT G.DATE_PROV,
		KBK = case EO.BO_DT_KT when 0 then isnull(GD.KBK, GK.KBK) else isnull(GK.KBK, GD.KBK) end,
		SGU = case EO.BO_DT_KT when 0 then isnull(case SD.AP_EKR when 1 then GD.EKR else GD.SGU end, case SK.AP_EKR when 1 then GK.EKR else GK.SGU end) 
										else isnull(case SK.AP_EKR when 1 then GK.EKR else GK.SGU end, case SD.AP_EKR when 1 then GD.EKR else GD.SGU end) end,
		DOP = case EO.BO_DT_KT when 0 then isnull(GD.AP2, GK.AP2) else isnull(GK.AP2, GD.AP2) end,
		IstFin = CONVERT(TINYINT,LEFT(SD.cSource,1)),
		DO = 0,
		COMMENT = 'Основание: ' + coalesce(G1.NAME_OPER, G2.NAME, ' не заполнен комментарий к проводке '),
		SUMMA = case EO.BO_MIN when 0 then G2.SUMMA else - G2.SUMMA end,
		DT_CODE = SD.CODE,
		KT_CODE = SK.CODE
FROM dbo.G_PROV G
inner join dbo.G_PROV1 G1 on G1.LINK_UP = G.LINK
inner join dbo.G_PROV2 G2 on G2.LINK_UP = G1.LINK
inner join dbo.XOZ_OPER EO on G2.ECON_OPER = EO.LINK and EO.BO = 1 
inner join dbo.G_PROV_AP GD on GD.LINK_UP = G2.LINK AND GD.DB_KR = 0
inner join dbo.G_PROV_AP GK on GK.LINK_UP = G2.LINK AND GK.DB_KR = 1 
inner join dbo.S_ACCOUNTS SD on SD.LINK = GD.ACCOUNT
inner join dbo.S_ACCOUNTS SK on SK.LINK = GK.ACCOUNT
where G.DATE_PROV is not null and 
		G.LINK = @varKSparLINK and (SK.CODE LIKE '1.501._3' and exists(select * from dbo.KOSGU where link = GK.EKR and @cEKRLimBO like '%' + CODE +  '%')
									or (SK.CODE not LIKE '1.501._3' and SK.CODE <> '1.502.11'))
union all
SELECT G.DATE_PROV,
		KBK = case EO.DO_DT_KT when 0 then isnull(GD.KBK, GK.KBK) else isnull(GK.KBK, GD.KBK) end,
		SGU = case EO.BO_DT_KT when 0 then isnull(case SD.AP_EKR when 1 then GD.EKR else GD.SGU end, case SK.AP_EKR when 1 then GK.EKR else GK.SGU end) 
										else isnull(case SK.AP_EKR when 1 then GK.EKR else GK.SGU end, case SD.AP_EKR when 1 then GD.EKR else GD.SGU end) end,
		DOP = case EO.DO_DT_KT when 0 then isnull(GD.AP2, GK.AP2) else isnull(GK.AP2, GD.AP2) end,
		IstFin = CONVERT(TINYINT,LEFT(SD.cSource,1)),
		DO = 1,
		COMMENT = 'Основание: ' + coalesce(G1.NAME_OPER, G2.NAME, ' не заполнен комментарий к проводке '),
		SUMMA = case EO.DO_MIN when 0 then G2.SUMMA else - G2.SUMMA end,
		DT_CODE = SD.CODE,
		KT_CODE = SK.CODE
FROM dbo.G_PROV G
inner join dbo.G_PROV1 G1 on G1.LINK_UP = G.LINK
inner join dbo.G_PROV2 G2 on G2.LINK_UP = G1.LINK
inner join dbo.XOZ_OPER EO on G2.ECON_OPER = EO.LINK and EO.DO = 1 
inner join dbo.G_PROV_AP GD on GD.LINK_UP = G2.LINK AND GD.DB_KR = 0
inner join dbo.G_PROV_AP GK on GK.LINK_UP = G2.LINK AND GK.DB_KR = 1 
inner join dbo.S_ACCOUNTS SD on SD.LINK = GD.ACCOUNT
inner join dbo.S_ACCOUNTS SK on SK.LINK = GK.ACCOUNT
where G.DATE_PROV is not null and G.LINK = @varKSparLINK


OPEN @Curs
FETCH NEXT FROM @Curs INTO @dDate_Prov, @iKBK, @iSGU, @iDOP, @iIstFin, @iDO, @cComment, @nSUMMA, @cDtCode, @cKtCode
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @iLinkBO = NULL
	SET @iLinkProv = NULL
	
	/* Не хватает данных для формирования БО */
	IF (@iSGU IS NULL OR @iKBK IS NULL) 
	BEGIN
		insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
		values('Не сформировано ' + case @iDO when 1 then 'денежное' else 'бюджетное' end + ' обязательство по проводке ' + @cDtCode + ' - ' + @cKtCode + ' на сумму ' + ltrim(str(@nSUMMA,20,2)) + '. Незаполнена классификация.',1,2,1)		
	END
	else		
	begin
		
		INSERT INTO dbo.JURN_BO(LINK_DOC,DATE_DOC,LINK_KBK,LINK_SGU,SUMMA,LINK_ACCOUNT,IST_FIN,LINK_DOP,COMMENT, DO)
		VALUES(@LinkOsnov,@dDate_Prov,@iKBK,@iSGU,@nSUMMA,@LinkAcc,@iIstFin,@iDOP,@cComment, @iDO)
		
		SET @iLinkBO = @@IDENTITY
		if @iLinkBO is null
			insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
			values('Не сформировано ' + case @iDO when 1 then 'денежное' else 'бюджетное' end + ' обязательство по проводке ' + @cDtCode + ' - ' + @cKtCode + ' на сумму ' + ltrim(str(@nSUMMA,20,2)) + '. Ошибка при формировании.',1,2,1)		
		ELSE
		begin
			insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
			values('Cформировано ' + case @iDO when 1 then 'денежное' else 'бюджетное' end + ' обязательство по проводке ' + @cDtCode + ' - ' + @cKtCode + ' на сумму ' + ltrim(str(@nSUMMA,20,2)),1,0,1)		
			
			/* Сформируем проводки*/
			EXEC BD_JURN_BO_FORM_PROV @iLinkProv OUTPUT, @iLinkBO, @cProvErr OUTPUT 
			if @iLinkProv is null
				insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
				values('Не сформирована проводка по принятию обязательства. ' + isnull(@cProvErr,'Ошибка при формировании.'),1,2,2)		
			else
				insert into @tLog(txt, NEW_ROW, nSTATUS, nTAB) 
				values('Cформирована проводка по принятию обязательства. ',1,0,2)		
			
		end
		
		
	end
	FETCH NEXT FROM @Curs INTO @dDate_Prov, @iKBK, @iSGU, @iDOP, @iIstFin, @iDO, @cComment, @nSUMMA, @cDtCode, @cKtCode
END
CLOSE @Curs
DEALLOCATE @Curs

COMMIT TRAN 
select txt, NEW_ROW, nSTATUS, nTAB from @tLog order by ord
return 0


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

grant execute on dbo.XD_FORM_BO to public

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_VAC_CHANGE_PERIOD_SAVE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_VAC_CHANGE_PERIOD_SAVE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/
CREATE  PROCEDURE [dbo].SD_VAC_CHANGE_PERIOD_SAVE
	@LINK	int	OUTPUT,
	@LINK_EMPL	int,
	@Date1	datetime,
	@Date2	datetime,
	@YEAR1	INT,
	@YEAR2	INT,
	@COMMENT	varchar(200)
AS
DECLARE 
	@ERROR	tinyint,
	@trancount	int,
	@EventText varchar(100),
	@chrNAME  varchar(30),
	@objCHANGE_PERIOD_VAC int,
	@SQLError INT,
	@RowCount INT

SET @trancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN

	IF ISNULL(@LINK_EMPL,0) = 0 OR @Date1 IS NULL OR @Date2 IS NULL OR ISNULL(@YEAR1,0) = 0 OR ISNULL(@YEAR2,0) = 0
	BEGIN
		ROLLBACK
		RETURN 5
	END
	
	IF EXISTS (SELECT * FROM dbo.VAC_PERIOD_CHANGE WHERE LINK <> @LINK AND LINK_EMPL = @LINK_EMPL AND @DATE1 <= DATE2 AND @DATE2 >= DATE1)
	BEGIN
		ROLLBACK
		RETURN 8
	END		

	SELECT @chrNAME = dbo.sd_GetEmplName(@LINK_EMPL)
	SELECT @objCHANGE_PERIOD_VAC = LINK FROM dbo.S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC'

	--EXECUTE @ERROR = X_UPDATE_CHANGE_PERIOD_VAC @LINK OUTPUT,@LINK_EMPL,@COMMENT,@DATE1_R,@DATE2_R,@Date1,@Date2,
	--					 @LINK_R

	IF ISNULL(@LINK,0) = 0
	BEGIN
		INSERT INTO dbo.VAC_PERIOD_CHANGE WITH (ROWLOCK) (LINK_EMPL,DATE1,DATE2,YEAR1,YEAR2,COMMENT)
		VALUES (@LINK_EMPL,@DATE1,@DATE2,@YEAR1,@YEAR2,@COMMENT)
		SELECT @SQLError = @@ERROR, @LINK = @@IDENTITY
		IF @SQLError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END
	ELSE
	BEGIN
		UPDATE dbo.VAC_PERIOD_CHANGE WITH (ROWLOCK) 
		SET LINK_EMPL = @LINK_EMPL, DATE1 = @DATE1, DATE2 = @DATE2, YEAR1 = @YEAR1, YEAR2 = @YEAR2, COMMENT = @COMMENT
		WHERE LINK=@LINK
		
		SELECT @SQLError = @@ERROR, @RowCount = @@ROWCOUNT
		IF @SQLError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
		IF @RowCount = 0
		BEGIN
			ROLLBACK
			RETURN 2
		END
	END
						 
	IF @ERROR <> 0
		RETURN @ERROR

	SET @EventText = 'Замена расчетного периода БЛ:' + ' ' +  LTRIM(RTRIM(@chrNAME))
	EXECUTE WF_GENERATEEVENT 'Сохранение строки справочника', @EventText, @objCHANGE_PERIOD_VAC, 'VAC_PERIOD_CHANGE',@LINK

IF @@TRANCOUNT > @trancount
	COMMIT TRAN
RETURN 0


GO


GRANT EXECUTE ON dbo.[SD_VAC_CHANGE_PERIOD_SAVE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_BOOK_MAIN]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_BOOK_MAIN]

GO

CREATE PROCEDURE dbo.BK_REPORT_BOOK_MAIN 
		@DATE_START		DATETIME	/* -- НАЧАЛО ПЕРИОДА -- */,
		@DATE_STOP		DATETIME	/* -- КОНЕЦ ПЕРИОДА -- */,
--		@ACCOUNT_LONG		tinyint,
--		@cSOURCE		CHAR (1),
		@intSTR_JO		INT,		/* -- 0 - Разделять обороты по ЖО,
								1 - Выводить ЖО ондной строкой с одинаковой аналитикой -- */
--		@intSource0		INT,
		@intZabalansAcct	INT,
		@intACCT_GR		INT,
		@varKScVal1	char(1), @varKSnOtborLink1 int,	 -- Отбор субсчетов --
		@intPRN_KBK	int,				-- Код счета с КБК --
		@intPRN_KOSGU	int,				-- Код счета с КОСГУ --
		@intSVOD_ZB	int,				-- Сводный отчет (ЦБ) --
		@intGRP_SGU	int,				-- Вывести подитоги по субсчетам с по группе КОСГУ --
		@cVal_KBK char(1), @nOtborLinkKBK int,		-- Отбор КБК --
		@cVal_KOSGU char(1), @nOtborLinkKOSGU int,	-- Отбор КОСГУ --
		@cVal_SFIN char(1), @nOtborLinkSFIN int,	-- Отбор источников финансирования --
		@cVal_KAU char(1) = '', @nOtborKAU	int	= 0 -- Отбор источников финансирования --
AS
BEGIN
	DECLARE @DATE_BEG_YEAR DATETIME,  -- Дата начала года
		@MONTH_NAME VARCHAR(20),  -- Дата начала года
		@OUT_DATE_REST	DATETIME, -- Для расчета конечных остатков

		@intDEP_LINK	INT,
		@strORGNAME	VARCHAR (254),
		@strOKPO	VARCHAR (20),
		@strGLBUH	VARCHAR (100),
		@UCHR_NAME	VARCHAR (254),	-- Учредитель
		@BUDG_NAME	VARCHAR (254)	-- Наименование бюджета

	SET @DATE_BEG_YEAR = dbo.DateBeginOfYear (@DATE_START)
	SELECT @MONTH_NAME = dbo.DateMonthName(MONTH(@DATE_STOP))

	SET @intSVOD_ZB = ISNULL (@intSVOD_ZB, 0)	/* -- Сводный отчет по ЦБ -- */
	SET @intDEP_LINK = ISNULL (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())
	
	IF @intSVOD_ZB = 1				/* -- Сводный отчет по ЦБ (собственные реквизиты организации) -- */
		SET @intDEP_LINK = dbo.GetOwnDepLink ()

	SELECT
		@strOKPO = D.[OKPO],
		@strORGNAME = dbo.BK_GET_PRINT_DEP_NAME (D.LINK),
		@UCHR_NAME = dbo.BK_GET_PRINT_DEP_NAME (D.UCHR_LINK),
		@BUDG_NAME = B.[NAME]
	FROM dbo.DEPARTMENTS D
	LEFT JOIN dbo.KL_ADMIN_BS V ON (V.LINK = D.VED_LINK)
	LEFT JOIN dbo.KL_BUDG_TYPE B ON (B.LINK = V.Link_Budg)
	WHERE D.LINK = @intDEP_LINK

	SELECT @UCHR_NAME = ISNULL (@UCHR_NAME, ''),
		@BUDG_NAME = ISNULL (@BUDG_NAME, '')

	IF @intSVOD_ZB = 1
		SET @strORGNAME = RTRIM (@strORGNAME) + ' (ЦБ)'

	SELECT @strGLBUH = SHORT_NAME
	FROM dbo.GetOtvFaceData (@intDEP_LINK, 'Главный бухгалтер')

	--- ОТБОР ПО СУБСЧЕТАМ --- 
	-- Отбор источников финансирования --
	DECLARE @TAB_SFIN TABLE (CODE CHAR (2))

	IF LEN (@cVal_SFIN) > 0 
		INSERT INTO @TAB_SFIN
		SELECT 
			D.CODE
		FROM dbo.OBJECT_VAR_FIN_SOURCE OVR
		INNER JOIN dbo.FIN_SOURCE D ON (D.LINK = OVR.RECORD)
		WHERE OVR.LINK_UP = @nOtborLinkSFIN
--			AND D.ISUSED = 1
	ELSE
	BEGIN
		INSERT INTO @TAB_SFIN
		SELECT 
			D.CODE
		FROM dbo.FIN_SOURCE D 
		WHERE D.ISUSED = 1

		INSERT INTO @TAB_SFIN (CODE) 
		SELECT ''
	END

	-- Отбор субсчетов --
	DECLARE @TAB_ACCT TABLE (ACCOUNT INT, ACCT_ROOT INT, JO INT)

	IF LEN (@varKScVal1) > 0
		INSERT INTO @TAB_ACCT
		SELECT
			OVR.RECORD,
			CASE 
				WHEN SA.cUSER <> '' THEN SA.LINK_SELF
				ELSE OVR.RECORD
			END,
			0	-- ЖО НЕ БЕРЕМ ИЗ ПС -- 
--			SA.JO
		FROM dbo.OBJECT_VAR_ACCT OVR
		INNER JOIN dbo.S_ACCOUNTS SA ON (OVR.RECORD = SA.LINK)
		WHERE OVR.LINK_UP = @varKSnOtborLink1
	ELSE
		INSERT INTO @TAB_ACCT
		SELECT
			SA.LINK,
			CASE 
				WHEN SA.cUSER <> '' THEN SA.LINK_SELF
				ELSE SA.LINK
			END,
			0	-- ЖО НЕ БЕРЕМ ИЗ ПС --
		FROM dbo.AccountsTableWithNoChild () T1
		INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = T1.LINK)
		INNER JOIN @TAB_SFIN T2 ON (T2.CODE = SA.cSOURCE)
		WHERE (@intZabalansAcct = 1
			OR (@intZabalansAcct = 2 AND ZABALANS = 0)
			OR (@intZabalansAcct = 3 AND ZABALANS = 1))

	--- ОТБОР ПО КБК --- 
	DECLARE @TAB_KBK TABLE (LINK_KBK INT, KBK_CODE VARCHAR (20))
	IF LEN (@cVal_KBK) > 0
		INSERT INTO @TAB_KBK
		SELECT AP.LINK,
			AP.CODE
		FROM dbo.KL_KBK AP 
		INNER JOIN dbo.OBJECT_VAR_KBK OVR ON (OVR.RECORD = AP.LINK)
		WHERE OVR.LINK_UP = @nOtborLinkKBK
	ELSE
		INSERT INTO @TAB_KBK
		SELECT LINK_AP, AP_CODE
		FROM dbo.BK_GetTableDictionByAP ('KBK')

	--- ОТБОР ПО КОСГУ --- 
	DECLARE @TAB_KOSGU TABLE (LINK INT, CODE VARCHAR (20))
	IF LEN (@cVal_KOSGU) > 0
		INSERT INTO @TAB_KOSGU
		SELECT AP.LINK,
			AP.CODE
		FROM dbo.KOSGU AP 
		INNER JOIN dbo.OBJECT_VAR_KOSGU OVR ON (OVR.RECORD = AP.LINK)
		WHERE OVR.LINK_UP = @nOtborLinkKOSGU
	ELSE
		INSERT INTO @TAB_KOSGU
		SELECT LINK_AP, AP_CODE
		FROM dbo.BK_GetTableDictionByAP ('SGU')

	--- ОТБОР ПО КАУ --- 
	DECLARE @T_KAU TABLE (LINK INT)
	IF LEN (@cVal_KAU) > 0
		INSERT INTO @T_KAU
		SELECT
			OVR.RECORD 
		FROM dbo.OBJECT_VAR_KAU OVR
		WHERE OVR.LINK_UP = @nOtborKAU
	ELSE
		SET @nOtborKAU = 0

	-- BEGIN YEAR --
	DECLARE @SALDO_BEGIN_YEAR TABLE
		(
		ACCOUNT [INT],
		SGU [INT],
		KBK [INT],
		KAU	INT,
		JO [INT],
		D_SUMMA [NUMERIC] (28,2),
		K_SUMMA [NUMERIC] (28,2)
		)

	INSERT INTO @SALDO_BEGIN_YEAR
	SELECT
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		NULL,
		ISNULL (SA.JO, 0),
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM dbo.BB_RestSaldoForLedgerByDate1 (@DATE_BEG_YEAR, DEFAULT, 1) SBY
	INNER JOIN @TAB_ACCT SA ON (SBY.ACCOUNT = SA.ACCOUNT)
	INNER JOIN @TAB_KBK AP ON (AP.LINK_KBK = ISNULL (SBY.KBK, 0))
	INNER JOIN @TAB_KOSGU KOSGU ON (KOSGU.LINK = ISNULL (SBY.SGU, 0))
	WHERE (@intSVOD_ZB = 1
				AND SBY.DEP_LINK IN (SELECT LINK FROM dbo.DEPARTMENTS WHERE ZB = 1 OR [TYPE] = 4)
			OR @intSVOD_ZB = 0 AND SBY.DEP_LINK = @intDEP_LINK)
		AND (@nOtborKAU = 0
			OR @nOtborKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = SBY.KAU)
			)	
	GROUP BY
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		ISNULL (SA.JO, 0)

--select * from @SALDO_BEGIN_YEAR
--select * from @TAB_ACCT
	-- BEGIN PERIOD --
	DECLARE @SALDO_BEGIN_PERIOD TABLE
		(
		ACCOUNT [INT],
		SGU [INT],
		KBK [INT],
		KAU	INT,
		JO [INT],
		D_SUMMA [NUMERIC] (28,2),
		K_SUMMA [NUMERIC] (28,2)
		)

	INSERT INTO @SALDO_BEGIN_PERIOD
	SELECT
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		NULL,
		ISNULL (SA.JO, 0),
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM dbo.BB_RestSaldoForLedgerByDate1(@DATE_START, DEFAULT, 1) SB
	INNER JOIN @TAB_ACCT SA ON (SB.ACCOUNT = SA.ACCOUNT)
	INNER JOIN @TAB_KBK AP ON (AP.LINK_KBK = ISNULL (SB.KBK, 0))
	INNER JOIN @TAB_KOSGU KOSGU ON (KOSGU.LINK = ISNULL (SB.SGU, 0))
	WHERE (@intSVOD_ZB = 1
				AND SB.DEP_LINK IN (SELECT LINK FROM dbo.DEPARTMENTS WHERE ZB = 1 OR [TYPE] = 4)
			OR @intSVOD_ZB = 0 AND SB.DEP_LINK = @intDEP_LINK)
		AND (@nOtborKAU = 0
			OR @nOtborKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = SB.KAU)
			)	
	GROUP BY
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		ISNULL (SA.JO, 0)
		
--SELECT * FROM @SALDO_BEGIN_PERIOD

	-- END PERIOD --
	SET @OUT_DATE_REST = DATEADD (DAY, 1, @DATE_STOP)

	DECLARE @SALDO_END_PERIOD TABLE
		(
		ACCOUNT [INT],
		SGU [INT],
		KBK [INT],
		KAU	INT,
		JO [INT],
		D_SUMMA [NUMERIC] (28,2),
		K_SUMMA [NUMERIC] (28,2)
		)

	INSERT INTO @SALDO_END_PERIOD
	SELECT
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		NULL,
		ISNULL (SA.JO, 0),
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM dbo.BB_RestSaldoForLedgerByDate1(@OUT_DATE_REST, DEFAULT, 1) SE
	INNER JOIN @TAB_ACCT SA ON (SE.ACCOUNT = SA.ACCOUNT)
	INNER JOIN @TAB_KBK AP ON (AP.LINK_KBK = ISNULL (SE.KBK, 0))
	INNER JOIN @TAB_KOSGU KOSGU ON (KOSGU.LINK = ISNULL (SE.SGU, 0))
	WHERE (@intSVOD_ZB = 1
				AND SE.DEP_LINK IN (SELECT LINK FROM dbo.DEPARTMENTS WHERE ZB = 1 OR [TYPE] = 4)
			OR @intSVOD_ZB = 0 AND SE.DEP_LINK = @intDEP_LINK)
		AND (@nOtborKAU = 0
			OR @nOtborKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = SE.KAU)
			)	
	GROUP BY
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		ISNULL (SA.JO, 0)

--select * from @SALDO_END_PERIOD

	-- OBOROTS BY PERIOD --
	DECLARE @OBOROT_PERIOD TABLE
		(
 		ACCOUNT [INT],
		SGU [INT],
		KBK [INT],
		KAU	INT,
		LEDGER_JOURNAL [INT],
		D_SUMMA [NUMERIC] (28,2),
		K_SUMMA [NUMERIC] (28,2)
		)

	INSERT INTO @OBOROT_PERIOD
	SELECT
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (OB.SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (OB.KBK, 0)
			ELSE 0
		END,
		NULL,
		ISNULL (LEDGER_JOURNAL, 0),
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM dbo.BB_RestOborotForLedgerByPeriod1(@DATE_START, @DATE_STOP, 1) OB
	INNER JOIN @TAB_ACCT SA ON (OB.ACCOUNT = SA.ACCOUNT)
	INNER JOIN @TAB_KBK AP ON (AP.LINK_KBK = ISNULL (OB.KBK, 0))
	INNER JOIN @TAB_KOSGU KOSGU ON (KOSGU.LINK = ISNULL (OB.SGU, 0))
	WHERE (@intSVOD_ZB = 1
				AND OB.DEP_LINK IN (SELECT LINK FROM dbo.DEPARTMENTS WHERE ZB = 1 OR [TYPE] = 4)
			OR @intSVOD_ZB = 0 AND OB.DEP_LINK = @intDEP_LINK)
		AND (@nOtborKAU = 0
			OR @nOtborKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = OB.KAU)
			)	
	GROUP BY
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		ISNULL (LEDGER_JOURNAL, 0)
--select * from @OBOROT_PERIOD

	-- ОБОРОТЫ С НАЧАЛА ГОДА -- 
	DECLARE @OBOROT_YEAR TABLE
		(
		ACCOUNT [INT],
		SGU [INT],
		KBK [INT],
		KAU	INT,
		LEDGER_JOURNAL [INT],
		D_SUMMA [NUMERIC] (28,2),
		K_SUMMA [NUMERIC] (28,2)
		)

	INSERT INTO @OBOROT_YEAR
	SELECT
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (OB.SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (OB.KBK, 0)
			ELSE 0
		END, 
		NULL,
		ISNULL (LEDGER_JOURNAL, 0),
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM dbo.BB_RestOborotForLedgerByPeriod1(@DATE_BEG_YEAR, @DATE_STOP, 1) OB
	INNER JOIN @TAB_ACCT SA ON (OB.ACCOUNT = SA.ACCOUNT)
	INNER JOIN @TAB_KBK AP ON (AP.LINK_KBK = ISNULL (OB.KBK, 0))
	INNER JOIN @TAB_KOSGU KOSGU ON (KOSGU.LINK = ISNULL (OB.SGU, 0))
	WHERE (@intSVOD_ZB = 1
				AND OB.DEP_LINK IN (SELECT LINK FROM dbo.DEPARTMENTS WHERE ZB = 1 OR [TYPE] = 4)
			OR @intSVOD_ZB = 0 AND OB.DEP_LINK = @intDEP_LINK)
		AND (@nOtborKAU = 0
			OR @nOtborKAU > 0 AND EXISTS (SELECT * FROM @T_KAU TTT WHERE TTT.LINK = OB.KAU)
			)	
	GROUP BY
		SA.ACCT_ROOT,
		CASE 
			WHEN @intPRN_KOSGU = 1 THEN ISNULL (SGU, 0)
			ELSE 0
		END, 
		CASE 
			WHEN @intPRN_KBK = 1 THEN ISNULL (KBK, 0)
			ELSE 0
		END,
		ISNULL (LEDGER_JOURNAL, 0)

	--select * from @OBOROT_YEAR

	DECLARE @ACCOUNT_BOOK TABLE
		(
		ACCOUNT [INT],
		KBK [INT],
		SGU [INT],
		LEDGER_JO [INT])

	INSERT INTO @ACCOUNT_BOOK
	SELECT ACCOUNT, KBK, SGU, JO
	FROM @SALDO_BEGIN_YEAR
	WHERE D_SUMMA <> 0 OR K_SUMMA <> 0 
	UNION
	SELECT ACCOUNT, KBK, SGU, JO
	FROM @SALDO_BEGIN_PERIOD
	WHERE D_SUMMA <> 0 OR K_SUMMA <> 0 
	UNION
	SELECT ACCOUNT, KBK, SGU, LEDGER_JOURNAL
	FROM @OBOROT_PERIOD
	WHERE D_SUMMA <> 0 OR K_SUMMA <> 0 
	UNION
	SELECT ACCOUNT, KBK, SGU, JO
	FROM @SALDO_END_PERIOD
	WHERE D_SUMMA <> 0 OR K_SUMMA <> 0 
	UNION
	SELECT ACCOUNT, KBK, SGU, LEDGER_JOURNAL
	FROM @OBOROT_YEAR
	WHERE D_SUMMA <> 0 OR K_SUMMA <> 0 
--select * from @ACCOUNT_BOOK

	/* --- Итоговые остатки по группе --- */
	/* НАЧАЛО ГОДА */
	DECLARE @SALDO_BEGIN_YEAR_GR TABLE (ACCOUNT [INT],
				D_SUMMA [NUMERIC] (28,2),
				K_SUMMA [NUMERIC] (28,2))

	INSERT INTO @SALDO_BEGIN_YEAR_GR	
	SELECT ACCOUNT,
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM @SALDO_BEGIN_YEAR
	GROUP BY ACCOUNT

	/* НАЧАЛО ПЕРИОДА */
	DECLARE @SALDO_BEGIN_PERIOD_GR TABLE (ACCOUNT [INT],
				D_SUMMA [NUMERIC] (28,2),
				K_SUMMA [NUMERIC] (28,2))

	INSERT INTO @SALDO_BEGIN_PERIOD_GR	
	SELECT ACCOUNT,
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM @SALDO_BEGIN_PERIOD
	GROUP BY ACCOUNT

	/* КОНЕЦ ПЕРИОДА */
	DECLARE @SALDO_END_PERIOD_GR TABLE (ACCOUNT [INT],
				D_SUMMA [NUMERIC] (28,2),
				K_SUMMA [NUMERIC] (28,2))

	INSERT INTO @SALDO_END_PERIOD_GR	
	SELECT ACCOUNT,
		SUM (D_SUMMA),
		SUM (K_SUMMA)
	FROM @SALDO_END_PERIOD
	GROUP BY ACCOUNT
/*
SELECT * FROM @SALDO_BEGIN_YEAR_GR
SELECT * FROM @SALDO_BEGIN_PERIOD_GR
SELECT * FROM @SALDO_END_PERIOD_GR
*/

--SELECT * FROM @ACCOUNT_BOOK

	DECLARE @MAIN_BOOK TABLE (
		[MONTH]	VARCHAR(20),
		ORGNAME	VARCHAR(254),
		OKPO	VARCHAR (20),
		GLBUH	VARCHAR (50),
		UCHR_NAME VARCHAR (254),
		BUDG_NAME VARCHAR (254),
		ACCT_GR	VARCHAR (5),
		ZABALANS TINYINT,
		AC_CODE VARCHAR (20),
		CODE_LONG VARCHAR (60),
		KBK_CODE VARCHAR (20),
		SGU_CODE VARCHAR (3),
		JO_CODE VARCHAR (10),
		BEG_YEAR VARCHAR (10),
		SBYD_SUMMA NUMERIC (28,4),
		SBYK_SUMMA NUMERIC (28,4),
		SBD_SUMMA NUMERIC (28,4),
		SBK_SUMMA NUMERIC (28,4),
		OBD_SUMMA NUMERIC (28,4),
		OBK_SUMMA NUMERIC (28,4),

		YOD_SUM NUMERIC (28,4),
		YOK_SUM NUMERIC (28,4),

		SED_SUMMA NUMERIC (28,4),
		SEK_SUMMA NUMERIC (28,4),

		SBYD_SUM_G NUMERIC (28,4),
		SBYK_SUM_G NUMERIC (28,4),
		SBD_SUM_G NUMERIC (28,4),
		SBK_SUM_G NUMERIC (28,4),
		SED_SUM_G NUMERIC (28,4),
		SEK_SUM_G NUMERIC (28,4),

		[SBYD_SUM_T] NUMERIC (28,4),
		[SBYK_SUM_T] NUMERIC (28,4),
		[SBD_SUM_T] NUMERIC (28,4),
		[SBK_SUM_T] NUMERIC (28,4),
		[SED_SUM_T] NUMERIC (28,4),
		[SEK_SUM_T] NUMERIC (28,4),

		ACSGU_GR1	VARCHAR (30),
		ACSGU_GR2	VARCHAR (30)
		)

--	ORDER BY 1, 2, 3, 4, 5
-- 	MONTH, ORGNAME, ACCT_GR, AC_CODE,

		
	INSERT INTO @MAIN_BOOK
	SELECT @MONTH_NAME AS MONTH,
		@strORGNAME AS ORGNAME,
		@strOKPO AS OKPO,
		@strGLBUH AS GLBUH,
		@UCHR_NAME,
		@BUDG_NAME,
		SA.cSINTH AS ACCT_GR,
		SA.ZABALANS,
		SA.CODE AS AC_CODE,

		dbo.BK_GetAcctFullCode1 (AC.ACCOUNT, AC.KBK, AC.SGU, @intPRN_KBK, @intPRN_KOSGU) AS CODE_LONG,
		ISNULL (KL_KBK.CODE, ''),
		ISNULL (KOSGU.CODE, ''),
		ISNULL (CONVERT (VARCHAR (10), JO.CODE), '') AS JO_CODE,
		CONVERT (VARCHAR (10), @DATE_BEG_YEAR, 104) AS BEG_YEAR,
		ISNULL (REST_BY.D_SUMMA, 0) AS SBYD_SUMMA ,
		ISNULL (REST_BY.K_SUMMA, 0) AS SBYK_SUMMA,
		ISNULL (REST_BP.D_SUMMA, 0) AS SBD_SUMMA,
		ISNULL (REST_BP.K_SUMMA , 0) AS SBK_SUMMA,
		ISNULL (OB.D_SUMMA, 0) AS OBD_SUMMA,
		ISNULL (OB.K_SUMMA, 0) AS OBK_SUMMA,

		ISNULL (OBY.D_SUMMA, 0) AS YOD_SUM,
		ISNULL (OBY.K_SUMMA, 0) AS YOK_SUM,

		ISNULL (REST_EP.D_SUMMA, 0) AS SED_SUMMA ,
		ISNULL (REST_EP.K_SUMMA, 0) AS SEK_SUMMA,

		ISNULL (REST_BY_GR.D_SUMMA, 0) AS SBYD_SUM_G ,
		ISNULL (REST_BY_GR.K_SUMMA, 0) AS SBYK_SUM_G,
		ISNULL (REST_BP_GR.D_SUMMA, 0) AS SBD_SUM_G,
		ISNULL (REST_BP_GR.K_SUMMA , 0) AS SBK_SUM_G,
		ISNULL (REST_EP_GR.D_SUMMA, 0) AS SED_SUM_G,
		ISNULL (REST_EP_GR.K_SUMMA, 0) AS SEK_SUM_G,

		[SBYD_SUM_T] = ISNULL ((SELECT SUM (D_SUMMA) FROM @SALDO_BEGIN_YEAR_GR), 0),
		[SBYK_SUM_T] = ISNULL ((SELECT SUM (K_SUMMA) FROM @SALDO_BEGIN_YEAR_GR), 0),
		[SBD_SUM_T] = ISNULL ((SELECT SUM (D_SUMMA) FROM @SALDO_BEGIN_PERIOD_GR), 0),
		[SBK_SUM_T] = ISNULL ((SELECT SUM (K_SUMMA) FROM @SALDO_BEGIN_PERIOD_GR), 0),
		[SED_SUM_T] = ISNULL ((SELECT SUM (D_SUMMA) FROM @SALDO_END_PERIOD_GR), 0),
		[SEK_SUM_T] = ISNULL ((SELECT SUM (K_SUMMA) FROM @SALDO_END_PERIOD_GR), 0),

		CASE
--			WHEN @intGRP_SGU = 1 AND SA.P_KASSA = 1 AND KOSGU.IS_EKR = 1 THEN RTRIM (SA.CODE) + '.' + LEFT (KOSGU.CODE, 2) + '0'
--			WHEN @intGRP_SGU = 1 AND SA.P_KASSA = 1 THEN RTRIM (SA.CODE) + '.' + ISNULL (LEFT (KOSGU.CODE, 2) + '0', '000')
			WHEN @intGRP_SGU = 1 THEN RTRIM (SA.CODE) + '.' + ISNULL (LEFT (KOSGU.CODE, 2) + '0', '000')
			ELSE ''
		END, 
		CASE
--			WHEN @intGRP_SGU = 1 AND SA.P_KASSA = 1 AND KOSGU.IS_EKR = 1 THEN RTRIM (SA.CODE) + '.' + LEFT (KOSGU.CODE, 1) + '00'
--			WHEN @intGRP_SGU = 1 AND SA.P_KASSA = 1 THEN RTRIM (SA.CODE) + '.' + ISNULL (LEFT (KOSGU.CODE, 1) + '00', '000')
			WHEN @intGRP_SGU = 1 THEN RTRIM (SA.CODE) + '.' + ISNULL (LEFT (KOSGU.CODE, 1) + '00', '000')
			ELSE ''
		END
	FROM @ACCOUNT_BOOK AC
	LEFT OUTER JOIN @SALDO_BEGIN_YEAR REST_BY ON (REST_BY.ACCOUNT = AC.ACCOUNT
			AND REST_BY.KBK = AC.KBK
			AND REST_BY.SGU = AC.SGU
			AND REST_BY.JO = AC.LEDGER_JO)
	LEFT OUTER JOIN @SALDO_BEGIN_PERIOD REST_BP ON (REST_BP.ACCOUNT = AC.ACCOUNT
			AND REST_BP.KBK = AC.KBK
			AND REST_BP.SGU = AC.SGU
			AND REST_BP.JO = AC.LEDGER_JO)
	LEFT OUTER JOIN @OBOROT_PERIOD OB ON (OB.ACCOUNT = AC.ACCOUNT
			AND OB.KBK = AC.KBK
			AND OB.SGU = AC.SGU
			AND OB.LEDGER_JOURNAL = AC.LEDGER_JO)
	LEFT OUTER JOIN @SALDO_END_PERIOD REST_EP ON (REST_EP.ACCOUNT = AC.ACCOUNT
			AND REST_EP.KBK = AC.KBK
			AND REST_EP.SGU = AC.SGU
			AND REST_EP.JO = AC.LEDGER_JO)
	LEFT OUTER JOIN @OBOROT_YEAR OBY ON (OBY.ACCOUNT = AC.ACCOUNT
			AND OBY.KBK = AC.KBK
			AND OBY.SGU = AC.SGU
			AND OBY.LEDGER_JOURNAL = AC.LEDGER_JO)
	LEFT OUTER JOIN @SALDO_BEGIN_YEAR_GR REST_BY_GR ON (REST_BY_GR.ACCOUNT = AC.ACCOUNT)
	LEFT OUTER JOIN @SALDO_BEGIN_PERIOD_GR REST_BP_GR ON (REST_BP_GR.ACCOUNT = AC.ACCOUNT)
	LEFT OUTER JOIN @SALDO_END_PERIOD_GR REST_EP_GR ON (REST_EP_GR.ACCOUNT = AC.ACCOUNT)

	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = AC.ACCOUNT
	LEFT JOIN dbo.KL_KBK ON KL_KBK.LINK=AC.KBK

	LEFT JOIN dbo.KOSGU ON KOSGU.LINK=AC.SGU
	LEFT JOIN dbo.JOURNAL_OPERATION JO ON JO.LINK=AC.LEDGER_JO
--	ORDER BY 1, 2, 3, 4, 5


	IF @intACCT_GR = 1
		IF @intGRP_SGU = 1
			SELECT *
			FROM @MAIN_BOOK ORDER BY ORGNAME, [MONTH], ZABALANS, ACCT_GR, AC_CODE, SGU_CODE, KBK_CODE
		ELSE
			SELECT *
			FROM @MAIN_BOOK ORDER BY ORGNAME, [MONTH], ZABALANS, ACCT_GR, AC_CODE, KBK_CODE, SGU_CODE
	ELSE
		IF @intGRP_SGU = 1
			SELECT *
			FROM @MAIN_BOOK ORDER BY ORGNAME, [MONTH], ZABALANS, AC_CODE, SGU_CODE, KBK_CODE
		ELSE
			SELECT *
			FROM @MAIN_BOOK ORDER BY ORGNAME, [MONTH], ZABALANS, AC_CODE, KBK_CODE, SGU_CODE

-- EXECUTE KIR_EXEC_QUERY 40039,'''20060101'',''20081231'',0,1,0,0,1,1,0,0,1,40905'
/*
SELECT *,
	CONVERT (VARCHAR (26), REPLACE (CODE_LONG, '.', '')) AS SCHET,
	CONVERT (NUMERIC (15), SBYD_SUMMA * 100) AS OST_NG_D,
	CONVERT (NUMERIC (15), SBYK_SUMMA * 100) AS OST_NG_K,
	CONVERT (NUMERIC (15), SBD_SUMMA * 100) AS OST_NM_D,
	CONVERT (NUMERIC (15), SBK_SUMMA * 100) AS OST_NM_K
FROM @MAIN_BOOK ORDER BY ORGNAME, [MONTH], ZABALANS, AC_CODE, KBK_CODE, SGU_CODE
*/
END




GO


GRANT EXECUTE ON dbo.[BK_REPORT_BOOK_MAIN] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BA_SAVE_G_PROV2_CHARGE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BA_SAVE_G_PROV2_CHARGE]

GO


/*******************************************************************************

   © Кейсистемс (Keysystems), 2006

*******************************************************************************/
-- Процедура сохранения проводок операции.
CREATE  PROCEDURE dbo.[BA_SAVE_G_PROV2_CHARGE]
	@iLINK_G_PROV  INT,                  -- Ссылка на ДОКУМЕНТ (G_PROV).
	@iLINK_G_PROV1 INT,                  -- Ссылка на ОПЕРАЦИЮ (G_PROV1).
	@dDATE         DATETIME      = NULL, -- Дата проводки документа.
	@iLINK_OPER    INT			  = NULL, -- Ссылка на ТИПОВУЮ ОПЕРАЦИЮ (G_PROV1).
	@iNOMEN_LINK   INT			  = NULL, -- Ссылка на НОМЕНКЛАТУРУ (NOMENCLATURE) |  
	@iINV_LINK     INT			  = NULL, -- Ссылка на ИНВЕНТАРЬ (INVENTORY)       | Д.б. заполнен только один параметр.
	@iTMC_LINK     INT			  = NULL, -- Ссылка на ТМЦ (DICTION)               | 
	@iDEP_LINK_KT  INT           = NULL, -- Ссылка на организацию (DEPARTMENTS) 
	@nQTY          NUMERIC(19,4) = NULL, -- Количество.
	@iMOL_LINK_KT  INT  = NULL,  -- Ссылка на МОЛ (EMPL).
	@nPRICE_FACT	NUMERIC (19,6) = 0,
	@nSUMMA	NUMERIC(19,4) = 0,
	@intACCOUNT	INT = NULL

AS
                                 -- Дебетовые аналитические признаки:
DECLARE @liSGU_DT     INT,       -- ссылка на код сектора государственного управления (KOSGU);
	     @liKBK_DT     INT,       -- ссылка на код бюджетной классификации (KL_KBK);
	     @liEKR_DT     INT,       -- экономическая классификация расходов;
	     @liDEP_DT     INT,       -- ссылка на организацию (DEPARTMENTS);
	     @liSUB_DT     INT,       -- ссылка на подразделение организации (SUBDIV);
	     @liEMP_DT     INT,       -- ссылка на сотрудника (EMPL);
	     @liNOMEN_DT   INT,       -- ссылка на номенклатуру (NOMENCLATURE);
	     @liINV_DT     INT,       -- ссылка на инвентарь (INVENTORY);
	     @liKAU_DT     INT,       -- ссылка на код аналитического учета (DICTION);
	     @liDEP_ACC_DT INT,       -- ссылка на дебетовый счет (S_ACCOUNTS);
	     @liTMC_DT     INT,       -- ссылка на товарно-материальную ценность (DICTION);
	     @ldINDATE_DT  DATETIME,  -- аналитический признак "Дата";
	     @liAP1_DT     INT,       -- ссылка на документ-основание (OSNOV);
	     @liAP2_DT     INT,       -- произвольный аналитический признак 2;
	     @liAP3_DT     INT,       -- произвольный аналитический признак 3.

                                 -- Кредитовые аналитические признаки:
        @liSGU_KT     INT,       -- ссылка на код сектора государственного управления (KOSGU);
	     @liKBK_KT     INT,       -- ссылка на код бюджетной классификации (KL_KBK);
	     @liEKR_KT     INT,       -- экономическая классификация расходов;
	     @liDEP_KT     INT,       -- ссылка на организацию (DEPARTMENTS);
	     @liSUB_KT     INT,       -- ссылка на подразделение организации (SUBDIV);
	     @liEMP_KT     INT,       -- ссылка на сотрудника (EMPL);
	     @liNOMEN_KT   INT,       -- ссылка на номенклатуру (NOMENCLATURE);
	     @liINV_KT     INT,       -- ссылка на инвентарь (INVENTORY);
	     @liKAU_KT     INT,       -- ссылка на код аналитического учета (DICTION);
	     @liDEP_ACC_KT INT,       -- ссылка на кредитовый счет (S_ACCOUNTS);
	     @liTMC_KT     INT,       -- ссылка на товарно-материальную ценность (DICTION);
	     @ldINDATE_KT  DATETIME,  -- аналитический признак "Дата";
	     @liAP1_KT     INT,       -- ссылка на документ-основание (OSNOV);
	     @liAP2_KT     INT,       -- произвольный аналитический признак 2;
	     @liAP3_KT     INT,       -- произвольный аналитический признак 3.
      
        @lnSumma         NUMERIC(19,2), -- Сумма проводки.
        @lnQTY           NUMERIC(19,4), -- Количество в текущей проводке.
        @liGP2_LINK      INT,           -- Ссылка на проводку (G_PROV2).
        @lvcGP2_NAME     VARCHAR(254),  -- Заголовок проводки.
        @liGP2_ECON_OPER INT,           
        @liGP2_ORDERS    INT,

        @liACCOUNT_DT    INT,
        @liACCOUNT_KT    INT,
        @liLINK_GP2 INT,

        @liRowCount      INT, -- Число обработанных строк.
        @liReturn        INT, -- Возвращаемый код ошибки.
        @liMOL_LINK_KT   INT,
	@REAL_PRICE_FACT NUMERIC (28,6),
	@PRICE_TYPE TINYINT


-- Проводки в переданной типовой операции.
DECLARE curG_PROV2_TYPICAL_OPER CURSOR LOCAL STATIC READ_ONLY FOR
   SELECT [LINK], 
          [NAME], 
          [ECON_OPER], 
          [ORDERS] 
   FROM dbo.[G_PROV2]
   WHERE [LINK_UP] = @iLINK_OPER


SET IMPLICIT_TRANSACTIONS OFF  -- Режим явного определения транзакций.
SET LOCK_TIMEOUT 3000          -- Время ожидания разблокировки ресурсов 3 сек.
PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Вход.'

IF @iLINK_G_PROV1 IS NULL 
BEGIN
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Не задана ccылка на операцию.'
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки -1.'
   RETURN -1
END

IF ISNULL(@iNOMEN_LINK - @iNOMEN_LINK + 1,0) +
   ISNULL(@iINV_LINK - @iINV_LINK + 1,0) +
   ISNULL(@iTMC_LINK - @iTMC_LINK + 1,0) <> 1
BEGIN
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Ccылка на МЦ (номенклатуру, инвентарь или ТМЦ) задана неправильно.'
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки -2.'
	RETURN -2 -- Возврат кода ошибки.
END

IF @nQTY IS NULL OR @nQTY <=0
BEGIN
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Количество не определено или <= 0'
   PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки -3.'
	RETURN -3 -- Возврат кода ошибки.
END

BEGIN TRANSACTION -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.
 
   -- Установка даты по умолчанию, если она не задана.
   IF @dDATE IS NULL
   BEGIN
   	SELECT @dDATE = [WORKDATE] + 1
      FROM dbo.[USER_INFO]
   END
   
   -- Извлечение параметров ТИПОВОЙ ОПЕРАЦИИ.
   OPEN curG_PROV2_TYPICAL_OPER
   
   FETCH NEXT 
   FROM curG_PROV2_TYPICAL_OPER 
   INTO @liGP2_LINK, 
        @lvcGP2_NAME, 
        @liGP2_ECON_OPER, 
        @liGP2_ORDERS
   
   WHILE @@FETCH_STATUS = 0 -- Цикл по проводкам заданной типовой оперции...
   BEGIN 

      SET @liMOL_LINK_KT = ISNULL(@iMOL_LINK_KT,0) -- Для "жесткого" фильтра по МОЛ.


-- EXEC xa_watchi '@iNOMEN_LINK',@iNOMEN_LINK

/*
EXEC xa_watchi '@iLINK_G_PROV',@iLINK_G_PROV
EXEC xa_watchi '@liGP2_LINK',@liGP2_LINK
EXEC xa_watchi '@dDATE',@dDATE
EXEC xa_watchi '@iNOMEN_LINK',@iNOMEN_LINK
EXEC xa_watchi '@iINV_LINK',@iINV_LINK
EXEC xa_watchi '@iTMC_LINK',@iTMC_LINK
EXEC xa_watchi '@iMOL_LINK_KT',@iMOL_LINK_KT
EXEC xa_watchi '@iDEP_LINK_KT',@iDEP_LINK_KT


      SELECT *
      FROM dbo.[BA_SELECT_AP](0x31, -- 1. Корректировка аналитических частей счетов.
                                    -- 2. Выборка аналитических признаков из остатков.
                              19294,
                              18067,
                              '20061010',
                              NULL,
                              0xFFBFF,
                              61,
                           	null,
                           	null,
                              null,
                              75514)


--EXEC xa_watchs
*/



      -- Выборка аналитических признаков у проводки ТИПОВОЙ ОПЕРАЦИИ.
      SELECT *
      INTO #REST
      FROM dbo.[BA_SELECT_AP](0xF1, -- 1. Корректировка синтетических и аналитических частей счетов.
                                     -- 2. Выборка аналитических признаков из остатков.
                                     -- 3. Корректировка INV, NOMEN и TMC дебетового счета.
                              @iLINK_G_PROV,
                              @liGP2_LINK,
                              @dDATE,
                              @intACCOUNT,
                              0xFFBFF,
                              @iNOMEN_LINK,
                           	@iINV_LINK,
                           	@iTMC_LINK,
                              @liMOL_LINK_KT,
                              @iDEP_LINK_KT,
				@nPRICE_FACT)

      SELECT @liACCOUNT_DT = [ACCOUNT],
             @liSGU_DT     = [SGU],
             @liEMP_DT     = [EMP],
             @liNOMEN_DT   = [NOMEN], 
	          @liINV_DT     = [INV],
             @liTMC_DT     = [TMC],   
             @liKBK_DT     = [KBK],
             @liEKR_DT     = [EKR],
             @liDEP_DT     = [DEP],
             @liSUB_DT     = [SUB],
             @liKAU_DT     = [KAU],
             @liDEP_ACC_DT = [DEP_ACC],
             @ldINDATE_DT  = [INDATE],
             @liAP1_DT     = [AP1],
             @liAP2_DT     = [AP2],
             @liAP3_DT     = [AP3]
      FROM #REST
      WHERE [DB_KR] = 0
      
      SELECT @liACCOUNT_KT = ISNULL([ACCOUNT_REST],[ACCOUNT]),
             @liSGU_KT     = [SGU],
             @liEMP_KT     = [EMP],
             @liNOMEN_KT   = [NOMEN],
	          @liINV_KT     = [INV],
             @liTMC_KT     = [TMC],   
             @liKBK_KT     = [KBK],
             @liEKR_KT     = [EKR],
             @liDEP_KT     = [DEP],
             @liSUB_KT     = [SUB],
             @liKAU_KT     = [KAU],
             @liDEP_ACC_KT = [DEP_ACC],
             @ldINDATE_KT  = [INDATE],
             @liAP1_KT     = [AP1],
             @liAP2_KT     = [AP2],
             @liAP3_KT     = [AP3],
		@REAL_PRICE_FACT = PRICE_FACT,
		@PRICE_TYPE = PRICE_TYPE
      FROM #REST
      WHERE [DB_KR] = 1

/*
      EXEC xa_watchi '@liACCOUNT_KT',@liACCOUNT_KT
      EXEC xa_watchi '@liACCOUNT_DT',@liACCOUNT_DT
--      EXEC xa_watchs
   SELECT code FROM s_accounts WHERE link=1284--1193
*/

      -- Определение суммы проводки.
	IF ISNULL (@nSUMMA, 0) = 0
		IF ISNULL (@PRICE_TYPE, 0) = 1 AND @REAL_PRICE_FACT <> 0
			SELECT @lnSumma = @REAL_PRICE_FACT * @nQTY
		ELSE
		      SELECT TOP 1 @lnSumma = CASE [D_QUANTITY]
		                                  WHEN 0 THEN 0
		                                  ELSE ([D_SUMMA] / [D_QUANTITY])*@nQTY
		                              END
	 		FROM #REST
	ELSE
		SET @lnSumma = @nSUMMA 

   	IF @lnSumma = 0 
      BEGIN
   	   FETCH NEXT 
         FROM curG_PROV2_TYPICAL_OPER 
         INTO @liGP2_LINK, 
              @lvcGP2_NAME, 
              @liGP2_ECON_OPER, 
              @liGP2_ORDERS
   	
       	DROP TABLE #REST
   
   		CONTINUE
      END 

      -- Корректировка кодов СГУ дебетовой и кредитовой частей.
      EXEC dbo.[BA_CORRECT_SGU] @liSGU_DT OUTPUT,
                                @liACCOUNT_DT,
                                0
      EXEC dbo.[BA_CORRECT_SGU] @liSGU_KT OUTPUT,
                                @liACCOUNT_KT,
                                1
   
      -- Обнуление количества, если количественно-сумовой учет не ведется.
   	IF NOT EXISTS(SELECT * 
                    FROM dbo.[S_ACCOUNTS]
                    WHERE [LINK] IN (@liACCOUNT_DT, 
                                     @liACCOUNT_KT) AND 
                          [KSU] = 1)
      BEGIN
         SET @lnQTY = @nQTY
      END
      ELSE
      BEGIN
         SET @lnQTY = @nQTY
      END

      -- Определение имени проводки.
      SELECT @liLINK_GP2      = NULL,
             @lvcGP2_NAME = dbo.[BA_GET_G_PROV2_NAME](@lvcGP2_NAME,
                                                      NULL,
                                                      @iNOMEN_LINK,
                                                      NULL,
                                                      NULL)

      -- Создание проводки.   
   	EXEC @liReturn = dbo.[XA_UPDATE_G_PROV2] @liLINK_GP2 OUTPUT, 
                                               @iLINK_G_PROV1, 
                                               NULL,
         		                                @lnSumma, 
                                               @lnQTY, 
                                               0, 
                                               @lvcGP2_NAME, 
                                               @liGP2_ECON_OPER,  
        @liGP2_ORDERS
   

   	IF @liReturn <> 0 OR 
         @liLINK_GP2 IS NULL
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки XA_UPDATE_G_PROV2 - 10.'
   		RETURN @liReturn - 10 -- Возврат кода ошибки -1X.
   	END

      -- Приведение источника финансирования дебетового счета к кредитовому.
      EXEC @liReturn = dbo.[BA_CORRECT_ACCOUNT_SOURCE] @liACCOUNT_DT OUTPUT, 
                                                       @liACCOUNT_KT 

      IF @liReturn < 0
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки BA_CORRECT_ACCOUNT_SOURCE - 20.'
			RETURN @liReturn - 20 -- Возврат кода ошибки -2X.
   	END
      
      -- Корректировка пользовательского субсчета дебетового и кредитового счетов (если необходимо).
      EXEC @liReturn = dbo.[BA_CORRECT_ACCOUNT_USER] @liACCOUNT_DT OUTPUT

      IF @liReturn < 0
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки BA_CORRECT_ACCOUNT_USER - 50.'
			RETURN @liReturn - 50 -- Возврат кода ошибки -5X.
   	END

      EXEC @liReturn = dbo.[BA_CORRECT_ACCOUNT_USER] @liACCOUNT_KT OUTPUT

      IF @liReturn < 0
      BEGIN
   		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
         COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
         PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки BA_CORRECT_ACCOUNT_USER - 60.'
			RETURN @liReturn - 60 -- Возврат кода ошибки -6X.
   	END

   	IF @liACCOUNT_DT > 0
      BEGIN
		SELECT @liEKR_DT = ANALIT_EKR FROM S_ACCOUNTS WHERE LINK = @liACCOUNT_DT AND p_EKR = 1
   		IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE LINK = @liACCOUNT_DT AND p_KASSA = 1) AND @liSGU_DT IS NOT NULL AND @liSGU_DT > 0
	            SET @liEKR_DT = @liSGU_DT
		EXEC @liReturn = dbo.[XA_UPDATE_G_PROV_AP] @liLINK_GP2, 
                                                    0, 
                                                    @liACCOUNT_DT, 
                                                    @liKBK_DT, 
                                                    @liEKR_DT, 
                                                    @liDEP_DT,
                                                    @liSUB_DT, 
                                                    @liEMP_DT, 
                                                    @liNOMEN_DT, 
                                                    @liINV_DT,
                                                    @liKAU_DT, 
                                                    @liDEP_ACC_DT, 
                                                    @liTMC_DT,
                                                    @ldINDATE_DT, 
                                                    @liAP1_DT, 
                                                    @liAP2_DT, 
                                                    @liAP3_DT, 
                                                    @liSGU_DT

         IF @liReturn <> 0 
         BEGIN
         	ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
            COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
            PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки XA_UPDATE_G_PROV_AP - 30.'
         	RETURN @liReturn - 30 -- Возврат кода ошибки -3X.
         END
 
      END
   
   	IF @liACCOUNT_KT > 0
      BEGIN
		SELECT @liEKR_KT = ANALIT_EKR FROM S_ACCOUNTS WHERE LINK = @liACCOUNT_KT AND p_EKR = 1
		IF EXISTS(SELECT * FROM S_ACCOUNTS WHERE LINK = @liACCOUNT_KT AND p_KASSA = 1) AND @liSGU_KT IS NOT NULL AND @liSGU_KT > 0
	            SET @liEKR_KT = @liSGU_KT
   		EXEC @liReturn = dbo.[XA_UPDATE_G_PROV_AP] @liLINK_GP2, 
                                                    1,
                                                    @liACCOUNT_KT, 
                                                    @liKBK_KT, 
                                                    @liEKR_KT, 
                                                    @liDEP_KT,
               	                                  @liSUB_KT, 
                                                    @liEMP_KT, 
                                                    @liNOMEN_KT, 
                                                    @liINV_KT, 
                                                    @liKAU_KT, 
                                                    @liDEP_ACC_KT, 
                                                    @liTMC_KT,
                                                    @ldINDATE_KT, 
                                                    @liAP1_KT, 
                                                    @liAP2_KT, 
                                                    @liAP3_KT, 
                                                    @liSGU_KT
   		IF @liReturn <> 0
         BEGIN
      		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
            COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
            PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход. Код ошибки XA_UPDATE_G_PROV_AP - 40.'
   			RETURN @liReturn - 40 -- Возврат кода ошибки -4X.
      	END

      END
   
   	DROP TABLE #REST
   
   	FETCH NEXT FROM curG_PROV2_TYPICAL_OPER 
      INTO @liGP2_LINK, 
           @lvcGP2_NAME, 
           @liGP2_ECON_OPER, 
           @liGP2_ORDERS
   
   END
   
   CLOSE curG_PROV2_TYPICAL_OPER
   DEALLOCATE curG_PROV2_TYPICAL_OPER

COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не изменила.
PRINT 'Х.п. BA_SAVE_G_PROV2_CHARGE : Выход.'
RETURN 0 -- Ошибок нет.


GO


GRANT EXECUTE ON dbo.[BA_SAVE_G_PROV2_CHARGE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_SET_STATIC_NASTR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_SET_STATIC_NASTR]

GO

CREATE  PROCEDURE DBO.SA_SET_STATIC_NASTR @CODE VARCHAR(20)
AS
---ЗАРПЛАТА-КС: ОБНОВЛЕНИЕ СТАВОК
BEGIN

	DECLARE @TITLE VARCHAR(254)
	SET @TITLE = 'Установлены статические настройки Зарплата-КС'

	DECLARE	@TD_LINK INT

	DELETE FROM DBO.SAL_WORNINGS WHERE TASK = 'SALARY' AND SID = SUSER_SID()


	IF @CODE = '2013' BEGIN

		SET @TITLE = @TITLE + ' на 01 ЯНВАРЯ 2013г.'

		--Мин. размер пособия по уходу за 1 ребенком
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT1', 0, '2453.93'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 1 ребенком = 2453.93', '', 'SALARY'


		--Мин. размер пособия по уходу за 2 и более дет.          
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT2', 0, '4907.85'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 2 и более дет. = 4907.85', '', 'SALARY'


		--Макс. размер пособия по уходу за 1 ребенком                                                                                                              
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT3', 0, '15429.71'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс. размер пособия по уходу за 1 ребенком = 15429.71', '', 'SALARY'


		--Макс.  размер пособия по уходу за 2 и более дет.                                                                                                                                                                 
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT4', 0, '15429.71'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс.  размер пособия по уходу за 2 и более дет. = 15429.71', '', 'SALARY'


		----Предельный размер пособия по нетрудоспособности                                                                                                                                                                
		--EXEC dbo.X_SET_OPTION 'ARCHE_OPT1', 0, '42666.66'

		--INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		--SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности = 42666.66', '', 'SALARY'

		----Максимальный размер пособия по беременности и родам                                                                                                                                                             
		--EXEC dbo.X_SET_OPTION 'ARCHE_OPT6', 0, '42666.66'

		--INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		--SELECT @TITLE, 'Максимальный размер пособия по беременности и родам = 42666.66', '', 'SALARY'
		
		----Предельный размер пособия по нетрудоспособности в минувшем году                                                                                                                                                        
		--EXEC dbo.X_SET_OPTION 'ARCHE_OPT7', 0, '38583.33'

		--INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		--SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности в минувшем году = 38583.33', '', 'SALARY'

		----Максимальный размер пособия по беременности и родам в минувшем году                                                                                                                                                      
		--EXEC dbo.X_SET_OPTION 'ARCHE_OPT8', 0, '38583.33'

		--INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		--SELECT @TITLE, 'Максимальный размер пособия по беременности и родам в минувшем году = 38583.33', '', 'SALARY'		

		-- УДАЛЕНИЕ ВСЕХ ПРАЗДНИКОВ 
		DELETE	FROM HOLIDAYS

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРАЗДНИЧНЫХ ДНЕЙ
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL)
			SELECT	'1 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 1, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'2 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 2, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'3 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 3, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'4 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 4, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'5 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 5, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'6 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 6, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'7 ЯНВАРЯ (РОЖДЕСТВО ХРИСТОВО)', 7, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'8 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 8, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'23 ФЕВРАЛЯ (ДЕНЬ ЗАЩИТНИКА ОТЕЧЕСТВА)', 23, 2, @TD_LINK, 1
			UNION ALL
			SELECT	'8 МАРТА (МЕЖДУНАРОДНЫЙ ЖЕНСКИЙ ДЕНЬ)', 8, 3, @TD_LINK, 1
			UNION ALL
			SELECT	'1 МАЯ (ПРАЗДНИК ВЕСНЫ И ТРУДА)', 1, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'9 МАЯ (ДЕНЬ ПОБЕДЫ)', 9, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'12 ИЮНЯ (ДЕНЬ РОССИИ)', 12, 6, @TD_LINK, 1
			UNION ALL
			SELECT	'4 НОЯБРЯ (ДЕНЬ НАРОДНОГО ЕДИНСТВА)', 4, 11, @TD_LINK, 1

		SET @TITLE = 'Установлены праздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 1 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРЕДПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB = 'П')
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРЕДПРАЗДНИЧНЫХ ДНЕЙ ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'22 ФЕВРАЛЯ', 22, 2, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'7 МАРТА', 7, 3, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'30 АПРЕЛЯ', 30, 4, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'8 МАЯ', 8, 5, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'11 ИЮНЯ', 11, 6, @TD_LINK, 2, null, null
			UNION ALL
			SELECT	'31 ДЕКАБРЯ', 31, 12, @TD_LINK, 2, null, null
		SET @TITLE = 'Установлены предпраздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 2 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ ДОПОЛНИТЕЛЬНЫХ ДНЕЙ ОТДЫХА ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'2 МАЯ (перенос выходного с 5 января)', 2, 5, @TD_LINK, 3, 5, 1
			UNION ALL
			SELECT	'3 МАЯ (перенос выходного с 6 января)', 3, 5, @TD_LINK, 3, 6, 1			
			UNION ALL
			SELECT	'10 МАЯ (перенос выходного с 25 февраля)', 10, 5, @TD_LINK, 3, 25, 2			

		SET @TITLE = 'Установлены дополнительные дни отдыха (перенос выходных)'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 3 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА РАБОЧИЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB IN ('Я','Ф'))
		IF COALESCE(@TD_LINK,0) > 0
		BEGIN
			-- ДОБАВЛЕНИЕ ПЕРЕНЕСЁННЫХ РАБОЧИХ ДНЕЙ
			/*	INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'11 МАРТА (рабочий день за 9 марта)', 11, 3, @TD_LINK, 3, 9, 3

				INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'5 МАЯ (рабочий день за 7 мая)', 5, 5, @TD_LINK, 3, 7, 5
			*/
			/*перенесенных рабочих дней за 2013 год нет */
		
		
			SET @TITLE = 'Установлены переносы рабочих дней'

			INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
			SELECT @TITLE, 'перенесенных рабочих дней за 2013 год нет', '', 'SALARY'
		end
	END --IF @CODE = '2013' BEGIN	

	IF @CODE = '2014' BEGIN

		SET @TITLE = @TITLE + ' на 01 ЯНВАРЯ 2014г.'

		--Мин. размер пособия по уходу за 1 ребенком
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT1', 0, '2576.63'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 1 ребенком = 2576.63', '', 'SALARY'


		--Мин. размер пособия по уходу за 2 и более дет.          
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT2', 0, '5153.24'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 2 и более дет. = 5153.24', '', 'SALARY'


		--Макс. размер пособия по уходу за 1 ребенком                                                                                                              
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT3', 0, '17990.11'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс. размер пособия по уходу за 1 ребенком = 17990.11', '', 'SALARY'

		--Макс.  размер пособия по уходу за 2 и более дет.                                                                                                                                                                 
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT4', 0, '17990.11'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс.  размер пособия по уходу за 2 и более дет. = 17990.11', '', 'SALARY'


		----Предельный размер пособия по нетрудоспособности                                                                                                                                                                
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT1', 0, '52000.00'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности = 52000.00', '', 'SALARY'

		--Максимальный размер пособия по беременности и родам                                                                                                                                                             
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT6', 0, '52000.00'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Максимальный размер пособия по беременности и родам = 52000.00', '', 'SALARY'
		
		--Предельный размер пособия по нетрудоспособности в минувшем году                                                                                                                                                        
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT7', 0, '47333.33'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности в минувшем году = 47333.33', '', 'SALARY'

		--Максимальный размер пособия по беременности и родам в минувшем году                                                                                                                                                      
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT8', 0, '47333.33'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Максимальный размер пособия по беременности и родам в минувшем году = 47333.33', '', 'SALARY'		

		-- УДАЛЕНИЕ ВСЕХ ПРАЗДНИКОВ 
		DELETE	FROM HOLIDAYS

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРАЗДНИЧНЫХ ДНЕЙ
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL)
			SELECT	'1 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 1, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'2 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 2, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'3 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 3, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'4 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 4, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'5 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 5, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'6 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 6, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'7 ЯНВАРЯ (РОЖДЕСТВО ХРИСТОВО)', 7, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'8 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 8, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'23 ФЕВРАЛЯ (ДЕНЬ ЗАЩИТНИКА ОТЕЧЕСТВА)', 23, 2, @TD_LINK, 1
			UNION ALL
			SELECT	'8 МАРТА (МЕЖДУНАРОДНЫЙ ЖЕНСКИЙ ДЕНЬ)', 8, 3, @TD_LINK, 1
			UNION ALL
			SELECT	'1 МАЯ (ПРАЗДНИК ВЕСНЫ И ТРУДА)', 1, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'9 МАЯ (ДЕНЬ ПОБЕДЫ)', 9, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'12 ИЮНЯ (ДЕНЬ РОССИИ)', 12, 6, @TD_LINK, 1
			UNION ALL
			SELECT	'4 НОЯБРЯ (ДЕНЬ НАРОДНОГО ЕДИНСТВА)', 4, 11, @TD_LINK, 1

		SET @TITLE = 'Установлены праздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 1 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРЕДПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB = 'П')
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРЕДПРАЗДНИЧНЫХ ДНЕЙ ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'7 МАРТА', 7, 3, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'30 АПРЕЛЯ', 30, 4, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'8 МАЯ', 8, 5, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'11 ИЮНЯ', 11, 6, @TD_LINK, 2, null, null
			UNION ALL
			SELECT	'31 ДЕКАБРЯ', 31, 12, @TD_LINK, 2, null, NULL
			UNION ALL
			SELECT	'24 ФЕВРАЛЯ', 24, 2, @TD_LINK, 2,null, NULL

		SET @TITLE = 'Установлены предпраздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 2 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ ДОПОЛНИТЕЛЬНЫХ ДНЕЙ ОТДЫХА ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'10 МАРТА (перенос выходного с 8 марта)', 10, 3, @TD_LINK, 3, 8, 3
			UNION ALL
			SELECT	'2 МАЯ (перенос выходного с 4 января)', 2, 5, @TD_LINK, 3, 4, 1
			UNION ALL
			SELECT	'13 ИЮНЯ (перенос выходного с 5 января)', 13, 6, @TD_LINK, 3, 5, 1
			UNION ALL
			SELECT	'3 НОЯБРЯ (перенос выходного с 24 февраля)', 3, 11, @TD_LINK, 3, 24, 2			

		SET @TITLE = 'Установлены дополнительные дни отдыха (перенос выходных)'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 3 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА РАБОЧИЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB IN ('Я','Ф'))
		IF COALESCE(@TD_LINK,0) > 0
		BEGIN
			-- ДОБАВЛЕНИЕ ПЕРЕНЕСЁННЫХ РАБОЧИХ ДНЕЙ
			/*	INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'11 МАРТА (рабочий день за 9 марта)', 11, 3, @TD_LINK, 3, 9, 3

				INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'5 МАЯ (рабочий день за 7 мая)', 5, 5, @TD_LINK, 3, 7, 5
			*/
			/*перенесенных рабочих дней за 2014 год нет */
		
		
			SET @TITLE = 'Установлены переносы рабочих дней'

			INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
			SELECT @TITLE, 'перенесенных рабочих дней за 2014 год нет', '', 'SALARY'
		end
	END --IF @CODE = '2014' BEGIN				

	IF @CODE = '2015' BEGIN

		SET @TITLE = @TITLE + ' на 01 ЯНВАРЯ 2015г.'

		--Мин. размер пособия по уходу за 1 ребенком
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT1', 0, '2718.34'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 1 ребенком = 2718.34', '', 'SALARY'


		--Мин. размер пособия по уходу за 2 и более дет.          
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT2', 0, '5436.67'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Мин. размер пособия по уходу за 2 и более дет. = 5436.67', '', 'SALARY'


		--Макс. размер пособия по уходу за 1 ребенком                                                                                                              
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT3', 0, '19855.82'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс. размер пособия по уходу за 1 ребенком = 19855.82', '', 'SALARY'

		--Макс.  размер пособия по уходу за 2 и более дет.                                                                                                                                                                 
		EXEC dbo.X_SET_OPTION 'VAC_CHILD_OPT4', 0, '19855.82'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Макс.  размер пособия по уходу за 2 и более дет. = 19855.82', '', 'SALARY'


		----Предельный размер пособия по нетрудоспособности                                                                                                                                                                
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT1', 0, '55833.33'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности = 55833.33', '', 'SALARY'

		--Максимальный размер пособия по беременности и родам                                                                                                                                                             
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT6', 0, '55833.33'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Максимальный размер пособия по беременности и родам = 55833.33', '', 'SALARY'
		
		--Предельный размер пособия по нетрудоспособности в минувшем году                                                                                                                                                        
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT7', 0, '52000.00'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Предельный размер пособия по нетрудоспособности в минувшем году = 52000.00', '', 'SALARY'

		--Максимальный размер пособия по беременности и родам в минувшем году                                                                                                                                                      
		EXEC dbo.X_SET_OPTION 'ARCHE_OPT8', 0, '52000.00'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, 'Максимальный размер пособия по беременности и родам в минувшем году = 52000.00', '', 'SALARY'		

		-- УДАЛЕНИЕ ВСЕХ ПРАЗДНИКОВ 
		DELETE	FROM HOLIDAYS

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРАЗДНИЧНЫХ ДНЕЙ
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL)
			SELECT	'1 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 1, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'2 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 2, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'3 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 3, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'4 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 4, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'5 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 5, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'6 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 6, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'7 ЯНВАРЯ (РОЖДЕСТВО ХРИСТОВО)', 7, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'8 ЯНВАРЯ (НОВОГОДНИЕ КАНИКУЛЫ)', 8, 1, @TD_LINK, 1
			UNION ALL
			SELECT	'23 ФЕВРАЛЯ (ДЕНЬ ЗАЩИТНИКА ОТЕЧЕСТВА)', 23, 2, @TD_LINK, 1
			UNION ALL
			SELECT	'8 МАРТА (МЕЖДУНАРОДНЫЙ ЖЕНСКИЙ ДЕНЬ)', 8, 3, @TD_LINK, 1
			UNION ALL
			SELECT	'1 МАЯ (ПРАЗДНИК ВЕСНЫ И ТРУДА)', 1, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'9 МАЯ (ДЕНЬ ПОБЕДЫ)', 9, 5, @TD_LINK, 1
			UNION ALL
			SELECT	'12 ИЮНЯ (ДЕНЬ РОССИИ)', 12, 6, @TD_LINK, 1
			UNION ALL
			SELECT	'4 НОЯБРЯ (ДЕНЬ НАРОДНОГО ЕДИНСТВА)', 4, 11, @TD_LINK, 1

		SET @TITLE = 'Установлены праздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 1 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРЕДПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB = 'П')
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ НОВЫХ ПРЕДПРАЗДНИЧНЫХ ДНЕЙ ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'30 АПРЕЛЯ', 30, 4, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'8 МАЯ', 8, 5, @TD_LINK, 2, NULL, NULL
			UNION ALL
			SELECT	'11 ИЮНЯ', 11, 6, @TD_LINK, 2, null, NULL
			UNION ALL
			SELECT	'3 НОЯБРЯ', 3, 11, @TD_LINK, 2, null, NULL
			UNION ALL
			SELECT	'31 ДЕКАБРЯ', 31, 12, @TD_LINK, 2, null, NULL


		SET @TITLE = 'Установлены предпраздничные дни'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 2 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА ПРАЗДНИЧНЫЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE WORK_D = 11)
		IF COALESCE(@TD_LINK,0) > 0
			-- ДОБАЛЕНИЕ ДОПОЛНИТЕЛЬНЫХ ДНЕЙ ОТДЫХА ГОД
			INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
			SELECT	'9 МАРТА (перенос выходного с 8 марта)', 9, 3, @TD_LINK, 3, 8, 3
			UNION ALL
			SELECT	'11 МАЯ (перенос выходного с 9 мая)', 11, 5, @TD_LINK, 3, 9, 5
			UNION ALL
			SELECT	'9 ЯНВАРЯ (перенос выходного с 3 января)', 9, 1, @TD_LINK, 3, 3, 1
			UNION ALL
			SELECT	'4 мая (перенос выходного с 4 января)', 3, 5, @TD_LINK, 3, 4, 1			

		SET @TITLE = 'Установлены дополнительные дни отдыха (перенос выходных)'

		INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
		SELECT @TITLE, NAME, '', 'SALARY' FROM dbo.HOLIDAYS WHERE TYPE_HOL = 3 ORDER BY [MONTH], [DAY] 

		--ОПРЕДЛЕНИЕ ССЫЛКИ НА РАБОЧИЙ ТИП ДНЯ
		SET @TD_LINK = (SELECT TOP 1 LINK FROM TYP_DAYS WHERE SYMB IN ('Я','Ф'))
		IF COALESCE(@TD_LINK,0) > 0
		BEGIN
			-- ДОБАВЛЕНИЕ ПЕРЕНЕСЁННЫХ РАБОЧИХ ДНЕЙ
			/*	INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'11 МАРТА (рабочий день за 9 марта)', 11, 3, @TD_LINK, 3, 9, 3

				INSERT	HOLIDAYS (NAME, DAY, MONTH, TD_LINK, TYPE_HOL, DAY1, MONTH1)
				SELECT	'5 МАЯ (рабочий день за 7 мая)', 5, 5, @TD_LINK, 3, 7, 5
			*/
			/*перенесенных рабочих дней за 2015 год нет */
		
		
			SET @TITLE = 'Установлены переносы рабочих дней'

			INSERT INTO SAL_WORNINGS (msg_before, msg, msg_after, TASK)
			SELECT @TITLE, 'перенесенных рабочих дней за 2015 год нет', '', 'SALARY'
		end
	END --IF @CODE = '2015' BEGIN	



END



GO


GRANT EXECUTE ON dbo.[SA_SET_STATIC_NASTR] TO PUBLIC

GO



GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[I_REPORT_OPTIONS_SAVE_COMMON]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[I_REPORT_OPTIONS_SAVE_COMMON]

GO
CREATE  PROCEDURE dbo.I_REPORT_OPTIONS_SAVE_COMMON
	@varKSEXPORT_TOTALS	int,
	@varKSALL_VERS_IN_THIN_CLI	int,
	@varKSCHIEF_SOC_POST	varchar(250),
	@varKSCHIEF_SOC_FIO	varchar(250),
	@varKSPERFORMER_SOC_POST	varchar(250),
	@varKSPERFORMER_SOC_FIO	varchar(250),
	@varKSPERFORMER_SOC_PHONE	varchar(250),
	@varKSINVISIBLE_CALCULATE	int,
	@varKSIMPORT_REPORT	int,
	@varKSNEW_REPORT	int,
	@varKSRELATE_DICTION	int,
	@varKSRepMaker	int,
	@varKSRepMakerFormat	int,
	@varKSNOT_VKL_V_SVOD	int,
	@varKSGOTOV_K_PROV	int,
	@varKSRETURN_STATUS	int,
	@varKSITOG_117	int,
	@varKSACCESS_STATUS	int,
	@varKSACCESS_WEB INT	
AS
-- Процедурa сформирована с помощью I_REPORT_OPTIONS_CREATE_SAVE_PROC (Федоров И.В.)
--Apr 28 2012  4:01PM           

	if exists (select * from report_options where razdel = 'COMMON' and code = 'EXPORT_TOTALS')
		update report_options
			SET val_int = @varKSEXPORT_TOTALS
			WHERE razdel = 'COMMON' and code = 'EXPORT_TOTALS'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'ALL_VERS_IN_THIN_CLI')
		update report_options
			SET val_int = @varKSALL_VERS_IN_THIN_CLI
			WHERE razdel = 'COMMON' and code = 'ALL_VERS_IN_THIN_CLI'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'CHIEF_SOC_POST')
		update report_options
			SET val_str = @varKSCHIEF_SOC_POST
			WHERE razdel = 'COMMON' and code = 'CHIEF_SOC_POST'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'CHIEF_SOC_FIO')
		update report_options
			SET val_str = @varKSCHIEF_SOC_FIO
			WHERE razdel = 'COMMON' and code = 'CHIEF_SOC_FIO'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'PERFORMER_SOC_POST')
		update report_options
			SET val_str = @varKSPERFORMER_SOC_POST
			WHERE razdel = 'COMMON' and code = 'PERFORMER_SOC_POST'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'PERFORMER_SOC_FIO')
		update report_options
			SET val_str = @varKSPERFORMER_SOC_FIO
			WHERE razdel = 'COMMON' and code = 'PERFORMER_SOC_FIO'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'PERFORMER_SOC_PHONE')
		update report_options
			SET val_str = @varKSPERFORMER_SOC_PHONE
			WHERE razdel = 'COMMON' and code = 'PERFORMER_SOC_PHONE'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'INVISIBLE_CALCULATE')
		update report_options
			SET val_int = @varKSINVISIBLE_CALCULATE
			WHERE razdel = 'COMMON' and code = 'INVISIBLE_CALCULATE'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'IMPORT_REPORT')
		update report_options
			SET val_int = @varKSIMPORT_REPORT
			WHERE razdel = 'COMMON' and code = 'IMPORT_REPORT'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'NEW_REPORT')
		update report_options
			SET val_int = @varKSNEW_REPORT
			WHERE razdel = 'COMMON' and code = 'NEW_REPORT'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'RELATE_DICTION')
		update report_options
			SET val_int = @varKSRELATE_DICTION
			WHERE razdel = 'COMMON' and code = 'RELATE_DICTION'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'RepMaker')
		update report_options
			SET val_int = @varKSRepMaker
			WHERE razdel = 'COMMON' and code = 'RepMaker'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'RepMakerFormat')
		update report_options
			SET val_int = @varKSRepMakerFormat
			WHERE razdel = 'COMMON' and code = 'RepMakerFormat'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'NOT_VKL_V_SVOD')
		update report_options
			SET val_int = @varKSNOT_VKL_V_SVOD
			WHERE razdel = 'COMMON' and code = 'NOT_VKL_V_SVOD'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'GOTOV_K_PROV')
		update report_options
			SET val_int = @varKSGOTOV_K_PROV
			WHERE razdel = 'COMMON' and code = 'GOTOV_K_PROV'

	if exists (select * from report_options where razdel = 'COMMON' and code = 'RETURN_STATUS')
		update report_options
			SET val_int = @varKSRETURN_STATUS
			WHERE razdel = 'COMMON' and code = 'RETURN_STATUS'

      
    IF     @varKSITOG_117 = 1 AND ISNULL((select Val_INT from report_options where razdel = 'COMMON' and code = 'ITOG_117'), 0) = 0
    BEGIN
	      update report_options
		   SET val_int = @varKSITOG_117
		   WHERE razdel = 'COMMON' and code = 'ITOG_117'
         
         BEGIN TRANSACTION

         DELETE dbo.report_kbk
         WHERE code_form = 'R_SPR_RASH_117_2011'


         EXEC [dbo].[RO_KBK_CASHE_UPDATE] @vcCodeForm = 'R_SPR_RASH_117_2011'

         exec dbo.droptemptable  '#t_CodeRow'
         CREATE TABLE #t_CodeRow (Code VARCHAR(50)) 
         exec dbo.droptemptable  '#LSF'
         CREATE TABLE #LSF (lsf int) 

         UPDATE STATISTICS report_kbk

         DECLARE @code VARCHAR(100), @LSF INT, @OT TINYINT, @LF INT, @LT int 

         DECLARE cur CURSOR LOCAL STATIC FOR 
         SELECT S.code, rt.orders,MAX(rsf.link_saved_form) link_saved_form FROM dbo.report_spr S
            JOIN dbo.report_coloumns rc ON S.code = rc.[Dictionary]
            JOIN dbo.report_tables rt ON rt.[Link_Table] = rc.[Link_Table]
            JOIN dbo.[REPORT_FORMS] rf ON rf.[Link_Form] = rt.[Link_Form]
            LEFT JOIN dbo.[REPORT_SAVED_FORMS] rsf ON rsf.[Link_Form] = rf.[Link_Form]
         WHERE S.NAME LIKE '%автозаполн%' AND S.code LIKE '%2011%'  AND charindex('AUTO_SPR_PARENT',rt.script_str)>0
            AND S.Code = 'R_SPR_RASH_117_2011'
         GROUP BY S.code, rt.orders

         OPEN cur

          FETCH NEXT FROM cur INTO @code, @OT, @LSF

         WHILE @@FETCH_STATUS = 0
         BEGIN
            INSERT #LSF (lsf)
            SELECT rsf.link_saved_form
            FROM dbo.report_spr S
               JOIN dbo.report_coloumns rc ON S.code = rc.[Dictionary]
               JOIN dbo.report_tables rt ON rt.[Link_Table] = rc.[Link_Table]
               JOIN dbo.[REPORT_FORMS] rf ON rf.[Link_Form] = rt.[Link_Form]
               JOIN dbo.[REPORT_SAVED_FORMS] rsf ON rsf.[Link_Form] = rf.[Link_Form]
            WHERE rt.orders = @OT AND S.code = @code --AND rf.code LIKE '%G%'
                  AND charindex('AUTO_SPR_PARENT',rt.script_str)>0

            
            SELECT @LF = link_form FROM dbo.report_saved_forms rsf JOIN #lsf ON lsf = rsf.[Link_Saved_Form]

           
            INSERT #t_CodeRow
            SELECT DISTINCT rd.Code_row
            FROM dbo.report_dinamics rd
               JOIN #lsf ON lsf = rd.link_sf
               JOIN dbo.report_coloumns rc ON rc.[Link_Col] = rd.[Link_Col]
               JOIN dbo.[REPORT_TABLES] rt ON rt.[Link_Table] = rc.[Link_Table]
            WHERE RT.[orders] = @OT
            
            EXEC dbo.[RN_FILL_WITH_CODEROW] @LSF, @LF, @OT
            
            
            TRUNCATE TABLE #t_CodeRow
            TRUNCATE TABLE #LSF  
            
            FETCH NEXT FROM cur INTO @code, @OT, @LSF
         END
         UPDATE STATISTICS report_kbk

         COMMIT          
    END     
    ELSE
    BEGIN
  	      update report_options
		   SET val_int = @varKSITOG_117
		   WHERE razdel = 'COMMON' and code = 'ITOG_117'

    END       


	if exists (select * from report_options where razdel = 'COMMON' and code = 'ACCESS_STATUS')
		update report_options
			SET val_int = @varKSACCESS_STATUS
			WHERE razdel = 'COMMON' and code = 'ACCESS_STATUS'
	if exists (select * from report_options where razdel = 'COMMON' and code = 'ACCESS_WEB')
		update report_options
			SET val_int = @varKSACCESS_WEB
			WHERE razdel = 'COMMON' and code = 'ACCESS_WEB'
GO


GRANT EXECUTE ON dbo.[I_REPORT_OPTIONS_SAVE_COMMON] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_GZ_EXPORT_MURM]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_GZ_EXPORT_MURM]

GO


CREATE	PROCEDURE [dbo].BB_GZ_EXPORT_MURM (@cBufName varchar(100), @iDubles tinyint = 0)

AS
BEGIN
declare @CurD			cursor,
		@CurT			cursor,
		@iDepLink		int,
		@cUser			varchar(50), 
		@cUserDol		varchar(50),
		@cBoss			varchar(50), 
		@cBossDol		varchar(50),
		@cBossPhone		varchar(20),
		@cGrbsName		varchar(255), 
		@cGrbsCode		varchar(15),


		@iGZLink		int,
		@iDog_Link		int,
		@cDOG_NUM		varchar(25),
		@dDOG_DATE		datetime,
		@cDEP_NAME		varchar(255),
		@cDEP_CODE		varchar(15),
		@cDEP_ACC		varchar(20),
		@cDEP_KPP		varchar(10),
		@cDEP_INN		varchar(12),
		@cZ_NUM			varchar(25),
		@dZ_DATE		DATETIME,
		@cGZ_TYPE		varchar(100),
		@cGZ_NUM		varchar(25),
		@dGZ_DATE		datetime,
		@cKOR_NAME		varchar(254),
		@cKOR_CODE		varchar(15),
		@cKOR_ACC		varchar(20),
		@cKOR_KPP		varchar(10),
		@cKOR_INN		varchar(12),
		@cKOR_ADR		varchar(255),
		@cKOR_PHONE		varchar(20),
		@cCOMMENT		varchar(255),
		@iSUMMA_B		numeric(18,2),
		@iSUMMA_V		numeric(18,2),
		@iSUMMA			numeric(18,2),
		@dDateEnd		datetime,
		@iSUMMA_PB		numeric(18,2),
		@iSUMMA_PV		numeric(18,2),
		@cCONDITION		varchar(50),
		@cOsnov			varchar(100),
		@cYear			varchar(4),

		@dDatePL		datetime,
		@iSUMMA_T		numeric(18,2),
		@cOKDP_CODE		varchar(15),
		@iOKDP_LINK		INT,
		@cOKDP_NAME		varchar(254),
		@cOKPD_CODE		varchar(15),
		@iOKPD_LINK		INT,
		@cOKPD_NAME		varchar(254),
		@iQUANTITY		numeric(20,4),
		@cUM_NAME		varchar(50),
		@iCOST			numeric(18,2),
		@cRAZD			char(4),
		@cCELST			char(7),
		@cRASH			char(3),
		@cEKR			char(3),
		@cDOP			char(10),
		@cKVART			char(1),
		@iNumDocOld		varchar(50)
		

declare @tTempDog table(	DOG_LINK	INT,
							DOG_NUM		varchar(25),
							DOG_DATE	datetime,
							DEP_NAME	varchar(255),
							DEP_CODE	varchar(15),
							DEP_ACC		varchar(20),
							DEP_KPP		varchar(10),
							DEP_INN		varchar(12),
							GZ_TYPE		varchar(100),
							GZ_NUM		varchar(25),
							GZ_DATE		datetime,
							KOR_NAME	varchar(254),
							KOR_CODE	varchar(15),
							KOR_ACC		varchar(20),
							KOR_KPP		varchar(10),
							KOR_INN		varchar(12),
							KOR_ADR		varchar(255),
							KOR_PHONE	varchar(20),
							COMMENT		varchar(255),
							OSNOV		varchar(255),
							SUMMA_B		numeric(18,2),
							SUMMA_V		numeric(18,2),
							SUMMA		numeric(18,2),
							END_DATE	datetime,
							SUMMA_PB	numeric(18,2),
							SUMMA_PV	numeric(18,2),
							CONDITION	varchar(50))			
	
declare @tTempTable table(	DATE_PL		datetime,
							LINK	INT,
							SUMMA		numeric(18,2),
							OKDP_LINK	int,
							OKPD_LINK	int,
							/*OKPD_CODE	varchar(15),
							OKPD_NAME	varchar(254),*/
							QUANTITY	numeric(20,4),
							--UM_NAME		varchar(50),
							COST		numeric(18,2),
							RAZD		char(4),
							CELST		char(7),
							RASH		char(3),
							EKR			char(3),
							DOP			char(10),
							KVART		char(1))


declare @tTxt table (Txt varchar(8000), orders int identity)
							
-- Организация -- 
SET @iDepLink = isnull(dbo.BK_GetDepZB () ,dbo.GetOwnDepLink())

-- Руководитель -- 
Select	@cBoss = OTV.FACE_NAME ,
		@cBossDol = EP.POST_NAME,
		@cBossPhone = OTV.PHONE
FROM dbo.DICTIONARY_OTV_FACE OTV 
LEFT OUTER JOIN dbo.KU_EMPL_PLACING EP ON OTV.FACE_LINK = EP.LINK
WHERE OTV.DEP_LINK = @iDepLink and OTV.NAME = 'Руководитель'

-- Исполнитель -- 
Select	@cUser = EP.NAME_EMPL,
		@cUserDol = ep.post_name
from dbo.WHO_IS_WHO UD 
left join dbo.KU_EMPL_PLACING EP ON UD.USER_REF = EP.LINK
where UD.SID = SUSER_SID()
-- ГРБС -- 
Select	@cGrbsName = ADM.NAME,
		@cGrbsCode = ADM.CODE
FROM DEPARTMENTS D
LEFT JOIN dbo.KL_ADMIN_BS ADM on ADM.LINK = D.VED_LINK 
WHERE D.LINK = @iDepLink

select @cBoss = isnull(@cBoss,''),
		@cBossDol = isnull(@cBossDol,''),
		@cBossPhone = isnull(@cBossPhone,''),
		@cUser = isnull(@cUser,''),
		@cUserDol = isnull(@cUserDol,''),
		@cGrbsName = isnull(@cGrbsName,''),
		@cGrbsCode = isnull(@cGrbsCode,'')

insert into @tTempTable (	DATE_PL, LINK, SUMMA, QUANTITY, COST, OKDP_LINK,OKPD_LINK,
						--OKPD_CODE, OKPD_NAME, UM_NAME,
						RAZD, CELST, RASH, EKR, DOP, KVART)
select	isnull(GR.DATE,''), 
		GZR.LINK, 
		isnull(T.SUMMA,0), 
		isnull(T.QUANTITY,0), 
		isnull(T.COST,0),
		isnull(N.LINK_OKDP,''), 
		isnull(N.LINK_OKPD,''),
		/*isnull(O.CODE,''), 
		isnull(O.NAME,''), 
		isnull(UM.NAME,''),*/
		isnull(VKR.CODE_FKR_D,''), 
		isnull(VKR.CODE_FKR_T,''), 
		isnull(VKR.CODE_FKR_E,''), 
		isnull(EKR.CODE,''), 
		isnull(DCL.CODE,''), 
		isnull(cast((month(GR.DATE_PROV)-1)/3+1 as char(1)),'')
from dbo.G_PROV GR 
inner join	dbo.GZ_REESTR GZR on GZR.LINK = GR.LINK
inner join	dbo.GZ_REESTR_DOP T on T.LINK_UP = GR.LINK
left join	dbo.NOMENCLATURE N on N.LINK = T.NOMENCLATURE
left join 	dbo.DICTIONARY_DIGIT UM on N.UM = UM.LINK 
--left join 	dbo.OKPD O on O.LINK = N.LINK_OKPD
left join	dbo.FINANSE_CONTRACT CT on CT.LINK_UP = GZR.LINK_CONTRACT and (CT.OKPD = T.NOMENCLATURE or  CT.OKDP = T.NOMENCLATURE)
left join	(select TOP 1 MAX(GAP.KBK) as KBK, MAX(GAP.EKR) as EKR, MAX(GAP.AP2) as AP2, G2.LINK 
			 from dbo.G_PROV2 G2 
			 inner join	dbo.G_PROV_AP GAP on G2.LINK = GAP.LINK_UP
			 group by G2.LINK) PROV ON GZR.LINK_G_PROV2 = PROV.LINK
left join 	dbo.BI_DICTION_VKR VKR on VKR.LINK_KBK = ISNULL(CT.VKR,PROV.KBK)
left join 	dbo.KOSGU EKR on EKR.LINK = ISNULL(CT.EKR,PROV.EKR)
left join 	dbo.DOP_CLASSIF DCL on DCL.LINK = ISNULL(CT.DOP_CLASSIF,PROV.AP2)
where (@cBufName = 'GZ_ALL' and GR.DEP = @iDepLink) or 
		(@cBufName <> 'GZ_ALL' and GR.LINK in (select LINK from dbo.BufferGetTableByID(@cBufName)))
		 


/*insert into @tTempDog (DOG_LINK, DOG_NUM, DOG_DATE, COMMENT, END_DATE,  
						DEP_NAME, DEP_CODE, DEP_ACC, DEP_KPP, DEP_INN,
						GZ_TYPE, GZ_NUM, GZ_DATE, 
						KOR_NAME, KOR_CODE, KOR_ACC, KOR_KPP, KOR_INN, KOR_ADR, KOR_PHONE,
						SUMMA_B, SUMMA_V, SUMMA, SUMMA_PB, SUMMA_PV, CONDITION)*/
SET @CurD = CURSOR FORWARD_ONLY	FOR 
SELECT GD.LINK, 
		ISNULL(GD.NUMBER,''), 
		ISNULL(GD.DATE,''), 
		ISNULL(case ZT.TYPE when 10 then '' else GD.COMMENT end,''), 
		ISNULL(case ZT.TYPE when 10 then GD.COMMENT else '' end,''), 
		COALESCE(HC.DATE_END,GD.DATE,''), 
		D.NAME, 
		D.CODE, 
		DA.CODE, 
		D.KPP, 
		D.INN,
		ZT.NAME, 
		ISNULL(GR.NUMBER,''), 
		GR.DATE,
		ISNULL(HC.GZ_NUM,''), 
		ISNULL(HC.GZ_DATE,''),				
		ISNULL(DK.NAME,''), 
		ISNULL(DK.CODE,''), 
		ISNULL(DAK.CODE,''), 
		ISNULL(DK.KPP,''), 
		ISNULL(DK.INN,''),
		isnull(rtrim(cast(dbo.GetAddressByKladr(DK.KLADR_LINK) + CASE when DK.HOUSE is null or DK.HOUSE = '' then '' else ' ,' + DK.HOUSE end   as varchar(250))),''),
		'',
		isnull(DS.SUMMA_PB,0), 
		isnull(DS.SUMMA_PV,0), 
		isnull(DS.SUMMA_OB + DS.SUMMA_OV,0), 
		isnull(DS.SUMMA_OB,0), 
		isnull(DS.SUMMA_OV,0), 
		case HC.CON_PAY when 1 then 'По факту поставки' else 'Предоплата' end,
		cast(year(GR.DATE) as char(4)),
		isnull(OKDP.NAME,''),
		DS.OKDP_LINK,
		isnull(OKPD.NAME,''),
		DS.OKPD_LINK,
		GR.LINK
FROM dbo.G_PROV GR 
inner join 	dbo.DEPARTMENTS D on GR.DEP = D.LINK
inner join	dbo.GZ_REESTR GZR on GZR.LINK = GR.link
left join	dbo.G_PROV GD on GD.LINK = GZR.LINK_CONTRACT
left join 	dbo.DEPARTMENT_ACCOUNTS DA ON DA.LINK = GR.ACC
left join	dbo.FINANSE_CONTRACT_HEAD HC on HC.LINK_G_PROV = GD.LINK
left join	dbo.GZ_NOT_CONTRACT_HEAD GZ on GZ.LINK = GD.LINK
left join	(select MAX(GAP.DEP) as DEP, MAX(GAP.DEP_ACC) as DEP_ACC, G2.LINK 
			from dbo.G_PROV2 G2 
			inner join	dbo.G_PROV_AP GAP on G2.LINK = GAP.LINK_UP
			group by G2.LINK) PROV ON GZR.LINK_G_PROV2 = PROV.LINK
left join 	dbo.DEPARTMENTS DK on COALESCE(HC.DEP_LINK_P,GZ.DEP_LINK_P,PROV.DEP) = DK.LINK
left join 	dbo.DEPARTMENT_ACCOUNTS DAK on PROV.DEP_ACC = DAK.LINK
left join 	dbo.FB_GZ_TYPE ZT on ISNULL(HC.TYPE, GZ.TYPE) = ZT.TYPE
left join 	(select SUMMA_PB = case TYPE when 1 then sum(RD.SUMMA) else 0 end,
					SUMMA_PV = 0,
					SUMMA_OB = case TYPE when 2 then sum(RD.SUMMA) else 0 end,
					SUMMA_OV = 0,
					LINK_UP, TYPE,
					OKDP_LINK = N.LINK_OKDP ,
					OKPD_LINK = N.LINK_OKPD 
			 from dbo.GZ_REESTR_DOP RD
			 inner join dbo.NOMENCLATURE N on N.LINK = RD.NOMENCLATURE
			 group by RD.LINK_UP, RD.TYPE, LINK_OKDP, LINK_OKPD) DS on DS.LINK_UP = GR.LINK
left join dbo.OKDP OKDP on DS.OKDP_LINK = OKDP.LINK
left join dbo.OKPD OKPD on DS.OKPD_LINK = OKPD.LINK
where (@cBufName = 'GZ_ALL' and GR.DEP = @iDepLink or 
	  @cBufName <> 'GZ_ALL' and GR.LINK in (select LINK from dbo.BufferGetTableByID(@cBufName)))
		and (DS.OKDP_LINK is not null or DS.OKPD_LINK is not null)
		and (@iDubles = 1 or @iDubles = 0 and GR.LINK not IN (select LINK_G from dbo.GZ_EXPORT_EVENTS))
		
--select * from @tTempDog

--select * from @tTempTable


insert into @tTxt
select '<?xml version="1.0" encoding="windows-1251"?>' union all
select '<doclist>'


open @CurD
fetch NEXT from @CurD 
into @iDog_Link, @cDOG_NUM, @dDOG_DATE, @cCOMMENT, @cOsnov, @dDateEnd, @cDEP_NAME, @cDEP_CODE, @cDEP_ACC, @cDEP_KPP, @cDEP_INN, @cGZ_TYPE, @cZ_NUM, @dZ_DATE, @cGZ_NUM, @dGZ_DATE, 
		@cKOR_NAME, @cKOR_CODE, @cKOR_ACC, @cKOR_KPP, @cKOR_INN, @cKOR_ADR, @cKOR_PHONE, @iSUMMA_B, @iSUMMA_V, @iSUMMA, @iSUMMA_PB, @iSUMMA_PV, @cCONDITION,@cYear, @cOKDP_NAME, @iOKDP_LINK, @cOKPD_NAME, @iOKPD_LINK, @iGZLink
set @iNumDocOld = ''
while @@FETCH_STATUS = 0
begin
--	if @iNumDocOld <> @cDOG_NUM
--	begin 
		insert into @tTxt values('<document type="REGKKON" id="" creator="DF" created="2010/01/01 17:04:15">')
		insert into @tTxt values('<fieldlist>')
		insert into @tTxt values('<field name="Number">' + rtrim(@cZ_NUM) + '</field>')
		insert into @tTxt values('<field name="Date">' + rtrim(convert(char(10),@dZ_DATE,104)) + '</field>')
		insert into @tTxt values('<field name="Client">' + rtrim(@cDEP_NAME) + '</field>')
		insert into @tTxt values('<field name="ClientINN">' + rtrim(@cDEP_INN) + '</field>')
		insert into @tTxt values('<field name="ClientKPP">' + rtrim(@cDEP_KPP) + '</field>')
		insert into @tTxt values('<field name="ClientLS">' + rtrim(@cDEP_ACC) + '</field>')
		insert into @tTxt values('<field name="PriceCon">' + rtrim(ltrim(str(@iSUMMA))) + '</field>')
		insert into @tTxt values('<field name="ReestNumCon">' + rtrim(@cZ_NUM) + '</field>')
		insert into @tTxt values('<field name="FinancialLim">' + rtrim(ltrim(str(@iSUMMA))) + '</field>')
		insert into @tTxt values('<field name="NumGenCon">' + rtrim(@cDOG_NUM) + '</field>')
		insert into @tTxt values('<field name="SubjectCon">' + (case when rtrim(ISNULL(@cOKDP_NAME,'')) = '' then rtrim(ISNULL(@cOKPD_NAME,''))  else '' end )+ '</field>')
		insert into @tTxt values('<field name="DateInReestr"></field>')
		insert into @tTxt values('<field name="DateConclCon">' + rtrim(convert(char(10),@dDOG_DATE,104)) + '</field>')
		insert into @tTxt values('<field name="DateEnd">' + case @dDateEnd when '19000101' then '' else rtrim(convert(char(10),@dDateEnd,104)) end + '</field>')
		insert into @tTxt values('<field name="ManagerSign">' + rtrim(@cBoss) + '</field>')
		insert into @tTxt values('<field name="PostMan">' + rtrim(@cBossDol) + '</field>')
		insert into @tTxt values('<field name="PostExec">' + rtrim(@cUserDol) + '</field>')
		insert into @tTxt values('<field name="Provider">' + rtrim(@cKOR_NAME) + '</field>')
		insert into @tTxt values('<field name="INN">' + rtrim(@cKOR_INN) + '</field>')
		insert into @tTxt values('<field name="KPP">' + rtrim(@cKOR_KPP) + '</field>')
		insert into @tTxt values('<field name="Phone_Fax">' + rtrim(@cKOR_PHONE) + '</field>')
		insert into @tTxt values('<field name="ProviderAccounts">' + rtrim(@cKOR_ACC) + '</field>')
		insert into @tTxt values('<field name="BankBik"/>')
		insert into @tTxt values('<field name="BankCorAcc"/>')
--	end
		insert into @tTxt values('<field name="RegKKon"><row T_Year_RegKKon="' + rtrim(@cYear) + (case when rtrim(ISNULL(@cOKPD_NAME,'')) <> '' then '" T_OKPDNew_RegKKon="' + rtrim(@cOKPD_NAME)+'' else '" T_OKDPNew_RegKKon="' + rtrim(@cOKDP_NAME)+'' end  ) + '" T_TotalSumma_RegKKon="' + rtrim(ltrim(str(isnull(@iSUMMA,0)))) + '" T_LimitSum_RegKKon="' + rtrim(ltrim(str(isnull(@iSUMMA,0)))) + '" T_ReestNumCon_REGKKON="" /></field>')	
	

	SET @CurT = CURSOR FORWARD_ONLY	FOR 
	select DATE_PL, SUMMA, QUANTITY, COST,
			RAZD, CELST, RASH, EKR, DOP, KVART 
	from @tTempTable 
	where LINK = @iGZLink and (OKDP_LINK = @iOKDP_LINK or OKPD_LINK = @iOKPD_LINK )

	open @CurT

	fetch NEXT from @CurT 
	into @dDatePL, @iSUMMA_T, @iQUANTITY, @iCOST,
		 @cRAZD, @cCELST, @cRASH, @cEKR, @cDOP, @cKVART

	while @@FETCH_STATUS = 0
	begin
		insert into @tTxt values('<field name="PaymentStage"><row T_PS_YEAR="' + rtrim(@cYear) + 
								'" T_PS_ReestrNum="' + rtrim(@cZ_NUM) + 
								'" T_PS_BillCharge="" T_PS_QuarterPay="' + rtrim(@cKVART) + 
								'" T_PS_SumPay="' + rtrim(ltrim(str(@iSUMMA_T))) + 
								'" T_PS_LS="' + rtrim(@cDEP_ACC) + 
								'" T_PS_DatePay="' + rtrim(convert(char(10),@dDatePL,104)) +
								'" T_PS_RazdelCode="' + rtrim(@cRAZD) + 
								'" T_PS_TargetCode="' + rtrim(@cCELST) + 
								'" T_PS_KodRas="' + rtrim(@cRASH) + 
								'" T_PS_EconomicCode="' + rtrim(@cEKR) + '" /></field>')
		
		fetch NEXT from @CurT 
		into @dDatePL, @iSUMMA_T, @iQUANTITY, @iCOST,
			  @cRAZD, @cCELST, @cRASH, @cEKR, @cDOP, @cKVART

	end
	if not exists(select * from dbo.GZ_EXPORT_EVENTS where LINK_G = @iGZLink)
		insert into dbo.GZ_EXPORT_EVENTS(LINK_G) values (@iGZLink)

	close @CurT
	--set @iNumDocOld = @cDOG_NUM
	fetch NEXT from @CurD 
	into @iDog_Link, @cDOG_NUM, @dDOG_DATE, @cCOMMENT, @cOsnov, @dDateEnd, @cDEP_NAME, @cDEP_CODE, @cDEP_ACC, @cDEP_KPP, @cDEP_INN, @cGZ_TYPE, @cZ_NUM, @dZ_DATE, @cGZ_NUM, @dGZ_DATE, 
		@cKOR_NAME, @cKOR_CODE, @cKOR_ACC, @cKOR_KPP, @cKOR_INN, @cKOR_ADR, @cKOR_PHONE, @iSUMMA_B, @iSUMMA_V, @iSUMMA, @iSUMMA_PB, @iSUMMA_PV, @cCONDITION,@cYear, @cOKPD_NAME, @iOKDP_LINK, @iOKPD_LINK, @iGZLink

--	if @iNumDocOld <> @cDOG_NUM
--		begin 
	
		--insert into @tTxt values('</field>')
		insert into @tTxt values('</fieldlist>')
		insert into @tTxt values('</document>')
		/*insert into @tTxt values('<link>')
		insert into @tTxt values('<field name="type">REGKKON</field>')
		insert into @tTxt values('<field name="ownerInfo">РН 0182100800011/ от 0182100800011</field>')
		insert into @tTxt values('<field name="itemType">DEMANDREGKKON</field>')
		insert into @tTxt values('<field name="itemOrg">KO_210</field>')
		insert into @tTxt values('<field name="itemCreator">2530</field>')
		insert into @tTxt values('</link>')*/
--	end
	
end
close @CurD
--insert into @tTxt values('</fieldlist>')
--insert into @tTxt values('</document>')
insert into @tTxt values('</doclist>')


--select * from @tTxt order by orders
select ltrim(rtrim(txt)) as txt from @tTxt order by orders
END




GO


GRANT EXECUTE ON dbo.[BB_GZ_EXPORT_MURM] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SVED_GOS_SLUSH]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SVED_GOS_SLUSH]

GO

/*----------------------------------------------------------
------------------------------------------------------------
	СВЕДЕНИЯ О ГОСУДАРСТВЕННЫХ ГРАЖДАНСКИХ СЛУЖАЩИХ
		Шорков И.А. 	28.10.2014 г.
------------------------------------------------------------
----------------------------------------------------------*/

CREATE PROCEDURE dbo.SVED_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS

DECLARE @dDate1 DATETIME, @dDate2 DATETIME


SET @dDate1 = dbo.ConvertDMY2Date(1,1,@cYear1) 

IF @nCombo1 = 1 	
	SET @dDate2 = dbo.ConvertDMY2Date(30,6,@cYear1) 
IF @nCombo1 = 2 
	SET @dDate2 = dbo.DateEndOfYear(@dDate1) 

-- выборка сотрудников из фильтра
DECLARE @varKSEMPLS TABLE(LINK_EMPL INT)

INSERT	INTO @varKSEMPLS
SELECT	EP.LINK
FROM	DBO.KU_EMPL_PLACING_FN(@dDate2) EP	
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0												-- работающие на дату @dDate
--------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------ДОПОЛНИТЕЛЬНЫЕ ТАБЛИЦЫ --------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------
-- даты последних назначений на должность
SELECT	EMPL_LINK, MAX(DATE_PD) AS DATE
INTO	#EMPL_DATE_POST
FROM	DICTIONARY_PURP_DISP_FACES
WHERE	DATE_PD <= @dDate2
	AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
GROUP	BY EMPL_LINK

-- последние образования (соответствующие квалификационным требованиям)
CREATE	TABLE #PERS_EDUC(PERS_LINK INT,EDUC_FORM VARCHAR(100),SCHOOL VARCHAR(250),DIP_DATE DATETIME,DIP_NUM VARCHAR(50),SPEC VARCHAR(200))
--
SELECT	E.PERS_LINK INTO #PERS
FROM	@varKSEMPLS A LEFT JOIN EMPL E ON A.LINK_EMPL = E.LINK
--
DECLARE @PERS_LINK INT
WHILE EXISTS(SELECT * FROM #PERS) BEGIN
	SELECT TOP 1 @PERS_LINK = PERS_LINK FROM #PERS
	--
	IF EXISTS(SELECT * FROM PERS_EDUCATION WHERE PERS_LINK = @PERS_LINK AND DATE_END <= @dDate2 AND SATISFY = 1) BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
			AND SATISFY = 1
		ORDER	BY DATE_END DESC
	END ELSE BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
		ORDER	BY DATE_END DESC
	END
	--
	DELETE FROM #PERS WHERE PERS_LINK = @PERS_LINK
END
DROP TABLE #PERS

-- последние классные чины
SELECT	KEC.EMPL_LINK, KEC.CHIN_NAME, KEC.DATE, KEC.REASON
INTO	#EMPL_CHIN
FROM	KU_EMPL_CHIN KEC RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE) AS DATE
	FROM	EMPL_CHIN
	WHERE	DATE <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEC.EMPL_LINK = T.EMPL_LINK AND KEC.DATE = T.DATE

-- последние аттестации
SELECT	KEA.EMPL_LINK, KEA.DATE, KEA.ATT_NAME
INTO	#EMPL_ATTEST
FROM	KU_EMPL_ATTEST KEA RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE) AS DATE
	FROM	EMPL_ATTEST
	WHERE	DATE <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEA.EMPL_LINK = T.EMPL_LINK AND KEA.DATE = T.DATE

-- последние профессиональные переподготовки
SELECT	KEP.EMPL_LINK, KEP.DATE_BEGIN, KEP.DATE_END, KEP.DOC_TYPE, KEP.DOC_NUM, KEP.DOC_DATE, KEP.PROG_NAME, KEP.PLACE, KEP.[TIME]
INTO	#EMPL_PROFP
FROM	KU_EMPL_PROFP KEP RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE_END) AS DATE_END
	FROM	EMPL_PROFP
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEP.EMPL_LINK = T.EMPL_LINK AND KEP.DATE_END = T.DATE_END

-- последние повышения квалификаций
SELECT	KEI.EMPL_LINK, KEI.DATE_BEGIN, KEI.DATE_END, KEI.DOC_TYPE, KEI.DOC_NUM, KEI.DOC_DATE, KEI.PROG_NAME, KEI.PLACE, KEI.[TIME]
INTO	#EMPL_INCQUAL
FROM	KU_EMPL_INCQUAL KEI RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE_END) AS DATE_END
	FROM	EMPL_INCQUAL
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEI.EMPL_LINK = T.EMPL_LINK AND KEI.DATE_END = T.DATE_END
-- последние награждения
SELECT	KPA.PERS_LINK, KPA.AWARD_NAME, KPA.DOC_DATE
INTO	#PERS_AWARD
FROM	KU_PERS_AWARD KPA RIGHT JOIN (
	SELECT	PERS_LINK, MAX(DOC_DATE) AS DOC_DATE
	FROM	PERS_AWARD
	WHERE	DOC_DATE <= @dDate2
	GROUP	BY PERS_LINK
	) T ON KPA.PERS_LINK = T.PERS_LINK AND KPA.DOC_DATE = T.DOC_DATE

------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------- ВЫБОРКа ДАННЫХ -----------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT
	[COL_2]	 = KEP.FIO,									-- фамилия
	[COL_3]	 = ISNULL(KEP.POST_NAME,''),							-- наименование должности
	[COL_4]	 = CASE	WHEN D_ST.KAT_GOS_CODE = 1 THEN 'Рукводители'				-- категория должности
			WHEN D_ST.KAT_GOS_CODE = 2 THEN 'Помощники (советники)'
			WHEN D_ST.KAT_GOS_CODE = 3 THEN 'Специалисты'
			WHEN D_ST.KAT_GOS_CODE = 4 THEN 'Обеспечивающие специалисты'
			ELSE ''
		   END,										
	[COL_5]	 = CASE	WHEN D_ST.GR_GOS_CODE = 1 THEN 'Высшая'					-- группа должности
			WHEN D_ST.GR_GOS_CODE = 2 THEN 'Главная'	
			WHEN D_ST.GR_GOS_CODE = 3 THEN 'Ведущая'	
			WHEN D_ST.GR_GOS_CODE = 4 THEN 'Старшая'	
			WHEN D_ST.GR_GOS_CODE = 5 THEN 'Младшая'	
			ELSE ''
		   END,
	[COL_6]	 = CONVERT(VARCHAR(10),P.BIRTHDATE,104),				-- дата рождения
	[COL_7]	 = CONVERT(VARCHAR(10),KEP.DATE_BEGIN,104),				-- дата поступления на службу в государсвтенный орган
	[COL_8]	 = CONVERT(VARCHAR(10),EDP.DATE,104),					-- дата назначения на должность
	[COL_9]	 = '',							-- Срок действия служебного контракта 
	[COL_10] = SUBSTRING((dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1)), 1,  charindex('м.' , dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1))+2),				-- Стаж государственной гражданской службы (лет, мес.)
	[COL_11] = SUBSTRING((dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)), 1,  charindex('м.' , (dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)))+2),	-- Стаж государственной гражданской службы для назначения пенсии за выслугу лет 
	[COL_12] = CASE WHEN ISNULL(PE.SCHOOL,'') = '' THEN  ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'')
				ELSE ltrim(rtrim(ISNULL(PE.SCHOOL,''))) + ', ' + ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'') END ,	-- учебное заведение (образование) и дата диплома (образование)
	[COL_13] = ISNULL(PE.SPEC,''),								-- специальность (образование)
	[COL_14] = CASE	WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	-- ученая степень, ученое звание , дата присвоения ученой степени, ученого звания
			ELSE (SELECT NAME FROM ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK)
		   END + 
		   CASE	WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 THEN ''
			ELSE CASE WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	
				  ELSE ', '
			     END + (SELECT NAME FROM ACAD_STATUS WHERE LINK = P.ACAD_STATUS_LINK)
		   END
		   + CASE WHEN isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE,104),'') = '' THEN ''
			  ELSE 
				CASE WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 AND ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''
				  ELSE ', '
				 END + isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE, 104),'') 
			 END ,
	[COL_15] = ltrim(RTRIM(ISNULL(EC.CHIN_NAME,'')))  
			 + CASE WHEN ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'') = '' THEN ''
				  else
				    case when ISNULL(EC.CHIN_NAME,'') = '' THEN ''
					  ELSE ', ' 
					 END + ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'')
				END  ,				-- наименование классного чина ,  дата присвоения чина
	[COL_16] = ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'')
				 +  CASE WHEN ISNULL(EA.ATT_NAME,'') = '' THEN ''
					else	
						CASE WHEN ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'') = '' THEN ''
							ELSE ', ' 
					   END + 	ISNULL(EA.ATT_NAME,'')
				   	END 	,				-- дата проведения аттестации, решение аттестационной комиссии

	[COL_17] =  CASE WHEN ISNULL(EP.PLACE,'')= '' 
					 AND  ISNULL(EP.PROG_NAME,'') = '' 
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = ''
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') = ''
					 AND  ISNULL(EP.[TIME],'') = ''
						THEN ''
				 	 ELSE 
						'Проф.переподготовка: ' + (CASE WHEN  ISNULL(EP.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EP.PLACE,''))) + '; ' END )  
										+   (CASE WHEN ISNULL(EP.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EP.PROG_NAME,''))) + '"; ' end )
										+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') =  '' THEN  ''
												ELSE 
													' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') + '; '
												END )	
										+ (CASE WHEN ISNULL(EP.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EP.[TIME]),'') + '; ' END )
					 END 
					, -- проф.переподготовка, наименование учреждения , наименование программы обучения, дата обучения, время обучения.
	
	[COL_18] =  CASE WHEN ISNULL(EI.PLACE,'')= '' 
				 AND  ISNULL(EI.PROG_NAME,'') = '' 
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = ''
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') = ''
				 AND  ISNULL(EI.[TIME],'') = ''
					THEN ''
			 	 ELSE 
					'Последнее повышение квалификации: ' + (CASE WHEN  ISNULL(EI.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EI.PLACE,''))) + '; ' END )  
									+   (CASE WHEN ISNULL(EI.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EI.PROG_NAME,''))) + '"; ' end )
									+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') =  '' THEN  ''
											ELSE 
												' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') + '; '
											END )	
									+ (CASE WHEN ISNULL(EI.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EI.[TIME]),'') + '; ' END )
				 END 
				, -- последнее повышение квалификации: наименование учреждения , наименование программы обучения, дата обучения, время обучения.
-------------------------------------------------------------------------------------------------------------------------------------------------------
	[SUBDIV]	= ISNULL(KEP.SUBDIV_NAME,''),
	[SUBDIV_C]	= ISNULL(KEP.SUBDIV_CODE,'')
FROM	KU_EMPL_PLACING_FN(@dDate2) KEP
	LEFT JOIN PERSON P ON P.LINK = KEP.PERS_LINK
	LEFT JOIN DICTIONARY_STAFF_FN(@dDate2) D_ST ON  KEP.STAFF_LINK = D_ST.STAFF_LINK
	LEFT JOIN #EMPL_DATE_POST EDP ON EDP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_CHIN EC ON EC.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_ATTEST EA ON EA.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_PROFP EP ON EP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_INCQUAL EI ON EI.EMPL_LINK = KEP.LINK
	LEFT JOIN #PERS_EDUC PE ON PE.PERS_LINK = KEP.PERS_LINK
	LEFT JOIN #PERS_AWARD PA ON PA.PERS_LINK = KEP.PERS_LINK
WHERE	KEP.LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)		-- СОТРУДНИКИ ИЗ ФИЛЬТРА
  	AND D_ST.GOSSL IN (1,2,3, 4)
ORDER	BY KEP.SUBDIV_CODE

-------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
DROP TABLE #EMPL_DATE_POST
DROP TABLE #EMPL_CHIN
DROP TABLE #EMPL_ATTEST
DROP TABLE #EMPL_PROFP
DROP TABLE #EMPL_INCQUAL
DROP TABLE #PERS_EDUC
DROP TABLE #PERS_AWARD

GO


GRANT EXECUTE ON dbo.[SVED_GOS_SLUSH] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_TMP_OTS_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_TMP_OTS_GS]

GO

/*----------------------------------------------------------
------------------------------------------------------------
	СВЕДЕНИЯ О ВРЕМЕННО ОТСУТСТВУЮЩИХ ГОСУДАРСТВЕННЫХ ГРАЖДАНСКИХ СЛУЖАЩИХ
	(отпуск по беременности и родам, отпуск по уходу за ребенком,
		длительный отпуск без сохранения денежного содержания)
		Шорков И.А. 	29.10.2014 г.
------------------------------------------------------------
----------------------------------------------------------*/

CREATE PROCEDURE dbo.REP_TMP_OTS_GS
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS

DECLARE @dDate1 DATETIME, @dDate2 DATETIME


SET @dDate1 = dbo.ConvertDMY2Date(1,1,@cYear1) 

IF @nCombo1 = 1 	
	SET @dDate2 = dbo.ConvertDMY2Date(30,6,@cYear1) 
IF @nCombo1 = 2 
	SET @dDate2 = dbo.DateEndOfYear(@dDate1) 

-- выборка сотрудников из фильтра
DECLARE @varKSEMPLS TABLE(LINK_EMPL INT)

INSERT	INTO @varKSEMPLS
SELECT	EP.LINK
FROM	DBO.KU_EMPL_PLACING_FN(@dDate2) EP	
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0												-- не уволенные на дату @dDate2
	AND EXISTS (SELECT * FROM vacation v 
INNER JOIN  VACATION_VID vv ON vv.link = v.type_link  
	INNER JOIN typ_days td ON td.LINK = vv.TYPE_LINK  AND td.WORK_D IN (13,7,8) AND isnull(vv.adm,0) <> 1  
	                WHERE  v.empl_link = EP.LINK AND v.date_END >=  @dDate2 AND V.dep_link = EP.DEP_LINK 
							AND V.active = 1)  		

--------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------ДОПОЛНИТЕЛЬНЫЕ ТАБЛИЦЫ --------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------
-- даты последних назначений на должность
SELECT	EMPL_LINK, MAX(DATE_PD) AS DATE
INTO	#EMPL_DATE_POST
FROM	DICTIONARY_PURP_DISP_FACES
WHERE	DATE_PD <= @dDate2
	AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
GROUP	BY EMPL_LINK

-- последние образования (соответствующие квалификационным требованиям)
CREATE	TABLE #PERS_EDUC(PERS_LINK INT,EDUC_FORM VARCHAR(100),SCHOOL VARCHAR(250),DIP_DATE DATETIME,DIP_NUM VARCHAR(50),SPEC VARCHAR(200))
--
SELECT	E.PERS_LINK INTO #PERS
FROM	@varKSEMPLS A LEFT JOIN EMPL E ON A.LINK_EMPL = E.LINK
--
DECLARE @PERS_LINK INT
WHILE EXISTS(SELECT * FROM #PERS) BEGIN
	SELECT TOP 1 @PERS_LINK = PERS_LINK FROM #PERS
	--
	IF EXISTS(SELECT * FROM PERS_EDUCATION WHERE PERS_LINK = @PERS_LINK AND DATE_END <= @dDate2 AND SATISFY = 1) BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
			AND SATISFY = 1
		ORDER	BY DATE_END DESC
	END ELSE BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
		ORDER	BY DATE_END DESC
	END
	--
	DELETE FROM #PERS WHERE PERS_LINK = @PERS_LINK
END
DROP TABLE #PERS

-- последние классные чины
SELECT	KEC.EMPL_LINK, KEC.CHIN_NAME, KEC.DATE, KEC.REASON
INTO	#EMPL_CHIN
FROM	KU_EMPL_CHIN KEC RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE) AS DATE
	FROM	EMPL_CHIN
	WHERE	DATE <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEC.EMPL_LINK = T.EMPL_LINK AND KEC.DATE = T.DATE

-- последние аттестации
SELECT	KEA.EMPL_LINK, KEA.DATE, KEA.ATT_NAME
INTO	#EMPL_ATTEST
FROM	KU_EMPL_ATTEST KEA RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE) AS DATE
	FROM	EMPL_ATTEST
	WHERE	DATE <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEA.EMPL_LINK = T.EMPL_LINK AND KEA.DATE = T.DATE

-- последние профессиональные переподготовки
SELECT	KEP.EMPL_LINK, KEP.DATE_BEGIN, KEP.DATE_END, KEP.DOC_TYPE, KEP.DOC_NUM, KEP.DOC_DATE, KEP.PROG_NAME, KEP.PLACE, KEP.[TIME]
INTO	#EMPL_PROFP
FROM	KU_EMPL_PROFP KEP RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE_END) AS DATE_END
	FROM	EMPL_PROFP
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEP.EMPL_LINK = T.EMPL_LINK AND KEP.DATE_END = T.DATE_END

-- последние повышения квалификаций
SELECT	KEI.EMPL_LINK, KEI.DATE_BEGIN, KEI.DATE_END, KEI.DOC_TYPE, KEI.DOC_NUM, KEI.DOC_DATE, KEI.PROG_NAME, KEI.PLACE, KEI.[TIME]
INTO	#EMPL_INCQUAL
FROM	KU_EMPL_INCQUAL KEI RIGHT JOIN (
	SELECT	EMPL_LINK, MAX(DATE_END) AS DATE_END
	FROM	EMPL_INCQUAL
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)
	GROUP	BY EMPL_LINK
	) T ON KEI.EMPL_LINK = T.EMPL_LINK AND KEI.DATE_END = T.DATE_END
-- последние награждения
SELECT	KPA.PERS_LINK, KPA.AWARD_NAME, KPA.DOC_DATE
INTO	#PERS_AWARD
FROM	KU_PERS_AWARD KPA RIGHT JOIN (
	SELECT	PERS_LINK, MAX(DOC_DATE) AS DOC_DATE
	FROM	PERS_AWARD
	WHERE	DOC_DATE <= @dDate2
	GROUP	BY PERS_LINK
	) T ON KPA.PERS_LINK = T.PERS_LINK AND KPA.DOC_DATE = T.DOC_DATE

--- кто замещал во время отсутствия 
SELECT	EMPL_LINK, fio, subst_empl_link , S_FIO, DATE_BEGIN, DATE_END, NUMBER, [DATE]
INTO	#SUBST
FROM	SUBST  
WHERE	DATE_END >= @dDate2
		AND SUBST_EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)

------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------- ВЫБОРКа ДАННЫХ -----------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT
	[COL_2]	 = KEP.FIO,									-- фамилия имя отчество
	[COL_3]	 = ISNULL(KEP.POST_NAME,''),							-- замещаемая должность граждансткой службы
	[COL_4]	 = CASE	WHEN D_ST.KAT_GOS_CODE = 1 THEN 'Рукводители'				-- категория должности
			WHEN D_ST.KAT_GOS_CODE = 2 THEN 'Помощники (советники)'
			WHEN D_ST.KAT_GOS_CODE = 3 THEN 'Специалисты'
			WHEN D_ST.KAT_GOS_CODE = 4 THEN 'Обеспечивающие специалисты'
			ELSE ''
		   END,										
	[COL_5]	 = CASE	WHEN D_ST.GR_GOS_CODE = 1 THEN 'Высшая'					-- группа должности
			WHEN D_ST.GR_GOS_CODE = 2 THEN 'Главная'	
			WHEN D_ST.GR_GOS_CODE = 3 THEN 'Ведущая'	
			WHEN D_ST.GR_GOS_CODE = 4 THEN 'Старшая'	
			WHEN D_ST.GR_GOS_CODE = 5 THEN 'Младшая'	
			ELSE ''
		   END,
	[COL_6]	 = CONVERT(VARCHAR(10),P.BIRTHDATE,104),				-- дата рождения
	[COL_7]	 = CONVERT(VARCHAR(10),KEP.DATE_BEGIN,104),				-- дата поступления на службу в государсвтенный орган
	[COL_8]	 = CONVERT(VARCHAR(10),EDP.DATE,104),					-- дата назначения на должность
	[COL_9]	 = '',							-- Срок действия служебного контракта 
	[COL_10] = SUBSTRING((dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1)), 1,  charindex('м.' , dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1))+2),				-- Стаж государственной гражданской службы (лет, мес.)
	[COL_11] = SUBSTRING((dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)), 1,  charindex('м.' , (dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)))+2),	-- Стаж государственной гражданской службы для назначения пенсии за выслугу лет 
	[COL_12] = CASE WHEN ISNULL(PE.SCHOOL,'') = '' THEN  ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'')
				ELSE ltrim(rtrim(ISNULL(PE.SCHOOL,''))) + ', ' + ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'') END ,	-- учебное заведение (образование) и дата диплома (образование)
	[COL_13] = ISNULL(PE.SPEC,''),								-- специальность (образование)
	[COL_14] = CASE	WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	-- ученая степень, ученое звание , дата присвоения ученой степени, ученого звания
			ELSE (SELECT NAME FROM ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK)
		   END + 
		   CASE	WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 THEN ''
			ELSE CASE WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	
				  ELSE ', '
			     END + (SELECT NAME FROM ACAD_STATUS WHERE LINK = P.ACAD_STATUS_LINK)
		   END
		   + CASE WHEN isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE,104),'') = '' THEN ''
			  ELSE 
				CASE WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 AND ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''
				  ELSE ', '
				 END + isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE, 104),'') 
			 END ,
	[COL_15] = ltrim(RTRIM(ISNULL(EC.CHIN_NAME,'')))  
			 + CASE WHEN ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'') = '' THEN ''
				  else
				    case when ISNULL(EC.CHIN_NAME,'') = '' THEN ''
					  ELSE ', ' 
					 END + ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'')
				END  ,				-- наименование классного чина ,  дата присвоения чина
	[COL_16] = ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'')
				 +  CASE WHEN ISNULL(EA.ATT_NAME,'') = '' THEN ''
					else	
						CASE WHEN ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'') = '' THEN ''
							ELSE ', ' 
					   END + 	ISNULL(EA.ATT_NAME,'')
				   	END 	,				-- дата проведения аттестации, решение аттестационной комиссии

	[COL_17] =  CASE WHEN ISNULL(EP.PLACE,'')= '' 
					 AND  ISNULL(EP.PROG_NAME,'') = '' 
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = ''
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') = ''
					 AND  ISNULL(EP.[TIME],'') = ''
						THEN ''
				 	 ELSE 
						'Проф.переподготовка: ' + (CASE WHEN  ISNULL(EP.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EP.PLACE,''))) + '; ' END )  
										+   (CASE WHEN ISNULL(EP.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EP.PROG_NAME,''))) + '"; ' end )
										+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') =  '' THEN  ''
												ELSE 
													' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') + '; '
												END )	
										+ (CASE WHEN ISNULL(EP.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EP.[TIME]),'') + '; ' END )
					 END 
					, -- проф.переподготовка, наименование учреждения , наименование программы обучения, дата обучения, время обучения.
	
	[COL_18] =  CASE WHEN ISNULL(EI.PLACE,'')= '' 
				 AND  ISNULL(EI.PROG_NAME,'') = '' 
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = ''
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') = ''
				 AND  ISNULL(EI.[TIME],'') = ''
					THEN ''
			 	 ELSE 
					'Последнее повышение квалификации: ' + (CASE WHEN  ISNULL(EI.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EI.PLACE,''))) + '; ' END )  
									+   (CASE WHEN ISNULL(EI.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EI.PROG_NAME,''))) + '"; ' end )
									+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') =  '' THEN  ''
											ELSE 
												' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') + '; '
											END )	
									+ (CASE WHEN ISNULL(EI.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EI.[TIME]),'') + '; ' END )
				 END 
				, -- последнее повышение квалификации: наименование учреждения , наименование программы обучения, дата обучения, время обучения.
	[COL_19] = LTRIM(rtrim(ISNULL(s.fio,''))), -- фамилия имя отчество лица, замещающего данного гражданского служащего			
-------------------------------------------------------------------------------------------------------------------------------------------------------
	[SUBDIV]	= ISNULL(KEP.SUBDIV_NAME,''),
	[SUBDIV_C]	= ISNULL(KEP.SUBDIV_CODE,'')
FROM	KU_EMPL_PLACING_FN(@dDate2) KEP
	LEFT JOIN PERSON P ON P.LINK = KEP.PERS_LINK
	LEFT JOIN DICTIONARY_STAFF_FN(@dDate2) D_ST ON  KEP.STAFF_LINK = D_ST.STAFF_LINK
	LEFT JOIN #EMPL_DATE_POST EDP ON EDP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_CHIN EC ON EC.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_ATTEST EA ON EA.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_PROFP EP ON EP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_INCQUAL EI ON EI.EMPL_LINK = KEP.LINK
	LEFT JOIN #PERS_EDUC PE ON PE.PERS_LINK = KEP.PERS_LINK
	LEFT JOIN #PERS_AWARD PA ON PA.PERS_LINK = KEP.PERS_LINK
	LEFT JOIN #SUBST s ON s.subst_empl_link = KEP.LINK
WHERE	KEP.LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS)		-- СОТРУДНИКИ ИЗ ФИЛЬТРА
  	AND D_ST.GOSSL IN (1,2,3, 4)
ORDER	BY KEP.SUBDIV_CODE

-------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------
DROP TABLE #EMPL_DATE_POST
DROP TABLE #EMPL_CHIN
DROP TABLE #EMPL_ATTEST
DROP TABLE #EMPL_PROFP
DROP TABLE #EMPL_INCQUAL
DROP TABLE #PERS_EDUC
DROP TABLE #PERS_AWARD

GO


GRANT EXECUTE ON dbo.[REP_TMP_OTS_GS] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_REPL_KADR_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_REPL_KADR_GS]

GO

CREATE PROCEDURE [dbo].REP_REPL_KADR_GS
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS

DECLARE @dDate1 DATETIME, @dDate2 DATETIME


SET @dDate1 = dbo.ConvertDMY2Date(1,1,@cYear1) 

IF @nCombo1 = 1 	
	SET @dDate2 = dbo.ConvertDMY2Date(30,6,@cYear1) 
IF @nCombo1 = 2 
	SET @dDate2 = dbo.DateEndOfYear(@dDate1) 


-- ПРИНЯТЫЕ
declare @FLAG_PER	INT			-- флаг (с учетом переведеных сотрудников, либо только принятые)

SELECT	T.*
INTO	#REPORT_TABLE
FROM	(
	SELECT	
		[TYPE]		=	1,
		DATE		=	IM.DATE_BEGIN,
		SUB_LINK	=	S.SUBDIV_LINK,
		SUB_NAME	=	S.SUBDIV_NAME,
		POST_NAME	=	S.POST_NAME,
		FIO			=	LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),
		OSNOV		=	'приказ № ' + RTRIM(LTRIM(O.NUMBER)) +					-- ОСНОВАНИЕ
			   ' от ' + rtrim(ltrim(CONVERT(VARCHAR(10),O.DATE,104))),
		PRICHINA	=	isnull(IM.USL_PR,''),
		
		[SUBDIVC]= S.SUBDIV_CODE,
		[EMPL]	= IM.EMPL_LINK	,							-- КЛЮЧЕВОЕ ПОЛЕ
		[CAT_G_CODE] = isnull(s.kat_gos_CODE,0)  -- категория гос должности 1-Руководители, 2-Помощники(советники),3-Специалисты,4-Обеспечивающие специалисты
	FROM	dbo.ITEM_MOVE IM
		LEFT JOIN dbo.DICTIONARY_STAFF_ALL S ON S.LINK_UP = IM.STAFF_LINK AND IM.DATE_BEGIN BETWEEN S.DATE_BEGIN AND S.DATE_END
		LEFT JOIN dbo.EMPL E ON E.LINK = IM.EMPL_LINK
		LEFT JOIN dbo.PERSON P ON E.PERS_LINK = P.LINK
		LEFT JOIN dbo.ORDERS O ON IM.ORDER_LINK = O.LINK
	WHERE	IM.ACTIVE = 1
		--AND IM.NEW_FACE = 1--IN (0,1)
		AND (IM.[TYPE] IN (1,2) OR IM.NEW_FACE = 1)
		AND IM.DATE_BEGIN BETWEEN @dDATE1 AND @dDATE2
		AND E.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
		AND s.gossl in (1,2,3, 4)
	) T
ORDER BY T.SUBDIVC, T.DATE


-- ПРИНЯТЫЕ и ПЕРЕВЕДЕННЫЕ
SELECT [TYPE],	DATE,SUB_LINK,SUB_NAME,POST_NAME,FIO,OSNOV,PRICHINA, CAT_G_CODE
INTO #REPORT_NEW_TABLE
FROM #REPORT_TABLE

---------------------------------
-- ЗАМЕЩАЮЩИЕ
SELECT		
		[TYPE]		=	2,
		DATE		=	SU.DATE_BEGIN,
		SUB_LINK	=	SU.S_SUBDIV_LINK,
		SUB_NAME	=	SU.S_SUBDIV,
		POST_NAME	=	SU.S_POST,
		FIO			=	SU.FIO,
		OSNOV		=	RTRIM(ISNULL(SU.REASON,'')) + 								-- ОСНОВАНИЕ замещения
		   ' приказ № ' + RTRIM(LTRIM(SU.NUMBER)) + ' от ' + CONVERT(VARCHAR(10),SU.[DATE],104),
		PRICHINA	=	ISNULL(SU.REASON,'') ,
		[EMPL]	= SU.EMPL_LINK,
		[CAT_G_CODE] = isnull(s.kat_gos_CODE,0)  -- категория гос должности 1-Руководители, 2-Помощники(советники),3-Специалисты,4-Обеспечивающие специалисты
INTO	#REPORT_SUBST_TABLE
FROM dbo.SUBST SU 
	inner join dbo.KU_EMPL_PLACING_FN(@dDate2) kep on kep.link = SU.subst_empl_link
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) S ON S.STAFF_LINK = kep.STAFF_LINK 
	LEFT JOIN dbo.EMPL E ON E.LINK = SU.EMPL_LINK
	LEFT JOIN dbo.PERSON P ON P.LINK = E.PERS_LINK 
	
WHERE	SU.DATE_BEGIN BETWEEN @dDATE1 AND @dDATE2
	AND SU.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND SU.ACTIVE = 1
	AND s.gossl in (1,2,3, 4)

 
INSERT INTO #REPORT_NEW_TABLE
SELECT [TYPE],DATE,SUB_LINK,SUB_NAME,POST_NAME,FIO,OSNOV,PRICHINA, CAT_G_CODE
FROM #REPORT_SUBST_TABLE

DECLARE @ZAM_COUNT INT , @ZAM_COUNT_1 INT, @ZAM_COUNT_2 INT, @ZAM_COUNT_3 INT, @ZAM_COUNT_4 INT,
		@NAZ_CNT INT, @NAZ_CNT_1 INT, @NAZ_CNT_2 INT , @NAZ_CNT_3 INT, @NAZ_CNT_4 int
--Количество замещающих и назначенных без конкурса
SET @NAZ_CNT = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE)
SET @NAZ_CNT_1 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE WHERE  [CAT_G_CODE] = 1)
SET @NAZ_CNT_2 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE WHERE  [CAT_G_CODE] = 2)
SET @NAZ_CNT_3 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE WHERE  [CAT_G_CODE] = 3)
SET @NAZ_CNT_4 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE WHERE  [CAT_G_CODE] = 4)


SELECT *,
		NAZ_CNT = @NAZ_CNT,
		NAZ_CNT1 = @NAZ_CNT_1,
		NAZ_CNT2 = @NAZ_CNT_2,
		NAZ_CNT3 = @NAZ_CNT_3,
		NAZ_CNT4 = @NAZ_CNT_4 
	--	UVOL_COUNT	=	@UVOL_COUNT
FROM #REPORT_NEW_TABLE
ORDER BY SUB_NAME,FIO

DROP TABLE #REPORT_NEW_TABLE
DROP TABLE #REPORT_SUBST_TABLE

DROP TABLE #REPORT_TABLE



GO


GRANT EXECUTE ON dbo.[REP_REPL_KADR_GS] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[UNLOAD_S_ACCOUNTS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[UNLOAD_S_ACCOUNTS]

GO
CREATE PROCEDURE [dbo].UNLOAD_S_ACCOUNTS 
--Список выгружаемых счетов передается через временную таблицу #tmp_UNLOAD_S_ACCOUNTS (LINK INT)
AS

BEGIN

SET NOCOUNT ON

IF OBJECT_ID('TEMPDB..#tmp_UNLOAD_S_ACCOUNTS','U') IS NULL
BEGIN
	PRINT 'Не найдена таблица со списком выгружаемых счетов #tmp_UNLOAD_S_ACCOUNTS (LINK INT)' 
	RETURN 1
END

IF OBJECT_ID('TEMPDB..#OUT','U') IS NOT NULL
	DROP TABLE #OUT

CREATE TABLE #OUT (ORD INT IDENTITY(1,1), TXT VARCHAR(8000) )

INSERT INTO #OUT (TXT)
SELECT
'--Добавление счетов в план счетов
--Сгенерировано скриптом: EXECUTE [dbo].UNLOAD_S_ACCOUNTS ' 

INSERT INTO #OUT (TXT)
SELECT
'
set xact_abort ON
BEGIN TRAN
' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT
'

IF OBJECT_ID(''TEMPDB..#TMP_S_ACCOUNTS'',''U'') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS

CREATE TABLE #TMP_S_ACCOUNTS (
	[LINK] int ,
	[NAME] varchar(150) NOT NULL ,
	[KSU] tinyint NOT NULL ,
	[LINK_SELF] int NULL ,
	[CODE_SELF] VARCHAR(50),
	[ORDERS] smallint NOT NULL ,
	[ZABALANS] tinyint NOT NULL ,
	[s_active] tinyint NOT NULL ,
	[s_passive] tinyint NOT NULL ,
	[s_packed] tinyint NOT NULL ,
	[s_kassa] tinyint NOT NULL ,
	[p_DVZ] tinyint NOT NULL ,
	[ap_KBK] tinyint NOT NULL ,
	[ap_EKR] tinyint NOT NULL ,
	[ap_DEP] tinyint NOT NULL ,
	[ap_SUB] tinyint NOT NULL ,
	[ap_EMP] tinyint NOT NULL ,
	[ap_NOMEN] tinyint NOT NULL ,
	[ap_INV] tinyint NOT NULL ,
	[ap_KAU] tinyint NOT NULL ,
	[ap_DEP_ACC] tinyint NOT NULL ,
	[ap_TMC] tinyint NOT NULL ,
	[ap_INDATE] tinyint NOT NULL ,
	[ap_AP1] tinyint NOT NULL ,
	[ap_AP2] tinyint NOT NULL ,
	[ap_AP3] tinyint NULL ,
	[p_NOCONTROL] tinyint NOT NULL ,
	[cSource] char(1) NOT NULL ,
	[cSinth] char(3) NOT NULL ,
	[cAnalit] char(2) NOT NULL ,
	[cUser] varchar(4) NOT NULL ,
	[p_UZAB] tinyint NOT NULL ,
	[KBK_TYPE] tinyint NOT NULL ,
	[CODE] VARCHAR(50),
	[p_EKR] tinyint NOT NULL ,
	[ANALIT_EKR] int NULL ,
	[p_KASSA] tinyint NOT NULL ,
	[NOMEN_TYPE] tinyint NOT NULL ,
	[p_DATE] tinyint NOT NULL ,
	[OB_KBK] tinyint NOT NULL ,
	[OB_EKR] tinyint NOT NULL ,
	[OB_DEP] tinyint NOT NULL ,
	[OB_SUB] tinyint NOT NULL ,
	[OB_EMP] tinyint NOT NULL ,
	[OB_NOMEN] tinyint NOT NULL ,
	[OB_INV] tinyint NOT NULL ,
	[OB_KAU] tinyint NOT NULL ,
	[OB_DEP_ACC] tinyint NOT NULL ,
	[OB_TMC] tinyint NOT NULL ,
	[OB_AP1] tinyint NOT NULL ,
	[OB_AP2] tinyint NOT NULL ,
	[OB_AP3] tinyint NOT NULL ,
	[B_YEAR0] tinyint NOT NULL ,
	[BUH_TYPE] tinyint NOT NULL ,
	[ISUSED] tinyint NOT NULL 
	)
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT 'INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(' 
	+ COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[LINK]))),'NULL')
	+ ',' + ISNULL('''' + RTRIM(LTRIM(NAME)) + '''',NULL)
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[KSU]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[LINK_SELF]))),'NULL')
	+ ',' + ISNULL('''' + RTRIM(LTRIM((SELECT TOP 1 CODE FROM dbo.S_ACCOUNTS WHERE LINK = T.LINK_SELF))) + '''',NULL)
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ORDERS]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ZABALANS]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[s_active]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[s_passive]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[s_packed]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[s_kassa]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_DVZ]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_KBK]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_EKR]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_DEP]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_SUB]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_EMP]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_NOMEN]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_INV]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_KAU]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_DEP_ACC]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_TMC]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_INDATE]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_AP1]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_AP2]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ap_AP3]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_NOCONTROL]))),'NULL')
	+ ',' + ISNULL('''' + RTRIM(LTRIM(cSource)) + '''',NULL)
	+ ',' + ISNULL('''' + RTRIM(LTRIM(cSinth)) + '''',NULL)
	+ ',' + ISNULL('''' + RTRIM(LTRIM(cAnalit)) + '''',NULL)
	+ ',' + ISNULL('''' + RTRIM(LTRIM(cUser)) + '''',NULL)
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_UZAB]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[KBK_TYPE]))),'NULL')
	+ ',' + ISNULL('''' + RTRIM(LTRIM((case when ([cSource] <> '') then ([cSource] + '.') else '' end + rtrim([cSinth]) + case when ([cAnalit] <> '') then ('.' + [cAnalit]) else '' end + case when ([cUser] <> '') then ('/' + [cUser]) else '' end))) + '''',NULL)
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_EKR]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ANALIT_EKR]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_KASSA]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[NOMEN_TYPE]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[p_DATE]))),'NULL')	
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_KBK]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_EKR]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_DEP]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_SUB]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_EMP]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_NOMEN]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_INV]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_KAU]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_DEP_ACC]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_TMC]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_AP1]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_AP2]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[OB_AP3]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[B_YEAR0]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[BUH_TYPE]))),'NULL')
	+ ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ISUSED]))),'NULL')	
	+ ')'
	+ CASE WHEN (ROW_NUMBER() OVER (ORDER BY NAME)) % 25 = 0 THEN CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) ELSE '' END
FROM 
	#tmp_UNLOAD_S_ACCOUNTS A INNER JOIN dbo.S_ACCOUNTS T ON A.LINK = T.LINK

-------------------------------------------------------------------
INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT
'
IF OBJECT_ID(''TEMPDB..#TMP_S_ACCOUNTS_KAU'',''U'') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_KAU

CREATE TABLE #TMP_S_ACCOUNTS_KAU (
	[ACCOUNT] INT,
	[KAU] varchar(50)
)
GO' + CHAR(13) + CHAR(10)


INSERT INTO #OUT (TXT)
SELECT 'INSERT INTO #TMP_S_ACCOUNTS_KAU (ACCOUNT,KAU) 
VALUES('
 + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ACCOUNT]))),'NULL')
 + ',' + ISNULL('''' + RTRIM(LTRIM(K.CODE)) + '''',NULL)
 + ')' + CASE WHEN (ROW_NUMBER() OVER (ORDER BY SA.CODE)) % 30 = 0 THEN CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) ELSE '' END
FROM 
	#tmp_UNLOAD_S_ACCOUNTS A INNER JOIN dbo.S_ACCOUNTS_KAU T ON T.ACCOUNT = A.LINK
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = T.ACCOUNT
	INNER JOIN dbo.KAU K ON K.LINK = LINK_KAU

INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)	

----------------------------------------------------------------------
INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT
'
IF OBJECT_ID(''TEMPDB..#TMP_JOURNAL_OPERATION_ACCOUNTS'',''U'') IS NOT NULL
	DROP TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS

CREATE TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS (
	[ACCOUNT] INT,
	[JURN] varchar(50),
	[GK] bit
)
GO' + CHAR(13) + CHAR(10)


INSERT INTO #OUT (TXT)
SELECT 'INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES('
 + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ACCOUNT]))),'NULL')
 + ',' + ISNULL('''' + RTRIM(LTRIM(K.CODE)) + '''',NULL)
 + ',' + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[GK]))),'NULL')
 + ')' + CASE WHEN (ROW_NUMBER() OVER (ORDER BY SA.CODE)) % 30 = 0 THEN CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) ELSE '' END
FROM 
	#tmp_UNLOAD_S_ACCOUNTS A INNER JOIN dbo.JOURNAL_OPERATION_ACCOUNTS T ON T.ACCOUNT = A.LINK
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = T.ACCOUNT
	INNER JOIN dbo.JOURNAL_OPERATION K ON K.LINK = JURN_LINK

INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)	

---------------------------------------------------------------

INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT
'
IF OBJECT_ID(''TEMPDB..#TMP_S_ACCOUNTS_SGU'',''U'') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_SGU

CREATE TABLE #TMP_S_ACCOUNTS_SGU (
	[ACCOUNT] INT,
	[SGU] varchar(50),
	[COMMENT] varchar(254)
)
GO' + CHAR(13) + CHAR(10)


INSERT INTO #OUT (TXT)
SELECT 'INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES('
 + COALESCE(RTRIM(LTRIM(convert(varchar(100), T.[ACCOUNT]))),'NULL')
 + ',' + ISNULL('''' + RTRIM(LTRIM(K.CODE)) + '''',NULL)
+ ',' + ISNULL('''' + RTRIM(LTRIM(T.COMMENT)) + '''',NULL)
 + ')' + CASE WHEN (ROW_NUMBER() OVER (ORDER BY SA.CODE)) % 30 = 0 THEN CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) ELSE '' END
FROM 
	#tmp_UNLOAD_S_ACCOUNTS A INNER JOIN dbo.S_ACCOUNTS_SGU T ON T.ACCOUNT = A.LINK
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = T.ACCOUNT
	INNER JOIN dbo.KOSGU K ON K.LINK = LINK_SGU

INSERT INTO #OUT (TXT)
SELECT 'GO' + CHAR(13) + CHAR(10)
	
INSERT INTO #OUT (TXT)
SELECT '
---- Обновление данных
IF Exists(select 1 from sys.columns where Name = N''INSERTED_LINK'' and Object_ID = Object_ID(N''dbo.S_ACCOUNTS''))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
ALTER TABLE dbo.S_ACCOUNTS ADD INSERTED_LINK INT NULL
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF not exists(select * from sysobjects where id = object_id(''[dbo].[_INSERTED_S_ACCOUNTS]'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1)
CREATE TABLE [dbo].[_INSERTED_S_ACCOUNTS] (
	LINK int ,
	INSERTED_LINK int )
ELSE 
	DELETE FROM dbo._INSERTED_S_ACCOUNTS
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = ''IX_INSERTED_S_ACCOUNTS'')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS] ([LINK]) ON [INDEX]
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = ''IX_INSERTED_S_ACCOUNTS2'')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS] ([INSERTED_LINK]) ON [INDEX]
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
INSERT INTO dbo.S_ACCOUNTS (INSERTED_LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED)
OUTPUT INSERTED.LINK, INSERTED.INSERTED_LINK INTO [dbo].[_INSERTED_S_ACCOUNTS] (LINK, INSERTED_LINK)
SELECT LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED
FROM #TMP_S_ACCOUNTS T
WHERE NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS SA WHERE SA.CODE = T.CODE)
' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
UPDATE SA SET 
	SA.LINK_SELF = (SELECT TOP 1 LINK FROM dbo.S_ACCOUNTS WHERE CODE = T.CODE_SELF)
FROM
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = A.LINK
	INNER JOIN #TMP_S_ACCOUNTS T ON T.LINK = A.INSERTED_LINK
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
INSERT INTO dbo.S_ACCOUNTS_KAU(ACCOUNT,LINK_KAU)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KAU K WHERE K.CODE = T.KAU)
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_KAU T ON T.ACCOUNT = A.INSERTED_LINK
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
INSERT INTO dbo.JOURNAL_OPERATION_ACCOUNTS(ACCOUNT,JURN_LINK,GK)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.JOURNAL_OPERATION K WHERE K.CODE = T.JURN),
	GK = T.GK
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_JOURNAL_OPERATION_ACCOUNTS T ON T.ACCOUNT = A.INSERTED_LINK
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
INSERT INTO dbo.S_ACCOUNTS_SGU(ACCOUNT,LINK_SGU,COMMENT)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KOSGU K WHERE K.CODE = T.SGU),
	COMMENT = T.COMMENT
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_SGU T ON T.ACCOUNT = A.INSERTED_LINK
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF Exists(select 1 from sys.columns where Name = N''INSERTED_LINK'' and Object_ID = Object_ID(N''dbo.S_ACCOUNTS''))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = ''IX_INSERTED_S_ACCOUNTS'')
DROP INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = ''IX_INSERTED_S_ACCOUNTS2'')
DROP INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO' + CHAR(13) + CHAR(10)

INSERT INTO #OUT (TXT)
SELECT '
IF exists(select * from sysobjects where id = object_id(''[dbo].[_INSERTED_S_ACCOUNTS]'') and OBJECTPROPERTY(id, N''IsUserTable'') = 1)
DROP TABLE [dbo].[_INSERTED_S_ACCOUNTS]
GO' + CHAR(13) + CHAR(10)


INSERT INTO #OUT (TXT)
SELECT
'
COMMIT TRAN
' + 'GO'+ CHAR(13) + CHAR(10)

SELECT TXT as [--txt] FROM #OUT ORDER BY ORD

SET NOCOUNT OFF

end

GO


GRANT EXECUTE ON dbo.[UNLOAD_S_ACCOUNTS] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_UVOL_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_UVOL_GS]

GO

CREATE PROCEDURE [dbo].REP_UVOL_GS
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS

DECLARE @dDate1 DATETIME, @dDate2 DATETIME


SET @dDate1 = dbo.ConvertDMY2Date(1,1,@cYear1) 

IF @nCombo1 = 1 	
	SET @dDate2 = dbo.ConvertDMY2Date(30,6,@cYear1) 
IF @nCombo1 = 2 
	SET @dDate2 = dbo.DateEndOfYear(@dDate1) 


-- УВОЛЕННЫЕ
SELECT		
		[TYPE]		=	2,
		DATE		=	DF.DIS_DATE,
		SUB_LINK	=	DF.SUBDIV_LINK,
		SUB_NAME	=	DF.SUBDIV,
		POST_NAME	=	DF.POST,
		FIO			=	DF.FIO,
		OSNOV		=	RTRIM(ISNULL(DF.REASON_NAME,'')) + 								-- ОСНОВАНИЕ замещения
		   ' приказ № ' + RTRIM(LTRIM(DF.NUMBER)) + ' от ' + CONVERT(VARCHAR(10),DF.[DATE],104),
		PRICHINA	=	ISNULL(DF.OSN,'') ,
		[EMPL]	= DF.EMPL_LINK
INTO	#REPORT_DIS_TABLE
FROM dbo.DIS_FACE DF 
	inner join dbo.KU_EMPL_PLACING_FN(@dDate2) kep on kep.link = DF.empl_link
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) S ON S.STAFF_LINK = kep.STAFF_LINK  AND  kep.DATE_SACK BETWEEN S.DATE_BEGIN AND S.DATE_END
WHERE	DF.DIS_DATE BETWEEN @dDate1 AND @dDate2
	AND DF.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND DF.ACTIVE = 1
	AND s.gossl in (1,2,3, 4)

SELECT [TYPE],	DATE,SUB_LINK,SUB_NAME,POST_NAME,FIO,OSNOV,PRICHINA
INTO #REPORT_NEW_TABLE
FROM #REPORT_DIS_TABLE


SELECT * FROM #REPORT_NEW_TABLE


DROP TABLE #REPORT_NEW_TABLE
DROP TABLE #REPORT_DIS_TABLE




GO


GRANT EXECUTE ON dbo.[REP_UVOL_GS] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_VAC_POST_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_VAC_POST_GS]

GO

-- информация о вакантных длжностях
CREATE PROCEDURE [dbo].REP_VAC_POST_GS
	@dDate1 datetime	/* Расчетная дата */
-- REP_VAC_POST_GS '20140630'
AS
	DECLARE @free_stakes	tinyint		-- 0 - выбирать все должности, 1 - только должности со свободными ставками
	SET @free_stakes = 1
	SELECT 
		SUB_LINK	=	DS.SUBDIV_LINK,
		SUB_NAME	=	DS.SUBDIV_NAME,
		POST_NAME	=	DS.POST_NAME,
		POST_COUNT	=	DS.FREE_STAKES,
		DATE_BEGIN  =   SS.DATE_BEGIN,
		COMMENT		=	'',
		COMM_PLAN =  '',
		VAC_ALL		=	'',
		EMPL_POST	=	'',
		EMPL_NAME	=	''
	FROM DBO.DICTIONARY_STAFF_FN(@dDate1)  DS
	INNER JOIN (	SELECT	[STAFF_LINK] = sh.LINK,
			[FREE_STAKES] = s.num_stake - isnull(t.num_stake, 0),
			DATE_BEGIN = s.date_begin 
	FROM	dbo.staff_head sh 
			INNER JOIN dbo.staff s ON s.link_up = sh.link and s.date_begin = isnull((SELECT max(date_begin) FROM staff WHERE link_up=s.link_up and @dDATE1 >= date_begin),
																					(SELECT min(date_begin) FROM staff WHERE link_up=s.link_up and @dDATE1 <= date_begin))
			left join (select STAFF_HEAD, [num_stake] = sum(case when (STAFF_OPT1.OPT = 1 and sei.status = 2) or (STAFF_OPT3.OPT = 1 and sei.status = 3) then 0 else sei.num_stake end)
					   from SA_EMPLS_INFO_PERIOD(@dDATE1, @dDATE1, default, default) sei
							inner join (select OPT = dbo.sa_get_option_by_code('KADRY_OPT1')) STAFF_OPT1 on 1 = 1 
							inner join (select OPT = dbo.sa_get_option_by_code('KADRY_OPT3')) STAFF_OPT3 on 1 = 1
					   where notwork = 0
					   group by STAFF_HEAD
					  ) t on sh.link = t.STAFF_HEAD
	) ss on ss.STAFF_LINK = ds.link 
	WHERE @dDATE1 BETWEEN DS.DATE_BEGIN AND DS.DATE_END
	AND DS.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND DS.DEL_SUBDIV = 0 AND DS.FREE_STAKES >0 
	AND ds.gossl in (1,2,3, 4)
	ORDER BY SUB_LINK
GO


GRANT EXECUTE ON dbo.[REP_VAC_POST_GS] TO PUBLIC

GO




GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_O_OTHER_FILL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_O_OTHER_FILL]

GO

CREATE   PROCEDURE dbo.SD_O_OTHER_FILL
@LINK INT
AS  

DECLARE @Month int, 
		@Year int, 
		@Link1 int,
		@DEP_LINK INT,
		@Date DATETIME	

SELECT 
	@Year = YEAR(S.DATE_CALC),
	@Month = MONTH(S.DATE_CALC),
	@DEP_LINK = S.LINK_DEP,
	@Date = dbo.DATEENDOFMONTH(S.DATE_CALC)
FROM 
	dbo.SDOC S
WHERE 
	S.LINK = @LINK

IF @DEP_LINK IS NULL
	Set @DEP_LINK = Coalesce( (SELECT TOP 1 ZB_LINK FROM dbo.KS_OPTIONS_ZB), dbo.GetOwnDepLink())

---Справочник тарифов
--!!! Ставки берет от тарифа Общий и не учитывает шкалу. При необходимости требуется переделать
CREATE TABLE #RANGE(LINK_PAYS INT, PREDEL NUMERIC(18,2), [PERCENT] NUMERIC(18,2))
INSERT INTO #RANGE (LINK_PAYS, PREDEL,  [PERCENT])
SELECT 
	DR.LINK_PAYS, PREDEL, [PERCENT]
FROM 
	dbo.PAYS P
	INNER JOIN dbo.DICTIONARY_RANGE DR ON P.LINK = DR.LINK_PAYS
WHERE
	P.[OBJECT] = 3 AND P.WAY_CALC = 5
	AND TARIF = 1
	AND DR.[DATE]= (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE DR1 
		WHERE DR1.TARIF = DR.TARIF AND LINK_PAYS = P.LINK AND [DATE] <= @Date ORDER BY [DATE] DESC) 	

DECLARE @COLUMN_REF_PAY_MROT_T3 INT
SET @COLUMN_REF_PAY_MROT_T3 = (SELECT TOP 1 LINK FROM dbo.S_OBJECTS WHERE CODE = 'COLUMN_REF_PAY_MROT_T3')

----Инвалиды и процент по ним
CREATE TABLE #INV ([PERCENT] NUMERIC(18,2), LINK INT)
INSERT  INTO #INV ([PERCENT], LINK)
SELECT
	[PERCENT] = MP.summa, I.PERS_LINK
FROM	
	dbo.MINROT_PAYS MP
	INNER JOIN dbo.PERS_INVALID I ON 1=1
WHERE
	[OBJECT] = @COLUMN_REF_PAY_MROT_T3
	AND
	LINK_MINROT = (SELECT TOP 1 LINK FROM MINROT WHERE PERIOD<=@Date ORDER BY PERIOD DESC)
	AND
	dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,@Month,@Year))
		BETWEEN I.DATE_BEGIN AND COALESCE(I.DATE_END,'29990101')	

--===РАСЧЁТ СКИДКИ
--Информация о предельном размере скидки
CREATE TABLE #SKIDKA (LINK_INC INT, PREDEL NUMERIC(18,2))
INSERT INTO #SKIDKA (LINK_INC, PREDEL)
SELECT TI.LINK, D.PREDEL
FROM 
	dbo.Salary_deduct_esn(@Date) D	
	INNER JOIN dbo.DICTIONARY_TYP_INCOMS TI ON TI.REF_DEDUCT = D.REF_PAY
	AND dbo.SA_GET_OPTION_BY_CODE('ESNTR_OPTIONS_OPT3') = 1 -- Предоставлять скидки 
	
--База расчёта
CREATE TABLE #BASE (LINK_TAX INT, LINK_PAY INT)
INSERT INTO #BASE (LINK_TAX, LINK_PAY)
SELECT T.LINK_TAX, T.LINK_PAYS 
FROM
	dbo.PAYS P  
	INNER JOIN dbo.TAX_REF T ON T.LINK_TAX = P.LINK
WHERE
	P.[OBJECT] = 3 AND P.WAY_CALC = 5	

--Базовые суммы по физлицам в разрезе кодов дохода и источников
DECLARE @LINK_EKR211 INT, @LINK_EKR212 INT, @LINK_EKR213 INT
SET @LINK_EKR211 = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '211')
SET @LINK_EKR212 = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '212')
SET @LINK_EKR213 = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '213')

DECLARE @SALARY_PROV_OPT4 TINYINT
SET @SALARY_PROV_OPT4 = dbo.sa_get_option_by_code('SALARY_PROV_OPT4')

CREATE TABLE #SUMMA (LINK_TAX INT, LINK_PERS INT, LINK_INC INT, LINK_VKR INT, LINK_EKR INT, SUMMA_M NUMERIC(18,2),SUMMA NUMERIC(18,2))
INSERT INTO #SUMMA (LINK_TAX, LINK_PERS, LINK_INC, LINK_VKR, LINK_EKR, SUMMA_M, SUMMA)
SELECT
	B.LINK_TAX,
	ISNULL(J.PERS_LINK,E.PERS_LINK),
	P.LINK_INC,
	LINK_VKR,
	CASE WHEN @SALARY_PROV_OPT4 = 0 THEN 
		CASE WHEN COALESCE(J.LINK_EKR,@LINK_EKR213) = @LINK_EKR211 THEN @LINK_EKR213 ELSE COALESCE(J.LINK_EKR,@LINK_EKR213) END
	ELSE 
		CASE WHEN COALESCE(J.LINK_EKR,@LINK_EKR213) IN (@LINK_EKR211, @LINK_EKR212) THEN @LINK_EKR213 ELSE COALESCE(J.LINK_EKR,@LINK_EKR213) END				
	END,	
	SUMMA_M = SUM(CASE WHEN MONTH(J.PERIOD_BEGIN) = @Month THEN SUMMA ELSE 0 END),
	SUMMA  = SUM(SUMMA)
FROM
	#BASE B 
	INNER JOIN dbo.PAYS P ON P.LINK = B.LINK_PAY
	INNER JOIN dbo.CALCULATE_JURNAL J ON J.LINK_PAYS = P.LINK
	INNER JOIN dbo.EMPL E ON E.LINK = J.LINK_EMPL
WHERE
	J.LINK_DEP = @DEP_LINK
	AND
	P.[OBJECT] = 1 
	AND
	YEAR(J.PERIOD_BEGIN) = @Year AND MONTH(J.PERIOD_BEGIN) <= @Month
	--AND
	--J.LINK_EKR <> @LINK_EKR213
GROUP BY
	B.LINK_TAX, ISNULL(J.PERS_LINK,E.PERS_LINK), P.LINK_INC, LINK_VKR, J.LINK_EKR

		
-- Базовые суммы по физлицам в разрезе кодов дохода
CREATE TABLE #SUMMA2 (LINK_TAX INT, LINK_PERS INT, LINK_INC INT, SUMMA_M NUMERIC(18,2), SUMMA NUMERIC(18,2))
INSERT INTO #SUMMA2 (LINK_TAX, LINK_PERS, LINK_INC, SUMMA_M, SUMMA)
SELECT LINK_TAX, LINK_PERS, LINK_INC, SUM(SUMMA_M), SUM(SUMMA)
FROM #SUMMA
GROUP BY LINK_TAX, LINK_PERS, LINK_INC


--Удалить рассчитанную скидку по данному расчёту, чтобы рассчитать её заново
DELETE FROM dbo.SDOC_DOT_SKIDKI WHERE LINK_UP = @LINK

-- Размер уже предоставленной скидки с начала года в разрезе кодов дохода
CREATE TABLE #SKIDKA_PREV (LINK_TAX INT, LINK_PERS INT, LINK_INC INT, SUMMA NUMERIC(18,2))

INSERT INTO #SKIDKA_PREV (LINK_TAX, LINK_PERS, LINK_INC, SUMMA)
SELECT LINK_TAX, LINK_PERS, LINK_INC, SUM(SUMMA)
FROM 
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DOT_SKIDKI S ON S.LINK_UP = D.LINK
WHERE
	D.LINK_DEP = @DEP_LINK
	AND 
	YEAR(DATE_CALC)	= @Year AND MONTH(DATE_CALC) < @Month
GROUP BY
	LINK_TAX, LINK_PERS, LINK_INC

--
DECLARE @ESNTR_OPTIONS_OPT5 INT
SET @ESNTR_OPTIONS_OPT5 = dbo.SA_GET_OPTION_BY_CODE('ESNTR_OPTIONS_OPT5')

--Предоставленные скидки с предыдущего места работы
CREATE TABLE #PREV_DED (LINK_PERS INT, LINK_INC INT, SUMMA NUMERIC(18,2))
--
INSERT INTO #PREV_DED (LINK_PERS, LINK_INC, SUMMA)
SELECT E.PERS_LINK, LINK_INC = T.LINK, SUMMA = SUM(PD.SUMMA_DED)
FROM 
	dbo.SD_EMPL_PREV_DED PD
	INNER JOIN dbo.DICTIONARY_TYP_INCOMS T with (nolock) ON T.REF_DEDUCT = PD.LINK_DED
	INNER JOIN dbo.EMPL E with (nolock) ON E.LINK = PD.LINK_EMPL
	INNER JOIN dbo.ITEM_MOVE IM with (nolock) ON IM.EMPL_LINK = E.LINK AND IM.ACTIVE = 1 AND IM.NEW_FACE=1 AND IM.[STATUS] IN (1,3) AND IM.DATE_BEGIN <= @Date
	INNER JOIN (
		SELECT E.PERS_LINK, MAX(DATE_BEGIN) AS DATE_BEGIN
		FROM 
			dbo.EMPL E with (nolock)
			INNER JOIN dbo.ITEM_MOVE IM with (nolock) ON IM.EMPL_LINK = E.LINK AND IM.ACTIVE = 1 AND IM.NEW_FACE=1 AND IM.[STATUS] IN (1,3) AND IM.DATE_BEGIN <= @Date
			LEFT JOIN DBO.ITEM_DIS_FACE IDF with (nolock) ON IDF.EMPL_LINK = E.LINK AND IDF.ACTIVE=1 AND COALESCE(IDF.DIS_DATE,'20990101') >= dbo.DateBeginOfMonth(@Date)	
		GROUP BY
			E.PERS_LINK	
	) A ON A.PERS_LINK = E.PERS_LINK AND A.DATE_BEGIN = IM.DATE_BEGIN
WHERE
	E.DEP_LINK = @DEP_LINK
	AND
	YEAR(IM.DATE_begin) = @Year --YEAR(dbo.kd_DateBeginWork(@linkEmpl,null)) = @Year
	AND
	@ESNTR_OPTIONS_OPT5 = 1 --Учитывать вычеты, предоставленные на предыдущем месте работы
GROUP BY
	E.PERS_LINK, T.LINK
	
-- Расчёт скидки за месяц по физлицам в разрезе кодов дохода и источников
INSERT INTO dbo.SDOC_DOT_SKIDKI (LINK_UP, LINK_TAX, LINK_PERS, LINK_INC, LINK_VKR, LINK_EKR, SUMMA, [PERCENT])
SELECT 
	@LINK, S2.LINK_TAX, S2.LINK_PERS, S2.LINK_INC, S.LINK_VKR, S.LINK_EKR,
	--Остаток скидки в пределах месячного дохода
	--CASE WHEN S2.SUMMA_M > CASE WHEN ISNULL(SP.SUMMA,0) < SK.PREDEL THEN (SK.PREDEL - ISNULL(SP.SUMMA,0)) * (S.SUMMA_M / S2.SUMMA_M) ELSE 0 END
	--	THEN CASE WHEN ISNULL(SP.SUMMA,0) < SK.PREDEL THEN (SK.PREDEL - ISNULL(SP.SUMMA,0)) * (S.SUMMA_M / S2.SUMMA_M) ELSE 0 END
	--	ELSE S2.SUMMA_M
	--END,
	(
		CASE WHEN
			--Всего надо скидку
			(CASE WHEN ISNULL(PD.SUMMA,0) + ISNULL(S2.SUMMA,0) > ISNULL(SK.PREDEL,0) THEN ISNULL(SK.PREDEL,0) ELSE ISNULL(PD.SUMMA,0) + ISNULL(S2.SUMMA,0) END) > 0 
		THEN
		(
			--Всего надо скидку
			(CASE WHEN ISNULL(PD.SUMMA,0) + ISNULL(S2.SUMMA,0) > ISNULL(SK.PREDEL,0) THEN ISNULL(SK.PREDEL,0) ELSE ISNULL(PD.SUMMA,0) + ISNULL(S2.SUMMA,0) END) 
			--Уже предоставили
			- ISNULL(SP.SUMMA,0) - ISNULL(PD.SUMMA,0)
		)	
			----пропорционально кодам доходов
			* (S.SUMMA_M / S2.SUMMA_M)
		ELSE
		0 
		END	
	),
	[PERCENT] = ISNULL(I.[PERCENT],DR.[PERCENT])
FROM 
	#RANGE DR --Ставка налога
	INNER JOIN #SUMMA2 S2 ON -- Базовые суммы по физлицам в разрезе кодов дохода
							S2.LINK_TAX = DR.LINK_PAYS
	INNER JOIN #SUMMA S ON --Базовые суммы по физлицам в разрезе кодов дохода и источников
							S.LINK_TAX = S2.LINK_TAX AND S.LINK_PERS = S2.LINK_PERS AND S.LINK_INC = S2.LINK_INC
	INNER JOIN #SKIDKA SK ON --Информация о предельном размере скидки
							SK.LINK_INC = S.LINK_INC
	LEFT JOIN #SKIDKA_PREV SP ON -- Размер уже предоставленной скидки с начала года в разрезе кодов дохода
							SP.LINK_TAX = S2.LINK_TAX AND SP.LINK_PERS = S2.LINK_PERS AND SP.LINK_INC = S2.LINK_INC
	LEFT JOIN #PREV_DED PD ON --Предоставленные скидки с предыдущего места работы
						PD.LINK_PERS = S2.LINK_PERS AND PD.LINK_INC = S2.LINK_INC								
	LEFT JOIN #INV I ON --Инвалиды и процент по ним
						I.LINK = S2.LINK_PERS
WHERE
	S2.SUMMA_M <> 0
	

--===РАСЧЁТ ВЫЧЕТОВ
--Информация о предельном размере ВЫЧЕТА
CREATE TABLE #VYCHET (LINK_DED INT, PREDEL NUMERIC(18,2))
INSERT INTO #VYCHET (LINK_DED, PREDEL)
SELECT TI.LINK, D.PREDEL
FROM 
	dbo.Salary_deduct_esn(@Date) D	
	INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION TI ON TI.LINK = D.REF_PAY
	LEFT JOIN dbo.DICTIONARY_TYP_INCOMS TI2 ON TI2.REF_DEDUCT = D.REF_PAY
WHERE 
	TI2.REF_DEDUCT IS NULL
	AND
	dbo.SA_GET_OPTION_BY_CODE('ESNTR_OPTIONS_OPT4') = 1 -- Предоставлять вычеты		
	
--Определение размера удержаний, дающие права на предоставление вычетов
CREATE TABLE #SUMMA_U (LINK_DED INT, LINK_PERS INT, SUMMA_M NUMERIC(18,2), SUMMA NUMERIC(18,2))
INSERT INTO #SUMMA_U (LINK_DED, LINK_PERS, SUMMA_M, SUMMA)
---Вычеты от удержаний
SELECT 
	TA.LINK_DED, ISNULL(J.PERS_LINK,E.PERS_LINK), 
	SUMMA_M = SUM(CASE WHEN MONTH(J.PERIOD_BEGIN) = @Month THEN SUMMA ELSE 0 END),
	SUMMA  = SUM(SUMMA)
FROM 
	dbo.EMPL E inner join dbo.calculate_jurnal J ON e.link = J.link_empl
	inner join dbo.TAX2_APP TA ON TA.LINK_UP = J.LINK_PAYS
WHERE 
	J.LINK_DEP = @DEP_LINK
	AND YEAR(J.PERIOD_BEGIN) = @Year AND MONTH(J.PERIOD_BEGIN) <= @Month
	AND ISNULL(TA.LINK_DED,0) > 0
GROUP BY 
	TA.LINK_DED, ISNULL(J.PERS_LINK,E.PERS_LINK)

--Удалить рассчитанную скидку по данному расчёту, чтобы рассчитать её заново
DELETE FROM dbo.SDOC_DOT_VYCHET WHERE LINK_UP = @LINK	

-- Размер уже предоставленного вычета с начала года в разрезе кодов вычетов
CREATE TABLE #VYCHET_PREV (LINK_TAX INT, LINK_PERS INT, LINK_DED INT, SUMMA NUMERIC(18,2))

INSERT INTO #VYCHET_PREV (LINK_TAX, LINK_PERS, LINK_DED, SUMMA)
SELECT LINK_TAX, LINK_PERS, LINK_DED, SUM(SUMMA)
FROM 
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DOT_VYCHET S ON S.LINK_UP = D.LINK
WHERE
	D.LINK_DEP = @DEP_LINK
	AND 
	YEAR(DATE_CALC)	= @Year AND MONTH(DATE_CALC) < @Month
GROUP BY
	LINK_TAX, LINK_PERS, LINK_DED

--==== Расчёт ВЫЧЕТА за месяц по физлицам в разрезе кодов дохода и источников

--Вычеты по сотрудникам в разрезе кодов вычетов
SELECT 
	LINK_TAX = P.LINK, S.LINK_PERS, S.LINK_DED,
	SUMMA_M = 
	--CASE WHEN S.SUMMA_M > CASE WHEN ISNULL(VP.SUMMA,0) < V.PREDEL THEN (V.PREDEL - ISNULL(VP.SUMMA,0)) * (S.SUMMA_M / S.SUMMA_M) ELSE 0 END
	--	THEN CASE WHEN ISNULL(VP.SUMMA,0) < V.PREDEL THEN (V.PREDEL - ISNULL(VP.SUMMA,0)) * (S.SUMMA_M / S.SUMMA_M) ELSE 0 END
	--	ELSE S.SUMMA_M
	--END,
	(
		--Всего надо скидку
		(CASE WHEN ISNULL(S.SUMMA,0) > ISNULL(V.PREDEL,0) THEN ISNULL(V.PREDEL,0) ELSE ISNULL(S.SUMMA,0) END) 
		--Уже предоставили
		- ISNULL(VP.SUMMA,0)
	),		
	[PERCENT] = ISNULL(I.[PERCENT],DR.[PERCENT])
INTO #TMP_VYCH
FROM
	dbo.PAYS P
	INNER JOIN #RANGE DR --Ставка налога
							ON P.LINK = DR.LINK_PAYS
	INNER JOIN #SUMMA_U S -- Вычеты по физлицам
							ON 1=1
	INNER JOIN #VYCHET V --Информация о предельном размере скидки
						ON V.LINK_DED = S.LINK_DED
	LEFT JOIN #VYCHET_PREV VP -- Размер уже предоставленного вычета с начала года
						ON VP.LINK_PERS = S.LINK_PERS AND VP.LINK_DED = S.LINK_DED
	LEFT JOIN #INV I --Инвалиды и процент по ним
					ON I.LINK = S.LINK_PERS
WHERE
	P.[OBJECT] = 3 AND P.WAY_CALC = 5
	AND S.SUMMA_M <> 0

--Доход по сотрудникам в разрезе источников
SELECT LINK_TAX, LINK_PERS, LINK_VKR, LINK_EKR, SUMMA_M = SUM(SUMMA_M)
INTO #TMP_DOH FROM #SUMMA GROUP BY LINK_TAX, LINK_PERS, LINK_VKR, LINK_EKR

--Доход по сотрудникам
SELECT LINK_TAX, LINK_PERS, SUMMA_M = SUM(SUMMA_M)
INTO #TMP_DOH2 FROM #SUMMA GROUP BY LINK_TAX, LINK_PERS

--Вычеты по сотрудникам в разрезе источников и кодов вычетов
INSERT INTO dbo.SDOC_DOT_VYCHET (LINK_UP, LINK_TAX, LINK_PERS, LINK_VKR, LINK_EKR, LINK_DED, SUMMA, [PERCENT])
SELECT 
	@LINK, D2.LINK_TAX, D2.LINK_PERS, D.LINK_VKR, D.LINK_EKR, V.LINK_DED, ISNULL(V.SUMMA_M,0) * ISNULL(D.SUMMA_M,0) / D2.SUMMA_M, V.[PERCENT]
FROM
	#TMP_DOH2 D2 
	INNER JOIN #TMP_DOH D ON D.LINK_TAX = D2.LINK_TAX AND D.LINK_PERS = D2.LINK_PERS
	INNER JOIN #TMP_VYCH V ON D2.LINK_TAX = V.LINK_TAX AND D2.LINK_PERS = V.LINK_PERS
WHERE
	ISNULL(D2.SUMMA_M,0) <> 0	

SELECT 
	[PERCENT] = ISNULL(I.[PERCENT],DR.[PERCENT]),
	DR.LINK_PAYS,
	CODE_PAYS = P.CODE,
	NAME_PAYS = P.NAME,
	S.LINK_VKR,
	[NAME_VKR] = F.CODE,
	S.LINK_EKR,
	[NAME_EKR] = G.CODE,	
	SUMMA = SUM(S.SUMMA_M),
	SKIDKA = SUM(ISNULL(SK.SUMMA,0)),
	VYCHET = SUM(ISNULL(V.SUMMA,0))
FROM 
	#RANGE DR
	INNER JOIN dbo.PAYS P ON P.LINK = DR.LINK_PAYS
	INNER JOIN #TMP_DOH S ON S.LINK_TAX = DR.LINK_PAYS
	INNER JOIN dbo.SAL_SFIN F ON F.LINK = S.LINK_VKR
	INNER JOIN dbo.KOSGU G ON G.LINK = S.LINK_EKR
	LEFT JOIN dbo.SDOC_DOT_SKIDKI SK ON  SK.LINK_UP = @LINK AND SK.LINK_TAX = DR.LINK_PAYS AND SK.LINK_PERS = S.LINK_PERS AND SK.LINK_VKR = S.LINK_VKR and SK.LINK_EKR = S.LINK_EKR
	LEFT JOIN 
	(
		SELECT LINK_TAX, LINK_PERS, LINK_VKR, LINK_EKR, SUMMA = SUM(SUMMA) FROM dbo.SDOC_DOT_VYCHET 
		WHERE LINK_UP = @LINK GROUP BY LINK_TAX, LINK_PERS, LINK_VKR, LINK_EKR
	) V
	ON V.LINK_TAX = DR.LINK_PAYS AND V.LINK_PERS = S.LINK_PERS AND V.LINK_VKR = S.LINK_VKR AND V.LINK_EKR = S.LINK_EKR
	LEFT JOIN #INV I ON I.LINK = S.LINK_PERS
GROUP BY
	ISNULL(I.[PERCENT],DR.[PERCENT]),
	DR.LINK_PAYS,
	P.CODE,
	P.NAME,
	S.LINK_VKR,
	F.CODE,
	S.LINK_EKR,
	G.CODE

DROP TABLE #SKIDKA
DROP TABLE #BASE
DROP TABLE #SUMMA
DROP TABLE #SUMMA2
DROP TABLE #SKIDKA_PREV
DROP TABLE #INV
DROP TABLE #TMP_VYCH
DROP TABLE #TMP_DOH
DROP TABLE #RANGE




GO


GRANT EXECUTE ON dbo.[SD_O_OTHER_FILL] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_RES_ATT_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_RES_ATT_GS]

GO

-- информация об аттестации
CREATE PROCEDURE [dbo].REP_RES_ATT_GS
	@date1 datetime
AS

	DECLARE @selectYear int
	SET @selectYear = DATEPART(year, @date1);

	SELECT AG.LINK, AG.DATE, AGT.DATE_TIME, AG.PERIOD, AGT.FIO, AGT.DOC_LINK, AGT.ATTEST_LINK, ISNULL(KEA.ATT_CODE,0) AS [ATT_CODE]
	INTO #ATT
	FROM	dbo.ATT_GRAPHIC	AG	
			INNER JOIN dbo.ATT_GRAPHIC_TABLE AGT ON AG.LINK = AGT.DOC_LINK
			LEFT JOIN dbo.KU_EMPL_ATTEST KEA ON KEA.LINK = AGT.ATTEST_LINK_NUM	
	WHERE PERIOD = @selectYear AND ag.[DATE] <= @date1



--- количество гражданских служащих
/*DECLARE @ALL_GOS INT
SET @ALL_GOS = (
				SELECT	COUNT(*) 
				FROM	DBO.KU_EMPL_PLACING_FN(@date1) KEP	
						LEFT JOIN DICTIONARY_STAFF_FN(@date1)	D_ST ON  KEP.STAFF_LINK = D_ST.STAFF_LINK
				WHERE	KEP.DEP_LINK = (select dep_link from user_dep)	-- только текцщей организации
						AND ISNULL(KEP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
						AND SACK = 0
						AND D_ST.GOSSL IN (1,2,3,4)		
						AND	 D_ST.GOSSL = 2			-- ГОСУДАРСТВЕННЫЕ СЛУЖАЩИЕ
  						OR   D_ST.GOSSL = 1		-- ГОСУДАРСТВЕННЫЕ ГРАЖДАНСКИЕ СЛУЖАЩИЕ
				)
*/
	SELECT  
		PLAN_CHIS	= (SELECT count(*) FROM #ATT),	-- Количество гражданских служащих, подлежащих аттестации		
		ATT			= (SELECT count(*) FROM #ATT WHERE ATTEST_LINK = 1 AND ATT_CODE <> '0'),	--Количество аттестованных гражданских служащих
		SOOTV		= (SELECT count(*) FROM #ATT WHERE ATTEST_LINK = 1 AND ATT_CODE = '1'),	--соответствуют замещаемой должности
		RESERV		= (SELECT count(*) FROM #ATT WHERE ATTEST_LINK = 1 AND ATT_CODE = '2'),	--соответствуют и рекомендуются к включению в кадровый резерв		
		PROF		= (SELECT count(*) FROM #ATT WHERE ATTEST_LINK = 1 AND ATT_CODE = '4'),	--соответствуют при условии получения дополнительного профессионального образования			
		DOWN		= (SELECT count(*) FROM #ATT WHERE ATTEST_LINK = 1 AND ATT_CODE = '3')	--не соответствуют замещаемой должности
	 		
	DROP TABLE #ATT


GO


GRANT EXECUTE ON dbo.[REP_RES_ATT_GS] TO PUBLIC

GO




GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SALARY_FILL_DED_ESN_VKR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SALARY_FILL_DED_ESN_VKR]

GO

CREATE PROCEDURE [dbo].SALARY_FILL_DED_ESN_VKR
--Начисление страховых взносов
@RefPay int, 
@LinkVKR int,
@LINK_EKR INT, 
@linkPers int, 
@Month int, 
@Year int, 
@FlagMS  tinyint,
@FlagShow int = 0,
@DEP_LINK INT  = NULL
AS

SET NOCOUNT ON

DECLARE 
	@DATE1 datetime, 
	@linkFace int,
	@LINK_213EKR INT,
	@LINK_211EKR INT,
	@TARIF TINYINT,
	@SHOW_212 TINYINT,
	@LINK_EKR_ADD INT
		  
SET @TARIF = ISNULL((SELECT TOP 1 ENVD FROM dbo.SAL_SFIN WHERE LINK = @LinkVKR),0) + 1	
		  
SET @LINK_211EKR = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '211')
SET @LINK_EKR_ADD = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '212')
SET @LINK_213EKR = (SELECT TOP 1 LINK FROM dbo.KOSGU WHERE CODE = '213')
SET @FlagMS = 1
SET @SHOW_212 = dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_3')

IF @SHOW_212 = 1 OR @LINK_EKR <> @LINK_211EKR
	SET @LINK_EKR_ADD = @LINK_EKR
	
DECLARE @ESN_OPTIONS_7 INT --Начислять доп. тариф только для полной ставки
--При включенной опции программа будет начислять страховые взносы по доп. тарифам только если у сотрудника по основной должности полная ставка. 
--Если ставка не полная, то доп. тариф не начисляется.
SET @ESN_OPTIONS_7 = dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_7')

DECLARE @ESN_OPTIONS_8 INT --Начислять доп. тариф внутренним совместителям
--При включенной опции программа будет начислять страховые взносы по доп. тарифам на доходы внутренних совместителей.
SET @ESN_OPTIONS_8 = dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_8')

DECLARE @DATE_BEG DATETIME
SET @DATE_BEG = dbo.convertDMY2Date(1,@Month,@Year)
SET @DATE1 = dbo.DateEndOfMonth(@DATE_BEG)

DECLARE @DATE_YEAR_BEG DATETIME
SET @DATE_YEAR_BEG = dbo.convertDMY2Date(1,1,@Year)

SELECT @linkFace = @linkPers 

DECLARE @T1 TABLE
([NUM]			[int],
 [SUMMA]		[numeric](19,2),
 [SUMMA_VKR]		[numeric](19,2),
 [SUMMA_M]		[numeric](19,2),
 [SUMMA_M_VKR]		[numeric](19,2))


IF @DEP_LINK IS NULL
	exec dbo.xd_whats_zb @DEP_LINK output

declare @linkEmpl int,  @Pred_Mesto_Rab numeric(15,2), 	  @FlagD int

SET @linkEmpl = 
	(SELECT TOP 1 IM.EMPL_LINK
	FROM
		DBO.EMPL E with (nolock)
		LEFT JOIN DBO.ITEM_MOVE IM with (nolock) ON IM.EMPL_LINK = E.LINK AND IM.ACTIVE = 1 AND IM.NEW_FACE=1 AND IM.[STATUS] IN (1,3) AND IM.DATE_BEGIN <= @DATE1
		LEFT JOIN DBO.ITEM_DIS_FACE IDF with (nolock) ON IDF.EMPL_LINK = E.LINK AND IDF.ACTIVE=1 AND COALESCE(IDF.DIS_DATE,'20990101') >= dbo.DateBeginOfMonth(@DATE1)
	WHERE
		E.DEP_LINK = @DEP_LINK
		AND
		E.PERS_LINK = @linkPers
	ORDER BY
		DATE_BEGIN DESC	
	)	

---------------------------------------------------
DECLARE @item_move TABLE (LINK INT, EMPL_LINK INT, STAFF_LINK INT, DATE_BEGIN DATETIME, DATE_END DATETIME, NUM_STAKE NUMERIC(5,3), active TINYINT, NEW_FACE TINYINT, [STATUS] TINYINT)
INSERT INTO @item_move (LINK, EMPL_LINK, STAFF_LINK, DATE_BEGIN, DATE_END, NUM_STAKE, active, NEW_FACE, [STATUS])
Select 
	P1.LINK, P1.EMPL_LINK, P1.STAFF_LINK, P1.DATE_BEGIN, P1.DATE_END, P1.NUM_STAKE, P1.active, P1.NEW_FACE, P1.[STATUS]
from 
	dbo.empl e INNER JOIN dbo.item_move P1 ON P1.EMPL_LINK = e.link
WHERE
	E.DEP_LINK = @DEP_LINK AND E.PERS_LINK	= @linkPers
---------------------------------------------------

--Информация о размере ставок по каждому табельному номеру
DECLARE @NUM_STAKE TABLE (LINK_EMPL INT, NUM_STAKE NUMERIC(18,4), DATE_BEG DATETIME, DATE_END DATETIME)
INSERT INTO @NUM_STAKE (LINK_EMPL, NUM_STAKE, DATE_BEG, DATE_END)
SELECT DISTINCT
	EMPL_LINK, NUM_STAKE, DATE_BEGIN, DATE_END 
FROM @item_move
WHERE active = 1 AND NEW_FACE <> 3 AND @DATE1 BETWEEN DATE_BEGIN AND DATE_END

if @FlagShow = 1 
	select 'Сотрудник:  '+ LTRIM(RTRIM(P.FM)) + ' ' + SUBSTRING(LTRIM(RTRIM(P.IM)),1,1) + '.' + SUBSTRING(LTRIM(RTRIM(P.OT)),1,1)
		+  ', месяц ' + convert(varchar(2),@Month)+ ', год ' +convert(varchar(4),@Year) as [Исходные данные],
		[Отчисление] = (select rtrim(name) from pays where link =@RefPay)  FROM dbo.PERSON P where link = @linkFace


DECLARE @NASTR TABLE
([LINK_MINROT] 	[int],
 [REF_PAY]			[int],
 [CODE]				[varchar](5),
 [NAME]				[varchar](254),
 [PREDEL]			[numeric](19, 2))

INSERT INTO @NASTR([LINK_MINROT],[REF_PAY],[CODE],[NAME],[PREDEL])
SELECT [LINK_MINROT],[REF_PAY],[CODE],[NAME],[PREDEL] FROM dbo.Salary_deduct_esn(@DATE1)

SELECT @Pred_Mesto_Rab = 0, @FlagD = 0

IF dbo.SA_GET_OPTION_BY_CODE('ESN_OPTIONS_6 ') = 1
BEGIN
	IF YEAR(dbo.kd_DateBeginWork(@linkEmpl,null)) = @Year
	BEGIN
		SET @Pred_Mesto_Rab = (SELECT ISNULL(SUM(SUMMA_DED),0) FROM dbo.SD_EMPL_PREV_DED WHERE LINK_EMPL = @linkEmpl and LINK_DED in (select REF_PAY from @NASTR))
		IF @Pred_Mesto_Rab IS null or @Pred_Mesto_Rab < 0
			SET @Pred_Mesto_Rab = 0
		SET @FlagD = 1
		
		IF  @FlagShow = 1 
			SELECT 'Совокупный доход: '+ rtrim(isnull(convert(varchar(100),(select sum(summa_TYP_INCOMS) from dbo.SD_EMPL_PREV_DOHOD where link_empl =@linkEmpl)),'0')) + ' , вычеты: '+
			 rtrim( isnull( convert(varchar(100),(select sum(summa_ded) from dbo.SD_EMPL_PREV_DED where link_empl =@linkEmpl and LINK_DED in (select REF_PAY from @NASTR) )),'0'))  as 'Данные с предыдущего места работы'
	END
END	

---Учитываются доходы по договорам ГПХ в данной организации, чтобы правильно применить регрессионную шкалу---
DECLARE @SUM_DGH numeric(15,2)
SET @SUM_DGH = 
	ISNULL(
	(
	SELECT SUM(GT.SUMMA_BASE)
	FROM dbo.DOCUMENTS_DGH G INNER JOIN dbo.DOCUMENTS_DGH_T3 GT ON G.LINK = GT.LINK
	WHERE FLAG_JC = 1
			AND YEAR(G.[DATE]) = @Year
			AND MONTH(G.[DATE]) <= @Month
			AND G.LINK_DEP = @DEP_LINK
			AND GT.LINK_PAY = @RefPay
			AND GT.PERS_LINK = @linkFace
	),0)

IF @SUM_DGH <> 0 AND @FlagShow = 1 
	SELECT 'Совокупный доход: '+ rtrim(isnull(convert(varchar(100),@SUM_DGH),'0')) as 'Доход по договорам ГПХ'


CREATE TABLE #PERIODY (LINK_EMPL INT, LINK_PERSON INT, TAB VARCHAR(10), NUM_STAKE NUMERIC(18,4), POSTNAME VARCHAR(50), st_date1 datetime, st_date2 datetime, im_date1 datetime, im_date2 datetime, [COD_SPO_USL_TRUD] int)

---------------------------------------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC IN (10,11) AND LINK = @RefPay)
BEGIN

	--sa_item_move
	--	
	DECLARE @sa_item_move TABLE (EMPL_LINK INT, STAFF_LINK INT, DATE_BEGIN DATETIME, DATE_END3 DATETIME, NUM_STAKE NUMERIC(5,3), [STATUS] TINYINT )

	INSERT INTO @sa_item_move (EMPL_LINK, STAFF_LINK, DATE_BEGIN, DATE_END3, NUM_STAKE, [STATUS])
	Select 
		P1.EMPL_LINK, P1.STAFF_LINK, P1.DATE_BEGIN, date_end3 = min(P2.date_begin) - 1, P1.NUM_STAKE, P1.[STATUS]
	from 
		dbo.empl e
		INNER JOIN @item_move P1 ON P1.EMPL_LINK = e.link
		INNER JOIN @item_move P2 on P1.EMPL_LINK = P2.EMPL_LINK
	where
		E.PERS_LINK	= @linkPers 
		AND P1.active = 1 AND P2.active = 1 AND P1.NEW_FACE <> 3 AND P2.NEW_FACE <> 3
		AND P1.[date_begin] < P2.[date_begin] 
	group by 
		P1.EMPL_LINK, P1.STAFF_LINK, P1.DATE_BEGIN, P1.NUM_STAKE, P1.[STATUS]

	INSERT INTO @sa_item_move (EMPL_LINK, STAFF_LINK, DATE_BEGIN, DATE_END3, NUM_STAKE, [STATUS])
	Select 
		P3.EMPL_LINK, P3.STAFF_LINK, P3.DATE_BEGIN, date_end3 = '99991231', P3.NUM_STAKE, P3.[STATUS]
	from
		dbo.empl e 
		INNER JOIN @item_move P3 ON P3.EMPL_LINK = e.link
	where
		E.PERS_LINK	= @linkPers  
		AND
		P3.active = 1 AND P3.NEW_FACE <> 3
		AND
		NOT EXISTS (
					Select *
					from 
						@item_move P1 inner join @item_move P2 on P1.EMPL_LINK = P2.EMPL_LINK
					where
						P1.LINK = P3.link
						AND P1.active = 1 and P2.active = 1 AND P1.NEW_FACE <> 3 AND P2.NEW_FACE <> 3
						and P1.[date_begin] < P2.[date_begin] 
					)
	-----------------------------------------------------------------------------------------------------

	CREATE TABLE #ADD_TYPE (
		[type] INT IDENTITY(1,1),
		[TERR_USL_TRUD] int NULL ,
		[TERR_RK] numeric(3, 2) NULL ,
		[OSOB_USL_TRUD] int NULL ,
		[COD_POS_SPISOK] int NULL ,
		[COD_POS_SPISOK2] int NULL ,
		[USL_DOSROCH_PENS] int NULL ,
		[STAVKA_PED_MED] numeric(3, 2) NULL,
		[COD_SPO_USL_TRUD] int NULL
	)

	INSERT INTO #ADD_TYPE 
	SELECT DISTINCT ISNULL(TERR_USL_TRUD,0), ISNULL(TERR_RK,0), ISNULL(OSOB_USL_TRUD,0), ISNULL(COD_POS_SPISOK,0), ISNULL(COD_POS_SPISOK2,0), ISNULL(USL_DOSROCH_PENS,0), ISNULL(STAVKA_PED_MED,0), ISNULL([COD_SPO_USL_TRUD],0)
	FROM dbo.staff
	WHERE ISNULL(COD_POS_SPISOK,0) <> 0 OR ISNULL(COD_POS_SPISOK2,0) <> 0

	INSERT INTO 
		#PERIODY (LINK_EMPL, LINK_PERSON, TAB, NUM_STAKE, POSTNAME, st_date1, st_date2, im_date1, im_date2, [COD_SPO_USL_TRUD])
	SELECT DISTINCT
		E.LINK,
		E.PERS_LINK,
		TAB,
		IM.NUM_STAKE,
		LEFT(PT.NAME,50),
		st_date1 = dbo.DateBeginOfMonth((case when st.DATE_BEGIN >= @DATE_YEAR_BEG then st.DATE_BEGIN else @DATE_YEAR_BEG end)),
		st_date2 = dbo.DateEndOfMonth((case when coalesce(st.DATE_END,@DATE1) <= @DATE1 then coalesce(st.DATE_END,@DATE1) else @DATE1 end)	),
		im_date1 = dbo.DateBeginOfMonth((case when im.DATE_BEGIN >= @DATE_YEAR_BEG then im.DATE_BEGIN else @DATE_YEAR_BEG end)),
		im_date2 = dbo.DateEndOfMonth( 
							CASE WHEN COALESCE(U.DIS_DATE,'20990101') <= (case when ISNULL(ISNULL(U.DIS_DATE,im.DATE_END3),@DATE1) <= @DATE1 then ISNULL(ISNULL(U.DIS_DATE,im.DATE_END3),@DATE1) else @DATE1 end)
								THEN COALESCE(U.DIS_DATE,'20990101')
								ELSE (case when ISNULL(ISNULL(U.DIS_DATE,im.DATE_END3),@DATE1) <= @DATE1 then ISNULL(ISNULL(U.DIS_DATE,im.DATE_END3),@DATE1) else @DATE1 end)
							END	),
		T.[COD_SPO_USL_TRUD]							
	FROM 
		dbo.empl e
		INNER JOIN @sa_item_move im ON im.EMPL_LINK = e.link
		inner join dbo.staff_head sh on sh.link = STAFF_LINK
		inner join dbo.staff st on st.link_up = sh.link
		INNER JOIN dbo.POST PT ON PT.LINK = st.post_link
		INNER join #ADD_TYPE T on ISNULL(st.TERR_USL_TRUD,0) = ISNULL(T.TERR_USL_TRUD,0) 
								AND ISNULL(st.TERR_RK,0) = ISNULL(T.TERR_RK,0) 
								AND ISNULL(st.OSOB_USL_TRUD,0) = ISNULL(T.OSOB_USL_TRUD,0) 
								AND ISNULL(st.COD_POS_SPISOK,0) = ISNULL(T.COD_POS_SPISOK,0) 
								AND ISNULL(st.COD_POS_SPISOK2,0) = ISNULL(T.COD_POS_SPISOK2,0) 
								AND ISNULL(st.USL_DOSROCH_PENS,0) = ISNULL(T.USL_DOSROCH_PENS,0) 
								AND ISNULL(st.STAVKA_PED_MED,0) = ISNULL(T.STAVKA_PED_MED,0)
								AND ISNULL(st.COD_SPO_USL_TRUD,0) = ISNULL(T.COD_SPO_USL_TRUD,0)
		LEFT JOIN dbo.ITEM_DIS_FACE U on E.link = U.empl_link AND U.ACTIVE=1	
	where
		E.PERS_LINK	= @linkPers
		and  
		im.DATE_BEGIN <= @DATE1 and im.DATE_END3 >= @DATE_YEAR_BEG
		AND
		IM.[STATUS] <> 2 --Вредность у внутренних совместителей не учитываем (НЕ ДОЛЖНО БЫТЬ)
		AND
		st.DATE_BEGIN <= @DATE1 and st.DATE_END >= @DATE_YEAR_BEG
		AND
		T.[TYPE] IS NOT NULL
		AND
		(
			ISNULL(T.[COD_POS_SPISOK],0) <> 0 AND EXISTS (SELECT * FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 AND LINK = @RefPay)
			OR
			ISNULL(T.[COD_POS_SPISOK2],0) <> 0 AND EXISTS (SELECT * FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 AND LINK = @RefPay)	
		)	

	if @FlagShow = 1 
		SELECT DISTINCT TAB AS [Таб_номер],  LEFT(dbo.ku_GetEmplSubdivName(LINK_EMPL,@DATE1),50) AS [Отдел], POSTNAME AS [Должность], CONVERT(VARCHAR(10), ST_DATE1, 104) AS 'Нач_пер_с_вредн_ШР', CONVERT(VARCHAR(10),ST_DATE2,104) AS 'Оконч_пер_с_вредн_ШР' FROM #PERIODY
			
	if @FlagShow = 1 
		SELECT DISTINCT TAB AS [Таб_номер],  NUM_STAKE AS [Кол-во ставок], LEFT(dbo.ku_GetEmplSubdivName(LINK_EMPL,@DATE1),50) AS [Отдел], POSTNAME AS [Должность], CONVERT(VARCHAR(10), IM_DATE1, 104) AS 'Нач_пер_с_вредн_должность', CONVERT(VARCHAR(10),IM_DATE2,104) AS 'Оконч_пер_с_вредн_должность', CASE WHEN NUM_STAKE < 1 THEN 'Доп. тариф не начисляется, т.к. не полный день' ELSE '' END AS [Примечание]
		FROM #PERIODY
	
	INSERT INTO @T1 ([NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR])
	SELECT M.NUM,SUM(SJ.SUMMA) AS SUMMA, 			
			 [SUMMA_VKR]	= SUM(CASE WHEN SJ.LINK_VKR = @LinkVKR AND SJ.LINK_EKR IN (@LINK_EKR,@LINK_EKR_ADD) THEN SJ.SUMMA ELSE 0 END),
			 [SUMMA_M] 		= SUM(CASE WHEN MONTH(SJ.PERIOD_BEGIN) = M.NUM THEN SJ.SUMMA ELSE 0 END),
			 [SUMMA_M_VKR] = SUM(CASE WHEN (MONTH(SJ.PERIOD_BEGIN) = M.NUM) AND (SJ.LINK_VKR = @LinkVKR AND SJ.LINK_EKR  IN (@LINK_EKR,@LINK_EKR_ADD)) THEN SJ.SUMMA ELSE 0 END)
	FROM 
		dbo.MONTHS M
		INNER JOIN dbo.EMPL E ON 1=1
		INNER JOIN dbo.CALCULATE_JURNAL SJ ON SJ.LINK_EMPL = E.LINK
		INNER JOIN dbo.TAX_REF TR ON TR.LINK_PAYS =  SJ.LINK_PAYS
	WHERE 
		E.PERS_LINK = @linkFace
		AND (M.NUM <= @Month) 
		AND (MONTH(SJ.PERIOD_BEGIN) <= M.NUM) 
		AND (YEAR(SJ.PERIOD_BEGIN) = @Year)
		AND TR.LINK_TAX = @RefPay 
		AND EXISTS (SELECT * FROM #PERIODY P WHERE 
												(@ESN_OPTIONS_7 = 0 OR @ESN_OPTIONS_7 = 1 AND P.NUM_STAKE >=1)
												AND 
												(
													@ESN_OPTIONS_8 = 0 AND P.LINK_EMPL = SJ.LINK_EMPL 
													OR
													@ESN_OPTIONS_8 = 1 AND P.LINK_PERSON = E.PERS_LINK
												)	
												AND SJ.PERIOD_BEGIN <= P.ST_DATE2 
												AND SJ.PERIOD_END >= P.ST_DATE1 
												AND SJ.PERIOD_BEGIN <= P.IM_DATE2 
												AND SJ.PERIOD_END >= P.IM_DATE1)
	GROUP BY  M.NUM	

	
END
---------------------------------------------------------------------------------------------------------------
ELSE
	INSERT INTO @T1 ([NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR])
	SELECT M.NUM,SUM(SJ.SUMMA) AS SUMMA, 			
			 [SUMMA_VKR]	= SUM(CASE WHEN SJ.LINK_VKR = @LinkVKR AND SJ.LINK_EKR IN (@LINK_EKR,@LINK_EKR_ADD) THEN SJ.SUMMA ELSE 0 END),
			 [SUMMA_M] 		= SUM(CASE WHEN MONTH(SJ.PERIOD_BEGIN) = M.NUM THEN SJ.SUMMA ELSE 0 END),
			 [SUMMA_M_VKR] = SUM(CASE WHEN (MONTH(SJ.PERIOD_BEGIN) = M.NUM) AND (SJ.LINK_VKR = @LinkVKR AND SJ.LINK_EKR  IN (@LINK_EKR,@LINK_EKR_ADD)) THEN SJ.SUMMA ELSE 0 END)
	FROM 
		dbo.MONTHS M
		INNER JOIN dbo.CALCULATE_JURNAL SJ ON 1=1 
		INNER JOIN dbo.TAX_REF TR ON TR.LINK_PAYS =  SJ.LINK_PAYS
		INNER JOIN dbo.EMPL E ON SJ.LINK_EMPL = E.LINK
	WHERE 
		(TR.LINK_TAX = @RefPay) 
		AND (E.PERS_LINK = @linkFace) 
		AND (MONTH(SJ.PERIOD_BEGIN) <= M.NUM) AND (M.NUM <= @Month) AND (YEAR(SJ.PERIOD_BEGIN)=@Year)
		AND sj.LINK_DEP = @DEP_LINK
	GROUP BY  M.NUM


if @FlagShow = 1 
	SELECT [num] as [Месяц], [summa] as [Сумма с нач года],summa_vkr as [Сумма с нач года по ВКР/ЕКР], summa_m as [Сумма за месяц], 
	summa_m_vkr as [Сумма за месяц по ВКР/ЕКР]  FROM @T1

--Если суммы, которые раньше были в базе убрали из базы, теперь базовой суммы вообще нет
IF NOT EXISTS(SELECT * FROM @T1)
	INSERT INTO @T1 ([NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR])
	VALUES(@Month, 0, 0, 0, 0)

DECLARE @Temp1_1 TABLE
([NUM]			[int],
 [LINK_PAYS]	[int],
 [MP]				[numeric](19,2),
 [MP_M]			[numeric](19,2),
 [MP_M_VKR]		[numeric](19,2))

--------------------------------------------------
CREATE TABLE #DICTIONARY_TYP_INCOMS (LINK INT)
INSERT INTO #DICTIONARY_TYP_INCOMS (LINK)
SELECT LINK FROM dbo.DICTIONARY_TYP_INCOMS WHERE EXISTS (SELECT * FROM @NASTR WHERE REF_PAY = REF_DEDUCT)
CREATE INDEX #DICTIONARY_TYP_INCOMS_IDX1 ON #DICTIONARY_TYP_INCOMS (LINK)

-------------------------------------------------
CREATE TABLE #PAYS (LINK INT)
INSERT INTO #PAYS (LINK)
SELECT P.LINK FROM dbo.PAYS P INNER JOIN #DICTIONARY_TYP_INCOMS I ON I.LINK = P.LINK_INC
CREATE INDEX #PAYS_IDX1 ON #PAYS (LINK)


--------------------------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC IN (10,11) AND LINK = @RefPay)
	
	INSERT INTO @Temp1_1 ([NUM],[LINK_PAYS],[MP],[MP_M],[MP_M_VKR])
	SELECT M.NUM,
			 [LINK_PAYS]= (SELECT LINK_INC  from pays where link = sj.LINK_PAYS),
			 [MP] 		= SUM(CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end), 
			 [MP_M] 		= SUM(CASE WHEN month(SJ.PERIOD_BEGIN)=m.num then (CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end) else 0 end),
			 [MP_M_VKR] = SUM(CASE WHEN ( month(SJ.PERIOD_BEGIN)=m.num)AND(sj.link_vkr = @LinkVKR AND SJ.LINK_EKR  IN (@LINK_EKR,@LINK_EKR_ADD)) 
								THEN (CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end) else 0 end)
	FROM 
		dbo.MONTHS M 
		INNER JOIN dbo.S_J_C_Short SJ ON 1=1
		INNER JOIN #PAYS P ON P.LINK = SJ.LINK_PAYS
		INNER JOIN dbo.TAX_REF TR ON TR.LINK_PAYS =  SJ.LINK_PAYS
	WHERE 
		TR.LINK_TAX = @RefPay 
		AND (SJ.LINK_FACE = @linkFace)
		AND YEAR(SJ.PERIOD_BEGIN)=@Year AND M.NUM <= @Month 
		AND sj.LINK_DEP = @DEP_LINK
		AND EXISTS (SELECT * FROM #PERIODY P WHERE 
									(
										@ESN_OPTIONS_8 = 0 AND P.LINK_EMPL = SJ.LINK_EMPL
										OR
										@ESN_OPTIONS_8 = 1 AND P.LINK_PERSON = SJ.LINK_FACE
									)									
									AND SJ.PERIOD_BEGIN <= P.ST_DATE2 AND SJ.PERIOD_END >= P.ST_DATE1)		
		AND EXISTS (SELECT * FROM #PERIODY P WHERE 
									(
										@ESN_OPTIONS_8 = 0 AND P.LINK_EMPL = SJ.LINK_EMPL
										OR
										@ESN_OPTIONS_8 = 1 AND P.LINK_PERSON = SJ.LINK_FACE
									)	
									AND (@ESN_OPTIONS_7 = 0 OR @ESN_OPTIONS_7 = 1 AND P.NUM_STAKE >=1)
									AND SJ.PERIOD_BEGIN <= P.IM_DATE2 AND SJ.PERIOD_END >= P.IM_DATE1)		
	GROUP BY 
		M.NUM,SJ.LINK_PAYS
ELSE
	INSERT INTO @Temp1_1 ([NUM],[LINK_PAYS],[MP],[MP_M],[MP_M_VKR])
	SELECT M.NUM,
			 [LINK_PAYS]= (SELECT LINK_INC  from pays where link = sj.LINK_PAYS),
			 [MP] 		= SUM(CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end), 
			 [MP_M] 		= SUM(CASE WHEN month(SJ.PERIOD_BEGIN)=m.num then (CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end) else 0 end),
			 [MP_M_VKR] = SUM(CASE WHEN ( month(SJ.PERIOD_BEGIN)=m.num)AND(sj.link_vkr = @LinkVKR AND SJ.LINK_EKR  IN (@LINK_EKR,@LINK_EKR_ADD)) 
								THEN (CASE WHEN month(SJ.PERIOD_BEGIN)<=m.num then SJ.summa else 0 end) else 0 end)
	FROM 
		dbo.MONTHS M 
		INNER JOIN dbo.S_J_C_Short SJ ON 1=1
		INNER JOIN #PAYS P ON P.LINK = SJ.LINK_PAYS
		INNER JOIN dbo.TAX_REF TR ON TR.LINK_PAYS =  SJ.LINK_PAYS
	WHERE 
		TR.LINK_TAX = @RefPay 
		AND (SJ.LINK_FACE = @linkFace)
		AND YEAR(SJ.PERIOD_BEGIN)=@Year AND M.NUM <= @Month 
		AND sj.LINK_DEP = @DEP_LINK
	GROUP BY 
		M.NUM,SJ.LINK_PAYS
	

/*if @FlagShow = 1  
	select *  from @Temp1_1*/

DECLARE @Temp1 TABLE
([NUM]			[int],
 [LINK_PAYS]	[int],
 [PREDEL]		[numeric](19,2),
 [MP]				[numeric](19,2),
 [MP_M]			[numeric](19,2),
 [MP_M_VKR]		[numeric](19,2))

INSERT INTO @Temp1 ([NUM],[LINK_PAYS],[PREDEL],[MP],[MP_M],[MP_M_VKR])
SELECT NUM,LINK_PAYS,
		[PREDEL] =  ISNULL((SELECT TOP 1 PREDEL FROM @NASTR 
								WHERE REF_PAY = (SELECT TOP 1 REF_DEDUCT FROM dbo.DICTIONARY_TYP_INCOMS WHERE LINK = LINK_PAYS)),0),
		SUM(MP) AS MP,
		SUM(MP_M) AS MP_M, 
		SUM(MP_M_VKR) AS MP_M_VKR
FROM @Temp1_1
GROUP BY NUM,LINK_PAYS

DECLARE @Temp2 TABLE
([NUM]			[int],
 [LINK_PAYS]	[int],
 [PREDEL]		[numeric](19,2),
 [MP]				[numeric](19,2),
 [MP_M]			[numeric](19,2),
 [MP_M_VKR]		[numeric](19,2),
 [SALDO]			[numeric](19,2),
 [KOEF]			[numeric](19,10))

---


INSERT INTO @Temp2 ([NUM],[LINK_PAYS],[PREDEL],[MP],[MP_M],[MP_M_VKR],[SALDO],[KOEF]) 
SELECT T1.[NUM],T1.[LINK_PAYS],T1.[PREDEL],T1.[MP],T1.[MP_M],T1.[MP_M_VKR],
		 [SALDO] = (CASE WHEN @Pred_Mesto_Rab + ISNULL((SELECT SUM(MP_M) FROM @Temp1 T2 WHERE T2.NUM <= T1.NUM AND T2.LINK_PAYS = T1.LINK_PAYS),0) > PREDEL
				THEN PREDEL
				ELSE @Pred_Mesto_Rab + ISNULL((SELECT SUM(MP_M) FROM @Temp1 T2 WHERE T2.NUM <= T1.NUM AND T2.LINK_PAYS = T1.LINK_PAYS),0)
				END)
				- (CASE WHEN @Pred_Mesto_Rab + ISNULL((SELECT SUM(MP_M) FROM @Temp1 T2 WHERE T2.NUM < T1.NUM AND T2.LINK_PAYS = T1.LINK_PAYS),0) > PREDEL
				THEN PREDEL
				ELSE @Pred_Mesto_Rab + ISNULL((SELECT SUM(MP_M) FROM @Temp1 T2 WHERE T2.NUM < T1.NUM AND T2.LINK_PAYS = T1.LINK_PAYS),0)
				END),
		 [KOEF] 	= (CASE WHEN (SELECT SUM(MP_M) FROM @Temp1 T3 WHERE T3.NUM = T1.NUM AND T3.LINK_PAYS = T1.LINK_PAYS) = 0 
						THEN 0 ELSE (CASE WHEN (SELECT SUM(MP_M) 
				                         FROM @Temp1 T3 WHERE T3.NUM = T1.NUM AND T3.LINK_PAYS = T1.LINK_PAYS)= 0 
										  THEN 0 ELSE 										
											MP_M_VKR/(SELECT SUM(MP_M) 
                    				     FROM @Temp1 T3 WHERE T3.NUM = T1.NUM AND T3.LINK_PAYS = T1.LINK_PAYS) END) END)
FROM @Temp1 T1

declare @predel numeric(18,2)
Set @predel = COALESCE((SELECT TOP 1 PREDEL FROM @Temp1),0)


DECLARE @Temp3 TABLE
([NUM]			[int],
 [LINK_PAYS]	[int],
 [SUMMA]			[numeric](19,2),
 [SUMMA_ALL]	[numeric](19,2),
 [SUMMA_M]		[numeric](19,2),
 [SUMMA_M_VKR]		[numeric](19,2)
)

INSERT INTO @Temp3 ([NUM],[LINK_PAYS],[SUMMA],[SUMMA_ALL],[SUMMA_M], SUMMA_M_VKR)
SELECT  T.[NUM], T.[LINK_PAYS],
		  [SUMMA] 	= dbo.IS_MIN((SELECT SUM(T3.SALDO * KOEF) FROM @Temp2 T3 WHERE  T3.NUM <= T.NUM AND T3.LINK_PAYS = T.LINK_PAYS),T.PREDEL), 
		  [SUMMA_ALL] 	= dbo.IS_MIN((SELECT SUM(T3.SALDO) FROM @Temp2 T3 WHERE  T3.NUM <= T.NUM AND T3.LINK_PAYS = T.LINK_PAYS),T.PREDEL),
		  [SUMMA_M] 	= CASE WHEN ABS(SUM(MP_M)) < ABS(T.SALDO) THEN ABS(T.SALDO) ELSE T.SALDO END,
		SUMMA_M_VKR 	= CASE WHEN ABS(SUM(MP_M)) < ABS(T.SALDO) THEN ABS(T.SALDO) ELSE T.SALDO END * KOEF
FROM @Temp2 T --WHERE SALDO > 0
GROUP BY T.NUM,T.PREDEL,T.SALDO,T.LINK_PAYS, KOEF 
ORDER BY T.NUM

if @FlagShow = 1  
	select num as [Месяц], LINK_PAYS as [Вычет], summa as [Скидка по ВКР/ЕКР], summa_all as [Скидка с начала года], summa_m as [Скидка за месяц]  from @Temp3


DECLARE @PREDEL_INV [numeric](15, 2)
SET @PREDEL_INV = ISNULL((SELECT TOP 1 PREDEL FROM dbo.DICTIONARY_MROT_TABLE3 DMT 
									WHERE LINK_MINROT = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_MROT 
									WHERE PERIOD <=@DATE1 ORDER BY PERIOD DESC) AND (REF_PAY = @RefPay)),0)

DECLARE @T2_1 TABLE
([NUM]			[int],
 [SUMMA]			[numeric](19, 2),
 [SUMMA_VKR]	[numeric](19, 2),
 [SUMMA_M]		[numeric](19, 2),
 [SUMMA_M_VKR]	[numeric](19, 2),
 [MP]				[numeric](19, 2),
 [MP_VKR]		[numeric](19, 2),
 [MP_M]			[numeric](19, 2),
 [MP_M_VKR]		[numeric](19, 2),
 [STATUS]		[int],
 [INV]			[numeric](19, 2))


INSERT INTO @T2_1 ([NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR],[MP],[MP_VKR],[MP_M],[MP_M_VKR],[STATUS],[INV])
SELECT T1.[NUM],T1.[SUMMA],T1.[SUMMA_VKR],T1.[SUMMA_M],T1.[SUMMA_M_VKR],
--		 [MP] 		= ISNULL((SELECT SUM(SUMMA) FROM @Temp3 T WHERE T.NUM <= T1.NUM),0),  
		 [MP] 		= ISNULL((SELECT SUM(SUMMA_ALL) FROM @Temp3 T WHERE T.NUM = T1.NUM),0),  
		 [MP_VKR]	= ISNULL((SELECT SUM(SUMMA) FROM @Temp3 T WHERE T.NUM = T1.NUM),0),  
		 [MP_M] 	= ISNULL((SELECT SUM(SUMMA_M) FROM @Temp3 T WHERE T.NUM = T1.NUM),0),  
		 [MP_M_VKR] = ISNULL((SELECT SUM(SUMMA_M_VKR) FROM @Temp3 T WHERE T.NUM = T1.NUM),0),  
--		 [MP_M_VKR] = ISNULL((SELECT SUM(SUMMA) FROM @Temp3 T WHERE T.NUM = T1.NUM),0),  
		 [STATUS] 	= dbo.is_invalid(@linkFace,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,T1.NUM,@Year))), 
		 [INV] 		= cast(0 as numeric(15,2))
FROM @T1 T1 
GROUP BY T1.NUM,T1.SUMMA,T1.SUMMA_VKR,T1.SUMMA_M,T1.SUMMA_M_VKR
ORDER BY T1.NUM


DECLARE @summa_m 	[numeric](15, 2), 
		  @mp_m 		[numeric](15, 2),
		  @num 		[int], 
		  @Flag 		[bit], 
		  @itog 		[numeric](15, 2)

SET @itog = 0
DECLARE TMP_CUR CURSOR
FOR SELECT SUMMA_M, MP_M,NUM FROM @T2_1 WHERE STATUS = 2
OPEN TMP_CUR
FETCH TMP_CUR INTO @summa_m,@mp_m,@num
WHILE (@@FETCH_STATUS  = 0) AND (@PREDEL_INV - @itog) > 0 BEGIN
	IF @PREDEL_INV < (@itog+ @summa_m - @mp_m)
		UPDATE @T2_1 SET INV =(@PREDEL_INV-@itog) WHERE NUM = @num
	ELSE
		UPDATE @T2_1 SET INV =(@summa_m - @mp_m) WHERE NUM = @num
	
	SET @itog = @itog + @summa_m - @mp_m
	FETCH TMP_CUR INTO @summa_m,@mp_m,@num
END
CLOSE TMP_CUR
DEALLOCATE TMP_CUR

-- Другие льготы за месяц помимо инвалидов
---Вычеты от удержаний
select 
	TA.LINK_DED, MON = MONTH(CJ.PERIOD_BEGIN),
	SUMMA_G = CAST(0 AS NUMERIC(18,2)),
	SUMMA_M = SUM(SUMMA),
	LIMIT = ISNULL((SELECT TOP 1 PREDEL FROM @NASTR WHERE REF_PAY = TA.LINK_DED),0)
INTO #DED_U
from 
	dbo.EMPL E inner join dbo.calculate_jurnal cj on e.link = cj.link_empl
	inner join dbo.TAX2_APP TA on TA.LINK_UP = CJ.LINK_PAYS
where 
	cj.LINK_DEP = @DEP_LINK
	AND
	year(period_begin) = @Year
	and
	E.PERS_LINK = @linkPers	
	and 
	MONTH(cj.PERIOD_BEGIN) <= @Month
	and
	ISNULL(TA.LINK_DED,0) > 0
GROUP BY 
	TA.LINK_DED, MONTH(CJ.PERIOD_BEGIN)


UPDATE A
SET SUMMA_G = (SELECT SUM(SUMMA_M) FROM #DED_U B WHERE B.MON <= A.MON )
FROM #DED_U A

UPDATE #DED_U
SET 
	SUMMA_G = CASE WHEN ISNULL(SUMMA_G,0) < ISNULL(LIMIT,0) THEN ISNULL(SUMMA_G,0) ELSE ISNULL(LIMIT,0) END,
	SUMMA_M = CASE WHEN ISNULL(SUMMA_G,0) < ISNULL(LIMIT,0) THEN ISNULL(SUMMA_M,0)
				ELSE 
					CASE WHEN ISNULL(LIMIT,0) - (ISNULL(SUMMA_G,0) - ISNULL(SUMMA_M,0)) > 0 THEN 
						ISNULL(LIMIT,0) - (ISNULL(SUMMA_G,0) - ISNULL(SUMMA_M,0))
					ELSE 0
					END
			  END

UPDATE @T2_1 SET INV = ISNULL(INV,0) + ISNULL((SELECT SUM(SUMMA_M) FROM #DED_U WHERE MON = NUM),0)

--Расчет налога
--
DECLARE @T2 TABLE 
([NUM]				[int],
 [SUMMA]			[numeric](19, 2),
 [SUMMA_VKR]		[numeric](19, 2),
 [SUMMA_M]			[numeric](19, 2),
 [SUMMA_M_VKR]		[numeric](19, 2),
 [MP]				[numeric](19, 2),
 [MP_VKR]			[numeric](19, 2),
 [MP_M]				[numeric](19, 2),
 [MP_M_VKR]			[numeric](19, 2),
 [STATUS]			[int],
 [INV]				[numeric](19, 2),
 [INV_VKR]			[numeric](19, 2),
 [TARIF]			[TINYINT],
 [SPECO] [INT]
  ) -- Категория тарифа

INSERT INTO @T2 ([NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR],[MP],[MP_VKR],[MP_M],[MP_M_VKR],[STATUS],[INV],[INV_VKR],[TARIF],[SPECO])
SELECT [NUM],[SUMMA],[SUMMA_VKR],[SUMMA_M],[SUMMA_M_VKR],[MP],[MP_VKR],[MP_M],[MP_M_VKR],[STATUS],[INV],
		 [INV_VKR] = (CASE WHEN (SUMMA_M - MP_M) = 0 THEN 0 ELSE (SUMMA_M_VKR - MP_M_VKR)*INV/(SUMMA_M - MP_M) END),
		 TARIF = CASE WHEN dbo.is_invalid(@linkFace,dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,NUM,@Year))) = 2 THEN 3 ELSE @TARIF END,
		 [SPECO] = (SELECT TOP 1 [COD_SPO_USL_TRUD] FROM #PERIODY 
						WHERE dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,NUM,@Year)) BETWEEN st_date1 AND st_date2
						AND dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,NUM,@Year)) BETWEEN im_date1 AND im_date2)
FROM 
	@T2_1

if @FlagShow = 1 
	select [num] as [Месяц], [summa] as [Сумма с Н/Г],summa_vkr as [Сумма с Н/Г по ВКР/ЕКР], summa_m as [За мес], 
	summa_m_vkr as [За мес.по ВКР/ЕКР], mp as [Ск.всего], mp_vkr as [Ск.всего по ВКР/ЕКР],mp_m as [Ск. за мес],
	mp_m_vkr as [Ск.за мес.по ВКР/ЕКР], inv as [Льготы], inv_vkr as [Льготы по ВКР/ЕКР], TARIF as [ТАРИФ], [SPECO]  from @T2


DECLARE @WAY_CALC [int]
SELECT @WAY_CALC = WAY_CALC FROM dbo.PAYS WHERE LINK = @RefPay

DECLARE @Pred table  
(
 TARIF TINYINT,	
 [PREDEL]  [numeric](15, 2), 
 [PERCENT] [numeric](8, 2),
 WAY_CALC TINYINT,
 SPECO INT,
 NSPECO VARCHAR(254) )

IF @WAY_CALC<5
	
	IF @FlagMS = 1
		INSERT INTO @Pred (TARIF, [PREDEL],[PERCENT],SPECO,NSPECO)
		SELECT TARIF, [PREDEL],[PERCENT],SPECO=0,NSPECO='' FROM dbo.DICTIONARY_RANGE D
		WHERE
			(LINK_PAYS = @RefPay) 
			AND [DATE] = (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE D1 WHERE D1.TARIF = D.TARIF AND (LINK_PAYS = @RefPay) AND DATE < @DATE1 ORDER BY [DATE] DESC) 
		ORDER BY 1 
	ELSE 
		INSERT INTO @Pred (TARIF, [PREDEL],[PERCENT],SPECO,NSPECO)
		SELECT TOP 1 TARIF, [PREDEL] = 999999999999, [PERCENT],SPECO=0,NSPECO='' 
		FROM dbo.DICTIONARY_RANGE D
		WHERE 
			(LINK_PAYS = @RefPay) 
			AND [DATE] = (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE D1 WHERE D1.TARIF = D.TARIF AND (LINK_PAYS = @RefPay) AND DATE < @DATE1 ORDER BY [DATE] DESC) 
		ORDER BY 1 
ELSE 
BEGIN	
		
	DECLARE @Sex 		[int], 
			  @YearB 	[int], 
			  @Type 		[int]

	SELECT @Sex = SEX, @YearB = CASE WHEN RESIDENT = 1 THEN ISNULL(YEAR(BIRTHDATE),0) 
												ELSE 1966 END -- иностранцы по тарифам как для 66 года и страрше
											FROM dbo.PERSON WHERE LINK =@linkFace
	SET 	@Type = (CASE WHEN (@Sex = 1 AND @YearB < 1953) OR (@Sex = 2 AND @YearB<1957) THEN 1
						WHEN (@Sex = 1 AND @YearB BETWEEN 1953 AND 1966) OR (@Sex = 2 AND  @YearB BETWEEN 1957 AND 1966) THEN 2 
						ELSE 3 END)

	IF @FlagMS = 1 
		INSERT INTO @Pred (TARIF, [PREDEL],[PERCENT],WAY_CALC,SPECO,NSPECO)
		SELECT 
			TARIF,  
			[PREDEL],
			[PERCENT] = (CASE WHEN @Type = 1 THEN PERCENT1 WHEN @Type = 2 THEN PERCENT2 ELSE PERCENT3 END),
			WAY_CALC,
			SPECO,
			NSPECO
		FROM 
			dbo.DICTIONARY_RANGE_PF D
		WHERE
			LINK_PAYS = @RefPay 
			AND [DATE] = (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE_PF D1 WHERE D1.TARIF = D.TARIF AND ISNULL(D1.SPECO,0) = ISNULL(D.SPECO,0) AND LINK_PAYS = @RefPay AND DATE < @DATE1 ORDER BY [DATE] DESC) 
		ORDER BY 1 
	ELSE 
		INSERT INTO @Pred (TARIF, [PREDEL],[PERCENT],WAY_CALC,SPECO,NSPECO)
		SELECT TOP 1 
			TARIF, 
			[PREDEL] = 999999999999,
			[PERCENT] = (CASE WHEN @Type = 1 THEN PERCENT1 WHEN @Type = 2 THEN PERCENT2 ELSE PERCENT3 END),
			WAY_CALC,
			SPECO,NSPECO
		FROM 
			dbo.DICTIONARY_RANGE_PF D
		WHERE
			LINK_PAYS = @RefPay 
			AND [DATE] = (SELECT TOP 1 [DATE] FROM dbo.DICTIONARY_RANGE_PF D1 WHERE D1.TARIF = D.TARIF AND ISNULL(D1.SPECO,0) = ISNULL(D.SPECO,0) AND LINK_PAYS = @RefPay AND DATE < @DATE1 ORDER BY [DATE] DESC) 
		ORDER BY 1 
	END

IF @FlagShow = 1 
	select TARIF as [Тариф], Predel as [Предел], [Percent] as [Процент], NSPECO AS [Спецоценка] from @Pred P
	WHERE EXISTS (SELECT * FROM @T2 B WHERE B.TARIF = P.TARIF AND ISNULL(B.[SPECO],0) = ISNULL(P.[SPECO],0))

DECLARE @res TABLE
([NUM]			[int],
 [SUMMA]		[numeric] (19, 2),
 [SUMMA_M_VKR]	[numeric] (19, 2),
 [PERC]			[numeric] (19, 2),
 [SUM_MON]		[numeric] (19, 2),
 [TARIF]		INT,
 [SPECO]		INT)

INSERT INTO @res([NUM],[SUMMA],[SUMMA_M_VKR],[PERC],[SUM_MON],[TARIF],[SPECO])
SELECT T7.[NUM],T7.[SUMMA],T7.[SUMMA_M_VKR],T7.[PERC], CAST(0 as numeric(15,2)) AS SUM_MON, [TARIF], [SPECO]
FROM  
	(
	SELECT 
		[NUM], 
		[SUMMA] 		 = SUMMA - MP, 
		[SUMMA_M_VKR] = SUMMA_M_VKR - MP_M_VKR,	
		[PERC] 		 = ISNULL((SELECT TOP 1 T.[PERCENT] FROM (SELECT TOP 1 * FROM @Pred P WHERE B.TARIF = P.TARIF AND ISNULL(B.SPECO,0) = ISNULL(P.[SPECO],0) AND PREDEL > (SUMMA - MP + @SUM_DGH) ORDER BY PREDEL) T),0),
		B.[TARIF],
		B.[SPECO]
	 FROM @T2	B
	 UNION
	 SELECT DISTINCT
		[NUM] 			= ISNULL((SELECT MIN(NUM) FROM @T2 B1 WHERE B1.TARIF = B.TARIF AND ISNULL(B1.[SPECO],0) = ISNULL(B.[SPECO],0) AND (SUMMA-MP+@SUM_DGH) > PREDEL),12), 
		[SUMMA] 		= PREDEL - @SUM_DGH, 
		[SUMMA_M_VKR]= 0, 
		[PERC] 		= [PERCENT],  
		B.[TARIF],
		B.[SPECO]		
 	 FROM 
 		@T2 B INNER JOIN @Pred T ON B.TARIF = T.TARIF AND ISNULL(B.[SPECO],0) = ISNULL(T.[SPECO],0)
 	 WHERE 
 		PREDEL < (SELECT TOP 1 (SUMMA - MP + @SUM_DGH) FROM @T2 B1 WHERE B1.TARIF = B.TARIF AND ISNULL(B1.[SPECO],0) = ISNULL(B.[SPECO],0) ORDER BY 1 DESC)
 	) T7


DECLARE Curs CURSOR FAST_FORWARD FOR
SELECT NUM,SUMMA FROM @res ORDER BY [NUM]  

DECLARE @Summa [numeric] (19, 2), 
	@summa_prev [numeric] (19, 2), 
	@num1 [int]


SET @summa_prev = 0
OPEN Curs
FETCH NEXT FROM Curs INTO @num1, @Summa
WHILE @@FETCH_STATUS = 0 BEGIN
	UPDATE @res SET SUM_MON = @Summa - @summa_prev WHERE NUM = @num1 AND SUMMA = @Summa
	SET @summa_prev = @Summa
  	FETCH NEXT FROM Curs INTO @num1, @Summa
END
CLOSE Curs
DEALLOCATE Curs

DECLARE @Result1 TABLE
([NUM]			[int],
 [SUMMA]			[numeric] (19, 2),
 [SUMMA_M_VKR]	[numeric] (19, 2),
 [PERC]			[numeric] (19, 2),
 [SUM_MON]		[numeric] (19, 2),
 [SKIDKA]		[numeric] (19, 2),
 [KOEF]			[numeric] (19, 10), 
 [TARIF]		INT,
 [SPECO]		INT)


INSERT INTO @Result1 ([NUM],[SUMMA],[SUMMA_M_VKR],[PERC],[SUM_MON],[SKIDKA],[KOEF], [TARIF], [SPECO])
SELECT [NUM],[SUMMA],[SUMMA_M_VKR],[PERC],[SUM_MON],
		 [SKIDKA] = dbo.is_min(T1.SUM_MON, ISNULL((SELECT INV FROM @T2 T4  WHERE T4.NUM = T1.NUM),0)  
						- ISNULL((SELECT SUM(T3.SUM_MON) FROM @res T3 WHERE T3.NUM = T1.NUM AND T3.SUMMA < T1.SUMMA), 0)),
		 [KOEF] = (SELECT (CASE WHEN (SUMMA_M - MP_M) = 0 THEN 0 ELSE (SUMMA_M_VKR - MP_M_VKR)/(SUMMA_M - MP_M) END) FROM @T2 T2 WHERE T2.NUM = T1.NUM),
		 [TARIF], [SPECO]
FROM @res T1

DECLARE @RESULT TABLE
([NUM]			[int],
 [SUMMA]			[numeric] (19, 2),
 [SUMMA_M_VKR]	[numeric] (19, 2),
 [PERC]			[numeric] (19, 2),
 [SUM_MON]		[numeric] (19, 2),
 [SKIDKA]		[numeric] (19, 2),
 [KOEF]			[numeric] (19, 10),
 [VYCH] 		[numeric] (19, 2),
 [TARIF]		INT,
 [SPECO]		INT)

INSERT INTO @RESULT ([NUM],[SUMMA],[SUMMA_M_VKR],[PERC],[SUM_MON],[SKIDKA],[KOEF], [TARIF], [SPECO])
SELECT [NUM],[SUMMA],[SUMMA_M_VKR],[PERC],[SUM_MON],
		 [SKIDKA] = (CASE WHEN SKIDKA < 0 THEN 0 ELSE SKIDKA END),
		 [KOEF], [TARIF], [SPECO]
FROM @Result1

DECLARE @Razn 			[numeric](15, 2), 
	  @NalCurr 	[numeric](15, 2),
	  @Sum1 		[numeric](15, 2)

--Расчет с копейками
SET @NalCurr = (SELECT sum(ROUND((PERC * (COALESCE(SUM_MON,0) - COALESCE(SKIDKA,0))* COALESCE(KOEF,0)/100) * 100, 2) / 100) FROM @RESULT )

--Сумма ранее начисленного взноса
SET @Sum1 = ISNULL((SELECT SUM(SJ.SUMMA) FROM dbo.S_J_C_Short SJ 
WHERE SJ.LINK_VKR = @LinkVKR 
	--AND ( (SJ.LINK_EKR IN (@LINK_EKR,@LINK_EKR_ADD) AND @LINK_EKR <> @LINK_211EKR) OR (@LINK_EKR = @LINK_211EKR AND SJ.LINK_EKR IN (@LINK_211EKR,@LINK_213EKR)) )
	AND ( (SJ.LINK_EKR IN (@LINK_EKR,@LINK_EKR_ADD) AND @LINK_EKR <> @LINK_211EKR) OR (@LINK_EKR = @LINK_211EKR AND SJ.LINK_EKR = @LINK_EKR) )
	AND SJ.LINK_PAYS = @RefPay 
	AND (SJ.LINK_FACE = @linkFace) 
	AND MONTH_BEGIN <= @Month 
	AND YEAR_BEGIN=@Year 
	AND sj.LINK_DEP = @DEP_LINK),0)

--IF --ЕСЛИ ГОДОВОЙ ДОХОД ПО ВСЕМ ИСТОЧНИКАМ < 0
--	(SELECT SUM(SUMMA) FROM @RESULT) < 0 
--		--AND @Sum1 = 0 
--		-- И ЕСЛИ ТЕКУЩИЙ НАЛОГ ПОЛУЧАЕТСЯ < 0
--		AND @NalCurr < 0
--	SET @NalCurr = 0
	
SET @Razn = @NalCurr - @Sum1

DECLARE @FLG INT
SELECT TOP 1 @FLG = ISNULL(CONVERT(INT,VALUE),0) 
FROM S_OPTIONS WHERE OBJECT = (SELECT TOP 1 LINK FROM S_OBJECTS WHERE CODE = 'ESN_OPTIONS_FLG') AND SID IS NULL

IF @Razn <0 AND @FLG = 0
	SET @Razn=0

SELECT [SUMMA] 		= ISNULL(SUMMA_VKR,0), 
	 [SUMMA_VKR] 	= ISNULL(SUMMA_M_VKR, 0),
	 [SUM_DED] 		=	CASE WHEN ISNULL(SUMMA_VKR, 0) > 0 
						THEN
							ISNULL((SELECT TOP 1 MP_VKR FROM @T2 WHERE NUM = @Month), 0)
						ELSE 0 END,	
	 [INV_M] 		= CASE WHEN ISNULL(SUMMA_VKR, 0) > 0 
						THEN
							ISNULL((SELECT SUM(SKIDKA*KOEF) FROM @RESULT WHERE NUM = @Month),0)
						ELSE 0 END,
	 [INV] 			= CASE WHEN ISNULL(SUMMA_VKR, 0) > 0 
						THEN
							ISNULL((SELECT SUM(SKIDKA*KOEF) FROM @RESULT WHERE NUM <= @Month),0)
						ELSE 0 END,
	 [DED_M] 		= CASE WHEN ISNULL(SUMMA_VKR, 0) > 0 
						THEN
							ISNULL((SELECT TOP 1 MP_M_VKR FROM @T2 WHERE NUM = @Month), 0)
						ELSE 0 END,
	 [PERC]			= ISNULL((SELECT MIN(PERC) FROM @RESULT WHERE NUM = @Month),0),
	 [NALOG] 		= @NalCurr, 
	 [NAL_DED] 		= @Sum1, 
	 [NAL_CUR] 		= @Razn,
	 [TARIF]		= ISNULL((SELECT MIN([TARIF]) FROM @RESULT WHERE NUM = @Month),0), 
	 [SPECO]		= ISNULL((SELECT MIN([SPECO]) FROM @RESULT WHERE NUM = @Month),0),
	 [NSPECO]		= (SELECT TOP 1 CODE FROM dbo.SZV4_SPR WHERE LINK = ISNULL((SELECT MIN([SPECO]) FROM @RESULT WHERE NUM = @Month),0) )
FROM 
	@T1 
WHERE 
	NUM = @Month

SET NOCOUNT OFF




GO


GRANT EXECUTE ON dbo.[SALARY_FILL_DED_ESN_VKR] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[UNLOAD_S_ACCOUNTS_1]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[UNLOAD_S_ACCOUNTS_1]

GO
CREATE PROCEDURE [dbo].UNLOAD_S_ACCOUNTS_1 (@MASK VARCHAR(50))
--ВЫГРУЗКА СЧЕТОВ ПЛАНА СЧЕТОВ С ВЫБОРОМ ПО МАСКЕ
--ПРИМЕР ВЫЗОВА 
--UNLOAD_S_ACCOUNTS_1 @MASK = '%209.30'
AS

BEGIN


IF OBJECT_ID('TEMPDB..#tmp_UNLOAD_S_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #tmp_UNLOAD_S_ACCOUNTS

CREATE TABLE #tmp_UNLOAD_S_ACCOUNTS (LINK INT)

INSERT INTO #tmp_UNLOAD_S_ACCOUNTS (LINK)
SELECT LINK FROM dbo.s_accounts where code like @MASK

--Собственно сама выгрузка
EXEC DBO.UNLOAD_S_ACCOUNTS

IF OBJECT_ID('TEMPDB..#tmp_UNLOAD_S_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #tmp_UNLOAD_S_ACCOUNTS

END

GO


GRANT EXECUTE ON dbo.[UNLOAD_S_ACCOUNTS_1] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_ANALIT_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_ANALIT_GS]

GO

-- сведеняи о хар-ке кадрового состава
CREATE PROCEDURE [dbo].REP_ANALIT_GS
	@date1 datetime
AS
	
DECLARE @dep_name varchar(100)
DECLARE @dep_link varchar(100)
set @dep_link = (SELECT DEP_LINK FROM dbo.USER_DEP)
SET @dep_name = (SELECT FULL_NAME FROM dbo.DEPARTMENTS WHERE LINK = @dep_link)
-------------------------------------------------------------------------------------------------------
--*** ВРЕМЕННЫЕ ТАБЛИЦЫ ДАННЫХ****--
-------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------
----- 1) /* ИНФОРМАЦИЯ ПО ШТАТНОЙ ЧИСЛЕННОСТИ 
---------------------------------------------------------------------
CREATE TABLE #STAFF_REC (STAFF_LINK INT, NUM_STAKE NUMERIC(18,2), [END] TINYINT)
CREATE INDEX #IX_REC_STAFF_REC ON #STAFF_REC (STAFF_LINK)

INSERT INTO #STAFF_REC (STAFF_LINK, NUM_STAKE, [END])
SELECT LINK, SUM(NUM_STAKE), 0 
FROM dbo.DICTIONARY_STAFF_FN(@date1) 
WHERE DEP_LINK = @DEP_LINK AND gossl in (1,2,3, 4) and ISNULL(DEL_SUBDIV,1) = 0	AND @date1 BETWEEN date_begin AND date_end
GROUP BY LINK
---------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
/*SELECT *
INTO #GsEmpl
FROM GetGSEmplToDepAndDateNew(@dep_link,@date1)

SELECT * FROM #GsEmpl

-- EXEC REP_ANALIT_GS '20141111'

*/

-------------------------------------------------------------------------------------------------------
----  2)/* ФАКТИЧЕСКАЯ ЧИСЛЕННОСТЬ */
-------------------------------------------------------------------------------------------------------
CREATE TABLE #EMPL_FAKT (EMPL_LINK INT, PERS_LINK INT , STAFF_LINK INT, NUM_STAKE NUMERIC(18,2), [END] TINYINT )

INSERT INTO #EMPL_FAKT (EMPL_LINK,PERS_LINK, STAFF_LINK, NUM_STAKE, [END])
SELECT kep.LINK, kep.PERS_LINK, kep.STAFF_HEAD, SUM(kep.NUM_STAKE), 1 
FROM dbo.KU_EMPL_PLACING_FN(@date1) kep
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@Date1) S ON S.STAFF_LINK = kep.STAFF_LINK 
WHERE KEP.DEP_LINK = @DEP_LINK  and KEP.NOTWORK<>1 AND KEP.SACK = 0 
AND s.gossl in (1,2,3, 4)
GROUP BY KEP.LINK,kep.PERS_LINK, KEP.STAFF_HEAD


-------------------------------------------------------------------------------------------------------
----  3)/*замещающие*/
-------------------------------------------------------------------------------------------------------
SELECT		
		[TYPE]		=	2,
		DATE		=	SU.DATE_BEGIN,
		SUB_LINK	=	SU.S_SUBDIV_LINK,
		SUB_NAME	=	SU.S_SUBDIV,
		POST_NAME	=	SU.S_POST,
		FIO			=	SU.FIO,
		OSNOV		=	RTRIM(ISNULL(SU.REASON,'')) + 								-- ОСНОВАНИЕ замещения
		   ' приказ № ' + RTRIM(LTRIM(SU.NUMBER)) + ' от ' + CONVERT(VARCHAR(10),SU.[DATE],104),
		PRICHINA	=	ISNULL(SU.REASON,'') ,
		[EMPL]	= SU.EMPL_LINK,
		S_EMPL = SU.subst_empl_link,
		[CAT_G_CODE] = isnull(s.kat_gos_CODE,0)  -- категория гос должности 1-Руководители, 2-Помощники(советники),3-Специалисты,4-Обеспечивающие специалисты
INTO	#SUBST
FROM dbo.SUBST SU 
	inner join dbo.KU_EMPL_PLACING_FN(@Date1) kep on kep.link = SU.subst_empl_link
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@Date1) S ON S.STAFF_LINK = kep.STAFF_LINK 
	LEFT JOIN dbo.EMPL E ON E.LINK = SU.EMPL_LINK
	LEFT JOIN dbo.PERSON P ON P.LINK = E.PERS_LINK 
	
WHERE	 @DATE1 BETWEEN SU.DATE_BEGIN AND ISNULL(SU.DATE_END,'31.12.2999')
	AND SU.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND SU.ACTIVE = 1
	AND s.gossl in (1,2,3, 4)

-------------------------------------------------------------------------------------------------------
-- 4)  госслужащие, кторорые находились в отпусках по беременности и родам и в отпусках по уходу за ребенком
------------------------------------------------------------------------------------------------------- 
DECLARE @varVAK_EMPLS TABLE(LINK_EMPL INT)

INSERT	INTO @varVAK_EMPLS

SELECT	EP.LINK
FROM	DBO.KU_EMPL_PLACING_FN(@Date1) EP	
		LEFT JOIN dbo.DICTIONARY_STAFF_FN(@Date1) S ON S.STAFF_LINK = EP.STAFF_LINK 
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0														-- не уволенные на дату @Date1
	AND s.gossl in (1,2,3, 4)											
	AND EXISTS (SELECT * FROM dbo.vacation v 
INNER JOIN  dbo.VACATION_VID vv ON vv.link = v.type_link  
	INNER JOIN dbo.typ_days td ON td.LINK = vv.TYPE_LINK  AND td.WORK_D IN (13,7) AND isnull(vv.adm,0) <> 1  
	                WHERE  v.empl_link = EP.LINK AND @Date1 BETWEEN v.date_begin and v.date_END  AND V.dep_link = EP.DEP_LINK 
							AND V.active = 1)  	
							
-- удаляются те гос служащие , которых не замещали во время их отсутствия
DELETE FROM @varVAK_EMPLS 
WHERE LINK_EMPL not IN (SELECT s_empl FROM #SUBST )			

-- из фактичеки работающих удаляются сотрудники которых замещали 
DELETE FROM #EMPL_FAKT 
WHERE EMPL_LINK IN (SELECT LINK_EMPL FROM @varVAK_EMPLS )	

-------------------------------------------------------------------------------------------------------
-- ТАБЛИЦА ДОЛЖНОСТЕЙ ШТАТНОГО РАСПИСАНИЯ
-------------------------------------------------------------------------------------------------------
select	[STAFF_LINK] =	 D_ST.STAFF_LINK,				-- ССЫЛКА НА ДОЛЖНОСТЬ ШТАТНОГО РАСПИСАНИЯ
		[NUM_STAKE] = 	 CONVERT(INT,D_ST.num_stake),	-- КОЛИЧЕСТВО СТАВОК ПО ШТАТУ
		[KAT_GOS_CODE] = D_ST.kat_gos_CODE,				-- КАТЕГОРИЯ ДОЛЖНОСТИ
		[GR_GOS_CODE] =  D_ST.gr_gos_CODE,				-- ГРУППА ДОЛЖНОСТИ
		[GOSSL] = 	 D_ST.GOSSL							-- ТИП ДОЛЖНОСТИ
into	#STAFF_INFO
from	dbo.DICTIONARY_STAFF_FN(@date1) D_ST
where	D_ST.DEP_LINK = (select dep_link from user_dep)	-- ДОЛЖНОСТИ ТОЛЬКО ТЕКУЩЕЙ ОРГАНИЗАЦИИ
	and D_ST.deleted = 0								-- ТОЛЬКО ДЕЙСТВУЮЩИЕ НА ДАННУЮ ДАТУ
	and D_ST.GOSSL in (1,2,3,4)								-- ТОЛЬКО ГОСУДАРСТВЕННОЙ И ГОСУДАРСТВЕННОЙ ГРАЖДАНСКОЙ СЛУЖБЫ
	and ISNULL(D_ST.DEL_SUBDIV,1) = 0					-- ТОЛЬКО ДОЛЖНОСТИ ДЕЙСТВУЮЩИХ ПОДРАЗДЕЛЕНИЙ


-------------------------------------------------------------------------------------------------------
-- ТАБЛИЦА ОБРАЗОВАНИЙ СОТРУДНИКОВ
-------------------------------------------------------------------------------------------------------
SELECT	TT.LINK AS LINK_PERS,
	TT.TYPE,
	TT.ACAD,
	TT.ACAD_ST,
	TT.POSL,
	TT.TWOO,
	TT.SATISFY,
	TT.STUD,
	CASE
	  WHEN	LEN(TT.SPEC) = 0 THEN 0
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
 		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%юриспруденция%'
 		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%международные отношения%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '04'
		)
		THEN 4									-- ГУМАНИТАРНЫЕ И СОЦИАЛЬНЫЕ НАУКИ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%юриспруденция%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '05'
		)
		THEN 5									-- ЮРИСПРУДЕНЦИЯ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%международные отношения%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '06'
		)
		THEN 6									-- МЕЖДУНАРОДНЫЕ ОТНОШЕНИЯ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		OR TT.SPEC IN ('0303','5216','5221'))
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%государственное и муниципальное управление%'
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%упрвление персоналом%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '07'
		)
		THEN 7									-- ЭКОНОМИНИКА И УПРАВЛЕНИЕ
	  WHEN	
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%Экономика%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '08'
		)
		THEN 8									-- ЭКОНОМИНИКА
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		OR TT.SPEC IN ('0303','5216','5221'))
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%государственное и муниципальное управление%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '09'
		)
		THEN 9									-- ГОСУДАРСТВЕННОЕ И МУНИЦИПАЛЬНОЕ УПРАВЛЕНИЕ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('01','51')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '10'
		)
		THEN 10									-- ФИЗИКОМАТЕМАТИЧЕСКИЕ И ЕСТЕСТВЕННЫЕ НАУКИ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('03','54')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '11'
		)
		THEN 11									-- ОБРАЗОВАНИЕ И ПЕДАГОГИКА
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('04')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '12'
		)
		THEN 12									-- ЗДРАВООХРАНЕНИЕ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('05')
		AND TT.SPEC IN ('5218','5406')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '13'
		)
		THEN 13									-- КУЛЬТУРА И ИСКУССТВО
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('22')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '14'
		)
		THEN 14									-- ИНФОРМАЦИОННАЯ БЕЗОПАСНОСТЬ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('31','56')
		AND TT.SPEC IN ('1710','2710')		
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '15'
		)
		THEN 15								-- СЕЛЬСКОЕ И РЫБНОЕ ХОЗЯЙСТВО
		
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('55','22','21','20','18')
		AND TT.SPEC IN ('6135','6123')		
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '16'
		)
		THEN 16								-- ТЕХНИЧЕСКОЕ(ИНЖЕНЕРНОЕ)	
	  ELSE	17
	END AS SPEC
INTO #EDUC_EMPL
FROM
(
SELECT	[LINK] = T.LINK,								-- ФИЗИЧЕСКОЕ ЛИЦО
	[TYPE] = T.TYPE,								-- ТИП ОБРАЗОВАНИЯ (СМ. НИЖЕ)
	[ACAD] = CASE									-- УЧЕНАЯ СТЕПЕНЬ ПРИ НАЛИЧИИ ВЫСШЕГО (СМ. НИЖЕ)
		   WHEN T.TYPE = 1 THEN T.ACAD_DEGREE
		   ELSE 0
		 END,
	[POSL] = CASE									-- ПОСЛЕВУЗОВСКОЕ ПРИ НАЛИЧИИ ВЫСШЕГО ( 1 - ЕСТЬ, 0 - НЕТ)
		   WHEN T.TYPE = 1 AND EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION		
					      WHERE PERS_LINK = T.LINK AND EDUC_CODE = 19) THEN 1
		   ELSE 0
		 END,
	[TWOO] = CASE									-- 2 И БОЛЕЕ ВЫСШИХ ( 1 - ЕСТЬ, 0 - НЕТ)
		   WHEN	T.TYPE = 1 AND (SELECT COUNT(*) FROM dbo.KU_PERS_EDUCATION
					WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18) > 1 THEN 1
		   ELSE 0
		 END,
	[SPEC] = CASE									-- СПЕЦИАЛЬНОСТЬ
		   WHEN T.TYPE = 1 THEN
		      CASE WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
   			               WHERE PERS_LINK = T.LINK AND SATISFY = 1)
				THEN (SELECT TOP 1 ISNULL(SPEC_CODE,'!!!') FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND SATISFY = 1)
			   ELSE (SELECT TOP 1  ISNULL(SPEC_CODE,'!!!') FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18)
		      END
		   ELSE ''
		 END,
	[SATISFY] = (select top 1 SATISFY from dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK),   --  СООТВЕТСТВУЕТ ПРОФИЛЮ ДЕЯТЕЛЬНОСТИ
	[STUD] = CASE  
			WHEN T.TYPE = 0 and EXISTS (SELECT * FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18 and ISNULL(DATE_BEGIN,0) <>0 and ISNULL(DATE_END,0)=0 AND ISNULL(DOC_DATE,0)=0)
					THEN 0
					ELSE 1 END,
	[ACAD_ST] = CASE									-- УЧЕНОЕ ЗВАНИЕ ПРИ НАЛИЧИИ ВЫСШЕГО (СМ. НИЖЕ)
		   WHEN T.TYPE = 1 THEN T.ACAD_DEGREE
		   ELSE 0
		 END			
			   			                      
FROM	(
	select	[LINK] = P.LINK,							-- ФИЗИЧЕСКОЕ ЛИЦО
		[TYPE] =								-- ОБРАЗОВАНИЕ (0 - БЕЗ ПРОФЕССИОНАЛЬНОГО,
			CASE								--		1 - ВЫСШЕЕ ПРОФЕССИОНЛЬНОЕ,
			  WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION			--		2 - СРЕДНЕЕ ПРОФЕССИОНАЛЬНОЕ)
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 18) THEN 1
			  WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 11) AND
			       NOT EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 18) THEN 2
			  ELSE 0
			END,
		[ACAD_DEGREE] = 							-- УЧЕНАЯ СТЕПЕНЬ (1 - ДОКТОР НАУК,
			CASE								--		   2 - КАНДИДАТ НАУК)
			  WHEN (SELECT CODE FROM dbo.ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK) = 1 THEN 1
			  WHEN (SELECT CODE FROM dbo.ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK) = 2 THEN 2
			  ELSE 0
			END,
		[ACAD_STATUS] = 							-- УЧЕНОЕ ЗВАНИЕ 
			CASE
			  WHEN (SELECT ISNULL(CODE,'') FROM dbo.ACAD_STATUS WHERE LINK = P.ACAD_STATUS_LINK) <> ''  THEN 1
			  ELSE 0
			END	
	from	PERSON P
			INNER JOIN #EMPL_FAKT e on p.link = e.PERS_LINK
	) T
) TT

-------------------------------------------------------------------------------------------  
-----  сведения о вакантных должностях 
-------------------------------------------------------------------------------------------
	declare @VAC_CNT int  
	SET @VAC_CNT	=	(SELECT SUM(DS.FREE_STAKES)
							FROM DBO.DICTIONARY_STAFF_FN(@Date1)  DS
							WHERE @DATE1 BETWEEN DS.DATE_BEGIN AND DS.DATE_END
							AND DS.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
							AND DS.DEL_SUBDIV = 0 AND DS.FREE_STAKES >0 
							AND ds.gossl in (1,2,3, 4))
-------------------------------------
---------------------------------------------------------------------------------------

CREATE TABLE #EMPLS_INFO(LINK INT, PERS_LINK INT, GOSSL INT, KAT_GOS_CODE VARCHAR(10),
GR_GOS_CODE VARCHAR(10), CHIN INT, EXPIR INT, [TYPE] INT, ACAD INT,ACAD_ST INT, POSL INT, TWOO INT, SPEC INT,SATISFY int, STUD INT,
SEX INT, AGE INT, NOTWORK INT, NEW_FACE INT, TYPE_MOVE INT, TEMP_LINK INT, DATE_END2 DATETIME)


INSERT	#EMPLS_INFO (LINK, PERS_LINK, GOSSL, KAT_GOS_CODE, GR_GOS_CODE, SEX, AGE, CHIN, EXPIR,
					[TYPE], ACAD,ACAD_ST, POSL, TWOO, SPEC,SATISFY, STUD, NOTWORK, NEW_FACE, TYPE_MOVE, TEMP_LINK, DATE_END2)
SELECT
-- ССЫЛКА НА СОТРУДНИКА
	[LINK] = 			EM_PL.LINK,	
-- ССЫЛКА НА СОТРУДНИКА							
	[PERS_LINK] = 		EM_PL.PERS_LINK,	
-- ТИП ДОЛЖНОСТИ (1- гос.гражд, 2- гос)					
	[GOSSL] = 			ST.GOSSL,		
-- КАТЕГОРИЯ ДОЛЖНОСТИ (1- рук, 2- помощ, 3- спец, 4- об.спец)							
	[KAT_GOS_CODE] =	ST.kat_gos_CODE,
-- ГРУППА ДОЛЖНОСТИ (1- высш, 2- глав, 3- вед, 4-с тар, 5- млад)						
	[GR_GOS_CODE] =		ST.gr_gos_CODE,
-- ПОЛ (1- муж, 2- жен)						
	[SEX] = 			P.SEX,			
-- ВОЗРАСТ							
	[AGE] =				dbo.ku_GetPersAge(P.LINK,@date1),		
-- НАЛЧИЧИЕ КЛАССНОГО ЧИНА
	[CHIN] =	CASE										
					WHEN EXISTS(SELECT * FROM dbo.EMPL_CHIN WHERE EMPL_LINK = EM_PL.link and date < @date1)
						THEN 1
					ELSE 0
				END,
-- СТАЖ ГОСУДАРСТВЕННОЙ ГРАЖДАНСКОЙ СЛУЖБЫ (В ГОДАХ),
	[EXPIR] = 	 dbo.ku_GetEmplExpir(EM_PL.LINK,'YEAR','GOS_NADB',@date1),
-- СВЕДЕНИЯ ПО ОБРАЗОВАНИЮ	
	EDUC.TYPE, EDUC.ACAD, EDUC.ACAD_ST, EDUC.POSL, EDUC.TWOO, EDUC.SPEC,EDUC.[SATISFY], EDUC.[STUD],
	-- ДАННЫЕ ДЛЯ УСЛОВИЙ ВЫБОРКИ СОТРУДНИКОВ
	[NOTWORK] =		EM_PL.NOTWORK,
	[NEW_FACE] =	IM.NEW_FACE,
	[TYPE_MOVE] = 	IM.TYPE,
	[TEMP_LINK] =	IM.TEMP_LINK,
	[DATE_END2] = 	IM.DATE_END2
FROM	#EMPL_FAKT ef
		inner join dbo.KU_EMPL_PLACING_FN(@date1) EM_PL ON ef.EMPL_LINK = EM_PL.LINK
		LEFT JOIN dbo.DICTIONARY_STAFF_FN(@date1) ST
			ON EM_PL.STAFF_LINK = ST.STAFF_LINK
		LEFT JOIN dbo.PERSON P
			ON EM_PL.PERS_LINK = P.LINK
		LEFT JOIN #EDUC_EMPL EDUC
			ON EM_PL.PERS_LINK = EDUC.LINK_PERS
		LEFT JOIN dbo.ITEM_MOVE IM
			ON EM_PL.ITEM_MOVE_LINK = IM.LINK
WHERE	EM_PL.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)		-- СОТРУДНИКИ ТОЛЬКО ТЕКУЩЕЙ ОРГАНИЗАЦИИ
			AND EM_PL.sack = 0										-- ТОЛЬКО РАБОТАЮЩИЕ (ИСКЛЮЧАЕМ УВОЛЕННЫХ)
			AND isnull(EM_PL.DATE_BEGIN,0) != 0						-- ГАРАНТИРОВАННО ПРИНЯТЫХ (ИСКЛЮЧАЕМ ТЕХ, КТО ВИСИТ В ПРОЕКТАХ ПРИКАЗАХ)
			AND ST.GOSSL in (1,2,3,4)

-------------------------------------------------------------------------------------------	

SELECT 
		SH_CNT		=	(select count(*) from #STAFF_REC),	-- штатная численность
		SUBST_CNT	=	(select count(*) from #SUBST),		-- Численность  временно замещающих должности на период отсутствия основного работника
		FACT_CNT	=	(select count(*) from #EMPL_FAKT),		-- фактическая численность
		---------- количество должностей по категориям   1- рук, 2- помощ, 3- спец, 4- об.спец
		RUK_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 1),		-- руководителей
		POM_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 2),		-- помощников
		SP_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 3),		-- специалистов
		OSP_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 4),		-- обеспечивающих специалистов
		---------- количество должностей по группам   1- высш, 2- глав, 3- вед, 4-с тар, 5- млад
		GVIS_CNT 	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 1),		-- высших
		GGLAV_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 2),		-- главных
		GVED_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 3),		-- ведущих
		GSTAR_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 4),		-- старших
		GMLAD_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 5),		-- младших
		---------- Количество гражданских служащих по возрасту
		AGG_30		=	(select count(*) from #EMPLS_INFO where age < 30) ,	-- возраст до 30 лет
		AGG_30_39	=	(select count(*) from #EMPLS_INFO where age between 30 and 39 ),	-- возраст от 30 до 39 лет
		AGG_40_49	=	(select count(*) from #EMPLS_INFO where age between 40 and 49 ),	-- возраст от 40 до 49 лет
		AGG_50_59	=	(select count(*) from #EMPLS_INFO where age between 50 and 59 ),	-- возраст от 50 до 59 лет
		AGG_60_65	=	(select count(*) from #EMPLS_INFO where age between 60 and 65 or age >65),	-- возраст от 60 до 65 лет
		AGG_AVG		=	(select avg(age) from #EMPLS_INFO),	--средний возраст
		---------- Количество гражданских служащих пенсионного возраста (мужчины – 60 лет и старше, женщины – 55 лет и старше)
		AGE_P_All	= ((select count(*) from #EMPLS_INFO where age >=60 AND SEX = 0) + (select count(*) from #EMPLS_INFO where age >=55 AND SEX = 1)),--всего
		AGE_P_Z		= (select count(*) from #EMPLS_INFO where age >=55 AND SEX = 1),-- КОЛИЧЕСТВО ЖЕНЩИН
		AGE_P_M		= (select count(*) from #EMPLS_INFO where age >=60 AND SEX = 0),-- КОЛИЧЕСТВО МУЖЧИН
		---------- Количество гражданских служащих по образованию:
		OBR_VUZ		= (select count(*) from #EMPLS_INFO where [TYPE] = 1),	-- образование 1 высшее
		----------- в том числе по укрупненным группам специальностей и направлениям подготовки:
		SPEC_4  = (select count(*) from #EMPLS_INFO where SPEC = 4), -- ГУМАНИТАРНЫЕ И СОЦИАЛЬНЫЕ НАУКИ
		SPEC_5  = (select count(*) from #EMPLS_INFO where SPEC = 5), -- ЮРИСПРУДЕНЦИЯ
		SPEC_6  = (select count(*) from #EMPLS_INFO where SPEC = 6), -- МЕЖДУНАРОДНЫЕ ОТНОШЕНИЯ
		SPEC_7  = (select count(*) from #EMPLS_INFO where SPEC = 7), -- ЭКОНОМИНИКА И УПРАВЛЕНИЕ
		SPEC_8  = (select count(*) from #EMPLS_INFO where SPEC = 8), -- ЭКОНОМИНИКА
		SPEC_9  = (select count(*) from #EMPLS_INFO where SPEC = 9), -- ГОСУДАРСТВЕННОЕ И МУНИЦИПАЛЬНОЕ УПРАВЛЕНИЕ
		SPEC_10  = (select count(*) from #EMPLS_INFO where SPEC = 10), -- ФИЗИКОМАТЕМАТИЧЕСКИЕ И ЕСТЕСТВЕННЫЕ НАУКИ
		SPEC_11  = (select count(*) from #EMPLS_INFO where SPEC = 11), -- ОБРАЗОВАНИЕ И ПЕДАГОГИКА
		SPEC_12  = (select count(*) from #EMPLS_INFO where SPEC = 12), -- ЗДРАВООХРАНЕНИЕ
		SPEC_13  = (select count(*) from #EMPLS_INFO where SPEC = 13), -- КУЛЬТУРА И ИСКУССТВО
		SPEC_14  = (select count(*) from #EMPLS_INFO where SPEC = 14), -- ИНФОРМАЦИОННАЯ БЕЗОПАСНОСТЬ
		SPEC_15  = (select count(*) from #EMPLS_INFO where SPEC = 15), -- СЕЛЬСКОЕ И РЫБНОЕ ХОЗЯЙСТВО
		SPEC_16  = (select count(*) from #EMPLS_INFO where SPEC = 16), -- ТЕХНИЧЕСКОЕ(ИНЖЕНЕРНОЕ)	
		SPEC_17  = (select count(*) from #EMPLS_INFO where SPEC = 17), -- ДРУГИЕ
		SATISFY  = (select count(*) from #EMPLS_INFO where SATISFY = 1), -- соответствующее профилю деятельности
		OBR_2VUZ = (select count(*) from #EMPLS_INFO where TWOO = 1),	-- образование 2 и более высших
		OBR_SRED = (select count(*) from #EMPLS_INFO where [TYPE] = 2),	-- образование среднее проф.
		OBR_0VUZ = (select count(*) from #EMPLS_INFO where [TYPE] = 0),	-- не имеющие высшего и среднего профессионального образования
		STUD	 = (select count(*) from #EMPLS_INFO where [TYPE] = 0 and STUD = 1), -- не имеющих высшего образования, обучающихся в образовательных организациях
			
		U_ST_CNT = (select count(*) from #EMPLS_INFO where ACAD > 0 OR ACAD_ST > 0),	-- ученая степень, ученое звание
		----------  Количество гражданских служащих по стажу гражданской службы
		S_1			= (select count(*) from #EMPLS_INFO where expir < 1),					-- стаж гос.службы до 1 года
		S_1_5		= (select count(*) from #EMPLS_INFO where expir >=1 and expir < 5),	-- стаж гос.службы от 1 до 5 лет
		S_5_10		= (select count(*) from #EMPLS_INFO where expir >=5 and expir < 10),	-- стаж гос.службы от 5 до 10 лет
		S_10_15		= (select count(*) from #EMPLS_INFO where expir >=10 and expir < 15),	-- стаж гос.службы от 10 до 15 лет
		S_15_25		= (select count(*) from #EMPLS_INFO where expir >=15 and expir < 25),	-- стаж гос.службы от 15 до 25 лет
		S_25		= (select count(*) from #EMPLS_INFO where expir >=25),				-- стаж гос.службы от 25 лет
		W_CNT		= (select count(*) from #EMPLS_INFO where SEX = 1),-- КОЛИЧЕСТВО ЖЕНЩИН
		M_CNT		= (select count(*) from #EMPLS_INFO where SEX = 0),-- КОЛИЧЕСТВО МУЖЧИН	
		VAC_CNT     = @VAC_CNT ,---Количество вакантных должностей в органе		
		USR_PHONE   = LTRIM(RTRIM((select PHONES from RA_GET_USER_INFO(null)))) -- Телефон Составителя 

		

DROP TABLE #EMPL_FAKT
DROP TABLE #SUBST
DROP TABLE #STAFF_INFO
DROP TABLE #EDUC_EMPL 


GO


GRANT EXECUTE ON dbo.[REP_ANALIT_GS] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[REP_REESTR_GS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[REP_REESTR_GS]

GO

/*----------------------------------------------------------
------------------------------------------------------------
	РЕЕСТР ГОСУДАРСТВЕННЫХ ГРАЖДАНСКИХ СЛУЖАЩИХ
		Шорков И.А. 	11.11.2014 г.
------------------------------------------------------------
----------------------------------------------------------*/

CREATE PROCEDURE dbo.REP_REESTR_GS
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS

DECLARE @dDate1 DATETIME, @dDate2 DATETIME


SET @dDate1 = dbo.ConvertDMY2Date(1,1,@cYear1) 

IF @nCombo1 = 1 	
	SET @dDate2 = dbo.ConvertDMY2Date(30,6,@cYear1) 
IF @nCombo1 = 2 
	SET @dDate2 = dbo.DateEndOfYear(@dDate1) 


DECLARE @dep_name varchar(100)
DECLARE @dep_link varchar(100)
set @dep_link = (SELECT DEP_LINK FROM dbo.USER_DEP)
SET @dep_name = (SELECT FULL_NAME FROM dbo.DEPARTMENTS WHERE LINK = @dep_link)


----------------------------------------------------------------------------
--- РАЗДЕЛ 1. Сведения о государственных гражданских служащих
---Раздел 2. Сведения о временно отсутствующих гражданских служащих
---(отпуск по беременности и родам, отпуск по уходу за ребенком,
--- длительный отпуск без сохранения денежного содержания)
----------------------------------------------------------------------------
-- выборка сотрудников из фильтра
DECLARE @varKSEMPLS TABLE(LINK_EMPL INT, RAZD TINYINT)
-- РАЗДЕЛ 1
INSERT	INTO @varKSEMPLS
SELECT	EP.LINK,
		RAZD = 1 
FROM	DBO.KU_EMPL_PLACING_FN(@dDate2) EP	
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0												-- работающие на дату @dDate
-- Раздел 2
INSERT	INTO @varKSEMPLS
SELECT	EP.LINK,
		RAZD = 2
FROM	DBO.KU_EMPL_PLACING_FN(@dDate2) EP	
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0												-- не уволенные на дату @dDate2
	AND EXISTS (SELECT * FROM vacation v 
INNER JOIN  VACATION_VID vv ON vv.link = v.type_link  
	INNER JOIN typ_days td ON td.LINK = vv.TYPE_LINK  AND td.WORK_D IN (13,7,8) AND isnull(vv.adm,0) <> 1  
	                WHERE  v.empl_link = EP.LINK AND v.date_END >=  @dDate2 AND V.dep_link = EP.DEP_LINK 
							AND V.active = 1)  	
if (select count(*) from @varKSEMPLS where RAZD = 2)=0
	INSERT	INTO @varKSEMPLS   select 0 , 2 
			  								
-- Раздел 7 госслужащие, кторорые находились в отпусках по беременности и родам и в отпусках по уходу за ребенком
INSERT	INTO @varKSEMPLS
SELECT	EP.LINK,
		RAZD = 7
FROM	DBO.KU_EMPL_PLACING_FN(@dDate2) EP	
		LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) S ON S.STAFF_LINK = EP.STAFF_LINK 
WHERE	EP.DEP_LINK = (select dep_link from user_dep)								-- только текцщей организации
	AND ISNULL(EP.DATE_BEGIN,0) != 0									-- ТОЛЬКО гарантированно принятые на работу
	AND SACK = 0														-- не уволенные на дату @Date1
	AND s.gossl in (1,2,3, 4)											
	AND EXISTS (SELECT * FROM dbo.vacation v 
INNER JOIN  dbo.VACATION_VID vv ON vv.link = v.type_link  
	INNER JOIN dbo.typ_days td ON td.LINK = vv.TYPE_LINK  AND td.WORK_D IN (13,7) AND isnull(vv.adm,0) <> 1  
	                WHERE  v.empl_link = EP.LINK AND v.date_END >=  @dDate2  AND V.dep_link = EP.DEP_LINK 
							AND V.active = 1)  	
if (select count(*) from @varKSEMPLS where RAZD = 7)=0
	INSERT	INTO @varKSEMPLS   select 0 , 7 															
--------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------ДОПОЛНИТЕЛЬНЫЕ ТАБЛИЦЫ --------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------

-- даты последних назначений на должность
SELECT	EMPL_LINK, MAX(DATE_PD) AS DATE
INTO	#EMPL_DATE_POST
FROM	DICTIONARY_PURP_DISP_FACES
WHERE	DATE_PD <= @dDate2
	AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS where razd in (1,2))
GROUP	BY EMPL_LINK


-- последние образования (соответствующие квалификационным требованиям)
CREATE	TABLE #PERS_EDUC(PERS_LINK INT,EDUC_FORM VARCHAR(100),SCHOOL VARCHAR(250),DIP_DATE DATETIME,DIP_NUM VARCHAR(50),SPEC VARCHAR(200))
--
SELECT	PERS_LINK = ISNULL(E.PERS_LINK,0) INTO #PERS
FROM	@varKSEMPLS A LEFT JOIN EMPL E ON A.LINK_EMPL = E.LINK and razd in (1,2)


DECLARE @PERS_LINK INT
WHILE EXISTS(SELECT * FROM #PERS) BEGIN
	SELECT TOP 1 @PERS_LINK = PERS_LINK FROM #PERS
	--
	IF EXISTS(SELECT * FROM PERS_EDUCATION WHERE PERS_LINK = @PERS_LINK AND DATE_END <= @dDate2 AND SATISFY = 1) BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
			AND SATISFY = 1
		ORDER	BY DATE_END DESC
	END ELSE BEGIN
		INSERT	#PERS_EDUC
		SELECT	TOP 1 PERS_LINK, RTRIM(EDUC_NAME), LTRIM(RTRIM(SCHOOL_NAME)), DOC_DATE, LTRIM(RTRIM(DOC_NUM)), LTRIM(RTRIM(ISNULL(SPEC_NAME,'')))
		FROM	KU_PERS_EDUCATION
		WHERE	PERS_LINK = @PERS_LINK
			AND DATE_END <= @dDate2
		ORDER	BY DATE_END DESC
	END
	--
	DELETE FROM #PERS WHERE PERS_LINK = @PERS_LINK
END
DROP TABLE #PERS

-- последние классные чины
SELECT	EMPL_LINK = ISNULL(KEC.EMPL_LINK,0), KEC.CHIN_NAME, KEC.DATE, KEC.REASON
INTO	#EMPL_CHIN
FROM	KU_EMPL_CHIN KEC RIGHT JOIN (
	SELECT	EMPL_LINK = ISNULL(EMPL_LINK,0), MAX(DATE) AS DATE
	FROM	EMPL_CHIN
	WHERE	DATE <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS  where razd in (1,2))
	GROUP	BY EMPL_LINK
	) T ON KEC.EMPL_LINK = T.EMPL_LINK AND KEC.DATE = T.DATE

-- последние аттестации
SELECT	KEA.EMPL_LINK, KEA.DATE, KEA.ATT_NAME
INTO	#EMPL_ATTEST
FROM	KU_EMPL_ATTEST KEA RIGHT JOIN (
	SELECT	EMPL_LINK = ISNULL(EMPL_LINK,0), MAX(DATE) AS DATE
	FROM	EMPL_ATTEST
	WHERE	DATE <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS  where razd in (1,2))
	GROUP	BY EMPL_LINK
	) T ON KEA.EMPL_LINK = T.EMPL_LINK AND KEA.DATE = T.DATE

-- последние профессиональные переподготовки
SELECT	KEP.EMPL_LINK, KEP.DATE_BEGIN, KEP.DATE_END, KEP.DOC_TYPE, KEP.DOC_NUM, KEP.DOC_DATE, KEP.PROG_NAME, KEP.PLACE, KEP.[TIME]
INTO	#EMPL_PROFP
FROM	KU_EMPL_PROFP KEP RIGHT JOIN (
	SELECT	EMPL_LINK = ISNULL(EMPL_LINK,0), MAX(DATE_END) AS DATE_END
	FROM	EMPL_PROFP
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK  IN (SELECT LINK_EMPL FROM @varKSEMPLS  where razd in (1,2))
	GROUP	BY EMPL_LINK
	) T ON KEP.EMPL_LINK = T.EMPL_LINK AND KEP.DATE_END = T.DATE_END

-- последние повышения квалификаций
SELECT	KEI.EMPL_LINK, KEI.DATE_BEGIN, KEI.DATE_END, KEI.DOC_TYPE, KEI.DOC_NUM, KEI.DOC_DATE, KEI.PROG_NAME, KEI.PLACE, KEI.[TIME]
INTO	#EMPL_INCQUAL
FROM	KU_EMPL_INCQUAL KEI RIGHT JOIN (
	SELECT	EMPL_LINK = ISNULL(EMPL_LINK,0), MAX(DATE_END) AS DATE_END
	FROM	EMPL_INCQUAL
	WHERE	DATE_END <= @dDate2
		AND EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS  where razd in (1,2))
	GROUP	BY EMPL_LINK
	) T ON KEI.EMPL_LINK = T.EMPL_LINK AND KEI.DATE_END = T.DATE_END
-- последние награждения
SELECT	KPA.PERS_LINK, KPA.AWARD_NAME, KPA.DOC_DATE
INTO	#PERS_AWARD
FROM	KU_PERS_AWARD KPA RIGHT JOIN (
	SELECT	PERS_LINK, MAX(DOC_DATE) AS DOC_DATE
	FROM	PERS_AWARD
	WHERE	DOC_DATE <= @dDate2
	GROUP	BY PERS_LINK
	) T ON KPA.PERS_LINK = T.PERS_LINK AND KPA.DOC_DATE = T.DOC_DATE


--- кто замещал во время отсутствия 
SELECT	EMPL_LINK = ISNULL(EMPL_LINK,0), fio, subst_empl_link , S_FIO, DATE_BEGIN, DATE_END, NUMBER, [DATE]
INTO	#SUBST
FROM	SUBST  
WHERE	DATE_END >= @dDate2
		AND SUBST_EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS  where razd in (1,2))
--------------------------------------------------------------------------------------------------
--- РАЗДЕЛ 3 Сведения о замещении должностей государственной гражданской службы 
--------------------------------------------------------------------------------------------------
-- ПРИНЯТЫЕ
SELECT	T.*
INTO	#REPORT_TABLE_3
FROM	(
	SELECT	
		[TYPE]		=	1,
		DATE		=	IM.DATE_BEGIN,
		SUB_LINK	=	S.SUBDIV_LINK,
		SUB_NAME	=	S.SUBDIV_NAME,
		POST_NAME	=	S.POST_NAME,
		FIO			=	LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),
		OSNOV		=	'приказ № ' + RTRIM(LTRIM(O.NUMBER)) +					-- ОСНОВАНИЕ
			   ' от ' + rtrim(ltrim(CONVERT(VARCHAR(10),O.DATE,104))),
		PRICHINA	=	isnull(IM.USL_PR,''),
		
		[SUBDIVC]= S.SUBDIV_CODE,
		[EMPL]	= IM.EMPL_LINK	,							-- КЛЮЧЕВОЕ ПОЛЕ
		[CAT_G_CODE] = isnull(s.kat_gos_CODE,0)  -- категория гос должности 1-Руководители, 2-Помощники(советники),3-Специалисты,4-Обеспечивающие специалисты
	FROM	dbo.ITEM_MOVE IM
		LEFT JOIN dbo.DICTIONARY_STAFF_ALL S ON S.LINK_UP = IM.STAFF_LINK AND IM.DATE_BEGIN BETWEEN S.DATE_BEGIN AND S.DATE_END
		LEFT JOIN dbo.EMPL E ON E.LINK = IM.EMPL_LINK
		LEFT JOIN dbo.PERSON P ON E.PERS_LINK = P.LINK
		LEFT JOIN dbo.ORDERS O ON IM.ORDER_LINK = O.LINK
	WHERE	IM.ACTIVE = 1
		--AND IM.NEW_FACE = 1--IN (0,1)
		AND (IM.[TYPE] IN (1,2) OR IM.NEW_FACE = 1)
		AND IM.DATE_BEGIN BETWEEN @dDATE1 AND @dDATE2
		AND E.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
		AND s.gossl in (1,2,3, 4)
	) T
ORDER BY T.SUBDIVC, T.DATE


-- ПРИНЯТЫЕ и ПЕРЕВЕДЕННЫЕ
SELECT [TYPE] = ISNULL([TYPE],''),	[DATE] = ISNULL([DATE],''),
	   SUB_LINK = ISNULL(SUB_LINK,''),SUB_NAME = ISNULL(SUB_NAME,''),
	   POST_NAME = ISNULL(POST_NAME,''),FIO = ISNULL(FIO,''),
	   OSNOV = ISNULL(OSNOV,''),PRICHINA = ISNULL(PRICHINA,''), CAT_G_CODE =  ISNULL(CAT_G_CODE,'')
INTO #REPORT_NEW_TABLE_3
FROM #REPORT_TABLE_3


---------------------------------
-- ЗАМЕЩАЮЩИЕ
SELECT		
		[TYPE]		=	2,
		DATE		=	SU.DATE_BEGIN,
		SUB_LINK	=	SU.S_SUBDIV_LINK,
		SUB_NAME	=	SU.S_SUBDIV,
		POST_NAME	=	SU.S_POST,
		FIO			=	SU.FIO,
		OSNOV		=	RTRIM(ISNULL(SU.REASON,'')) + 								-- ОСНОВАНИЕ замещения
		   ' приказ № ' + RTRIM(LTRIM(SU.NUMBER)) + ' от ' + CONVERT(VARCHAR(10),SU.[DATE],104),
		PRICHINA	=	ISNULL(SU.REASON,'') ,
		[EMPL]	= SU.EMPL_LINK,
		[CAT_G_CODE] = isnull(s.kat_gos_CODE,0)  -- категория гос должности 1-Руководители, 2-Помощники(советники),3-Специалисты,4-Обеспечивающие специалисты
INTO	#REPORT_SUBST_TABLE_3
FROM dbo.SUBST SU 
	inner join dbo.KU_EMPL_PLACING_FN(@dDate2) kep on kep.link = SU.subst_empl_link
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) S ON S.STAFF_LINK = kep.STAFF_LINK 
	LEFT JOIN dbo.EMPL E ON E.LINK = SU.EMPL_LINK
	LEFT JOIN dbo.PERSON P ON P.LINK = E.PERS_LINK 
	
WHERE	SU.DATE_BEGIN BETWEEN @dDATE1 AND @dDATE2
	AND SU.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND SU.ACTIVE = 1
	AND s.gossl in (1,2,3, 4)

 
INSERT INTO #REPORT_NEW_TABLE_3
SELECT [TYPE],DATE,SUB_LINK,SUB_NAME,POST_NAME,FIO,OSNOV,PRICHINA, CAT_G_CODE
FROM #REPORT_SUBST_TABLE_3

DECLARE @NAZ_CNT INT, @NAZ_CNT_1 INT, @NAZ_CNT_2 INT , @NAZ_CNT_3 INT, @NAZ_CNT_4 int
--Количество замещающих и назначенных без конкурса
SET @NAZ_CNT = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE_3)
SET @NAZ_CNT_1 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE_3 WHERE  [CAT_G_CODE] = 1)
SET @NAZ_CNT_2 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE_3 WHERE  [CAT_G_CODE] = 2)
SET @NAZ_CNT_3 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE_3 WHERE  [CAT_G_CODE] = 3)
SET @NAZ_CNT_4 = (SELECT COUNT (*) FROM #REPORT_NEW_TABLE_3 WHERE  [CAT_G_CODE] = 4)

--------------------------------------------------------------------------------------------------
--- РАЗДЕЛ 4 Список гражданских служащих, уволенных из государственного органа за отчетный период
--------------------------------------------------------------------------------------------------
-- УВОЛЕННЫЕ
SELECT		
		[TYPE]		=	2,
		DATE		=	DF.DIS_DATE,
		SUB_LINK	=	DF.SUBDIV_LINK,
		SUB_NAME	=	DF.SUBDIV,
		POST_NAME	=	DF.POST,
		FIO			=	DF.FIO,
		OSNOV		=	RTRIM(ISNULL(DF.REASON_NAME,'')) + 								-- ОСНОВАНИЕ замещения
		   ' приказ № ' + RTRIM(LTRIM(DF.NUMBER)) + ' от ' + CONVERT(VARCHAR(10),DF.[DATE],104),
		PRICHINA	=	ISNULL(DF.OSN,'') ,
		[EMPL]	= DF.EMPL_LINK
INTO	#REPORT_DIS_TABLE_4
FROM dbo.DIS_FACE DF 
	inner join dbo.KU_EMPL_PLACING_FN(@dDate2) kep on kep.link = DF.empl_link
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) S ON S.STAFF_LINK = kep.STAFF_LINK  AND  kep.DATE_SACK BETWEEN S.DATE_BEGIN AND S.DATE_END
WHERE	DF.DIS_DATE BETWEEN @dDate1 AND @dDate2
	AND DF.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND DF.ACTIVE = 1
	AND s.gossl in (1,2,3, 4)
--------------------------------------------------------------------------------------------------
--- РАЗДЕЛ 5 Информация о вакантных должностях гражданской службы(см выборку)
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--- РАЗДЕЛ 6 Результаты аттестации гражданских служащих
--------------------------------------------------------------------------------------------------
	SELECT AG.LINK, AG.DATE, AGT.DATE_TIME, AG.PERIOD, AGT.FIO, AGT.DOC_LINK, AGT.ATTEST_LINK, ISNULL(KEA.ATT_CODE,0) AS [ATT_CODE]
	INTO #ATT_6
	FROM	dbo.ATT_GRAPHIC	AG	
			INNER JOIN dbo.ATT_GRAPHIC_TABLE AGT ON AG.LINK = AGT.DOC_LINK
			LEFT JOIN dbo.KU_EMPL_ATTEST KEA ON KEA.LINK = AGT.ATTEST_LINK_NUM	
	WHERE PERIOD = @cYear1 AND ag.[DATE] <= @dDate2




--------------------------------------------------------------------------------------------------
--- РАЗДЕЛ 7 Аналитическая таблица
--------------------------------------------------------------------------------------------------
----- 1) /* ИНФОРМАЦИЯ ПО ШТАТНОЙ ЧИСЛЕННОСТИ */
---------------------------------------------------------------------
CREATE TABLE #STAFF_REC (STAFF_LINK INT, NUM_STAKE NUMERIC(18,2), [END] TINYINT)
CREATE INDEX #IX_REC_STAFF_REC ON #STAFF_REC (STAFF_LINK)

INSERT INTO #STAFF_REC (STAFF_LINK, NUM_STAKE, [END])
SELECT LINK, SUM(NUM_STAKE), 0 
FROM dbo.DICTIONARY_STAFF_FN(@ddate2) 
WHERE DEP_LINK = @DEP_LINK AND gossl in (1,2,3, 4) and ISNULL(DEL_SUBDIV,1) = 0	AND @ddate2 BETWEEN date_begin AND date_end
GROUP BY LINK
-------------------------------------------------------------------------------------------------------
----  2)/* ФАКТИЧЕСКАЯ ЧИСЛЕННОСТЬ */
-------------------------------------------------------------------------------------------------------
CREATE TABLE #EMPL_FAKT (EMPL_LINK INT, PERS_LINK INT , STAFF_LINK INT, NUM_STAKE NUMERIC(18,2), [END] TINYINT )

INSERT INTO #EMPL_FAKT (EMPL_LINK,PERS_LINK, STAFF_LINK, NUM_STAKE, [END])
SELECT kep.LINK, kep.PERS_LINK, kep.STAFF_HEAD, SUM(kep.NUM_STAKE), 1 
FROM dbo.KU_EMPL_PLACING_FN(@ddate2) kep
	LEFT JOIN dbo.DICTIONARY_STAFF_FN(@ddate2) S ON S.STAFF_LINK = kep.STAFF_LINK 
WHERE KEP.DEP_LINK = @DEP_LINK  and KEP.NOTWORK<>1 AND KEP.SACK = 0 
AND s.gossl in (1,2,3, 4)
GROUP BY KEP.LINK,kep.PERS_LINK, KEP.STAFF_HEAD

-- удаляются те гос служащие , которых не замещали во время их отсутствия
DELETE FROM @varKSEMPLS 
WHERE LINK_EMPL not IN (SELECT EMPL FROM #REPORT_SUBST_TABLE_3 )	and RAZD = 7	

-- из фактичеки работающих удаляются сотрудники которых замещали 
DELETE FROM #EMPL_FAKT 
WHERE EMPL_LINK IN (SELECT LINK_EMPL FROM @varKSEMPLS where RAZD = 7 )	
-------------------------------------------------------------------------------------------------------
-- ТАБЛИЦА ДОЛЖНОСТЕЙ ШТАТНОГО РАСПИСАНИЯ
-------------------------------------------------------------------------------------------------------
select	[STAFF_LINK] =	 D_ST.STAFF_LINK,				-- ССЫЛКА НА ДОЛЖНОСТЬ ШТАТНОГО РАСПИСАНИЯ
		[NUM_STAKE] = 	 CONVERT(INT,D_ST.num_stake),	-- КОЛИЧЕСТВО СТАВОК ПО ШТАТУ
		[KAT_GOS_CODE] = D_ST.kat_gos_CODE,				-- КАТЕГОРИЯ ДОЛЖНОСТИ
		[GR_GOS_CODE] =  D_ST.gr_gos_CODE,				-- ГРУППА ДОЛЖНОСТИ
		[GOSSL] = 	 D_ST.GOSSL							-- ТИП ДОЛЖНОСТИ
into	#STAFF_INFO
from	dbo.DICTIONARY_STAFF_FN(@dDate2) D_ST
where	D_ST.DEP_LINK = (select dep_link from user_dep)	-- ДОЛЖНОСТИ ТОЛЬКО ТЕКУЩЕЙ ОРГАНИЗАЦИИ
	and D_ST.deleted = 0								-- ТОЛЬКО ДЕЙСТВУЮЩИЕ НА ДАННУЮ ДАТУ
	and D_ST.GOSSL in (1,2,3,4)								-- ТОЛЬКО ГОСУДАРСТВЕННОЙ И ГОСУДАРСТВЕННОЙ ГРАЖДАНСКОЙ СЛУЖБЫ
	and ISNULL(D_ST.DEL_SUBDIV,1) = 0					-- ТОЛЬКО ДОЛЖНОСТИ ДЕЙСТВУЮЩИХ ПОДРАЗДЕЛЕНИЙ

-------------------------------------------------------------------------------------------------------
-- ТАБЛИЦА ОБРАЗОВАНИЙ СОТРУДНИКОВ
-------------------------------------------------------------------------------------------------------
SELECT	TT.LINK AS LINK_PERS,
	TT.TYPE,
	TT.ACAD,
	TT.ACAD_ST,
	TT.POSL,
	TT.TWOO,
	TT.SATISFY,
	TT.STUD,
	CASE
	  WHEN	LEN(TT.SPEC) = 0 THEN 0
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
 		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%юриспруденция%'
 		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%международные отношения%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '04'
		)
		THEN 4									-- ГУМАНИТАРНЫЕ И СОЦИАЛЬНЫЕ НАУКИ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%юриспруденция%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '05'
		)
		THEN 5									-- ЮРИСПРУДЕНЦИЯ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('02','52')
		AND TT.SPEC NOT IN ('5216','5221','5220')
		OR TT.SPEC = '6130')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%международные отношения%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '06'
		)
		THEN 6									-- МЕЖДУНАРОДНЫЕ ОТНОШЕНИЯ
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		OR TT.SPEC IN ('0303','5216','5221'))
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%государственное и муниципальное управление%'
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%упрвление персоналом%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '07'
		)
		THEN 7									-- ЭКОНОМИНИКА И УПРАВЛЕНИЕ
	  WHEN	
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%Экономика%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '08'
		)
		THEN 8									-- ЭКОНОМИНИКА
	  WHEN	(
		(SUBSTRING(TT.SPEC,1,2) IN ('06')
		OR TT.SPEC IN ('0303','5216','5221'))
		AND (SELECT top 1 RTRIM(LTRIM(NAME)) FROM SPECIALITY WHERE CODE = TT.SPEC) LIKE '%государственное и муниципальное управление%'
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '09'
		)
		THEN 9									-- ГОСУДАРСТВЕННОЕ И МУНИЦИПАЛЬНОЕ УПРАВЛЕНИЕ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('01','51')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '10'
		)
		THEN 10									-- ФИЗИКОМАТЕМАТИЧЕСКИЕ И ЕСТЕСТВЕННЫЕ НАУКИ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('03','54')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '11'
		)
		THEN 11									-- ОБРАЗОВАНИЕ И ПЕДАГОГИКА
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('04')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '12'
		)
		THEN 12									-- ЗДРАВООХРАНЕНИЕ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('05')
		AND TT.SPEC IN ('5218','5406')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '13'
		)
		THEN 13									-- КУЛЬТУРА И ИСКУССТВО
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('22')
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '14'
		)
		THEN 14									-- ИНФОРМАЦИОННАЯ БЕЗОПАСНОСТЬ
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('31','56')
		AND TT.SPEC IN ('1710','2710')		
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '15'
		)
		THEN 15								-- СЕЛЬСКОЕ И РЫБНОЕ ХОЗЯЙСТВО
		
	  WHEN	(
		SUBSTRING(TT.SPEC,1,2) IN ('55','22','21','20','18')
		AND TT.SPEC IN ('6135','6123')		
		)
		OR
		(
		SUBSTRING(RIGHT(TT.SPEC,3),1,1) = 'Я' AND RIGHT(TT.SPEC,2) = '16'
		)
		THEN 16								-- ТЕХНИЧЕСКОЕ(ИНЖЕНЕРНОЕ)	
	  ELSE	17
	END AS SPEC
INTO #EDUC_EMPL
FROM
(
SELECT	[LINK] = T.LINK,								-- ФИЗИЧЕСКОЕ ЛИЦО
	[TYPE] = T.TYPE,								-- ТИП ОБРАЗОВАНИЯ (СМ. НИЖЕ)
	[ACAD] = CASE									-- УЧЕНАЯ СТЕПЕНЬ ПРИ НАЛИЧИИ ВЫСШЕГО (СМ. НИЖЕ)
		   WHEN T.TYPE = 1 THEN T.ACAD_DEGREE
		   ELSE 0
		 END,
	[POSL] = CASE									-- ПОСЛЕВУЗОВСКОЕ ПРИ НАЛИЧИИ ВЫСШЕГО ( 1 - ЕСТЬ, 0 - НЕТ)
		   WHEN T.TYPE = 1 AND EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION		
					      WHERE PERS_LINK = T.LINK AND EDUC_CODE = 19) THEN 1
		   ELSE 0
		 END,
	[TWOO] = CASE									-- 2 И БОЛЕЕ ВЫСШИХ ( 1 - ЕСТЬ, 0 - НЕТ)
		   WHEN	T.TYPE = 1 AND (SELECT COUNT(*) FROM dbo.KU_PERS_EDUCATION
					WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18) > 1 THEN 1
		   ELSE 0
		 END,
	[SPEC] = CASE									-- СПЕЦИАЛЬНОСТЬ
		   WHEN T.TYPE = 1 THEN
		      CASE WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
   			               WHERE PERS_LINK = T.LINK AND SATISFY = 1)
				THEN (SELECT TOP 1 ISNULL(SPEC_CODE,'!!!') FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND SATISFY = 1)
			   ELSE (SELECT TOP 1  ISNULL(SPEC_CODE,'!!!') FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18)
		      END
		   ELSE ''
		 END,
	[SATISFY] = (select top 1 SATISFY from dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK),   --  СООТВЕТСТВУЕТ ПРОФИЛЮ ДЕЯТЕЛЬНОСТИ
	[STUD] = CASE  
			WHEN T.TYPE = 0 and EXISTS (SELECT * FROM dbo.KU_PERS_EDUCATION WHERE PERS_LINK = T.LINK AND EDUC_CODE = 18 and ISNULL(DATE_BEGIN,0) <>0 and ISNULL(DATE_END,0)=0 AND ISNULL(DOC_DATE,0)=0)
					THEN 0
					ELSE 1 END,
	[ACAD_ST] = CASE									-- УЧЕНОЕ ЗВАНИЕ ПРИ НАЛИЧИИ ВЫСШЕГО (СМ. НИЖЕ)
		   WHEN T.TYPE = 1 THEN T.ACAD_DEGREE
		   ELSE 0
		 END			
			   			                      
FROM	(
	select	[LINK] = P.LINK,							-- ФИЗИЧЕСКОЕ ЛИЦО
		[TYPE] =								-- ОБРАЗОВАНИЕ (0 - БЕЗ ПРОФЕССИОНАЛЬНОГО,
			CASE								--		1 - ВЫСШЕЕ ПРОФЕССИОНЛЬНОЕ,
			  WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION			--		2 - СРЕДНЕЕ ПРОФЕССИОНАЛЬНОЕ)
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 18) THEN 1
			  WHEN EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 11) AND
			       NOT EXISTS(SELECT * FROM dbo.KU_PERS_EDUCATION
				      WHERE PERS_LINK = P.LINK AND EDUC_CODE = 18) THEN 2
			  ELSE 0
			END,
		[ACAD_DEGREE] = 							-- УЧЕНАЯ СТЕПЕНЬ (1 - ДОКТОР НАУК,
			CASE								--		   2 - КАНДИДАТ НАУК)
			  WHEN (SELECT CODE FROM dbo.ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK) = 1 THEN 1
			  WHEN (SELECT CODE FROM dbo.ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK) = 2 THEN 2
			  ELSE 0
			END,
		[ACAD_STATUS] = 							-- УЧЕНОЕ ЗВАНИЕ 
			CASE
			  WHEN (SELECT ISNULL(CODE,'') FROM dbo.ACAD_STATUS WHERE LINK = P.ACAD_STATUS_LINK) <> ''  THEN 1
			  ELSE 0
			END	
	from	PERSON P
			INNER JOIN #EMPL_FAKT e on p.link = e.PERS_LINK
	) T
) TT

-------------------------------------------------------------------------------------------  
-----  сведения о вакантных должностях 
-------------------------------------------------------------------------------------------
	declare @VAC_CNT int  
	SET @VAC_CNT	=	(SELECT SUM(DS.FREE_STAKES)
							FROM DBO.DICTIONARY_STAFF_FN(@dDate2)  DS
							WHERE @dDate2 BETWEEN DS.DATE_BEGIN AND DS.DATE_END
							AND DS.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
							AND DS.DEL_SUBDIV = 0 AND DS.FREE_STAKES >0 
							AND ds.gossl in (1,2,3, 4))
-------------------------------------
---------------------------------------------------------------------------------------

CREATE TABLE #EMPLS_INFO(LINK INT, PERS_LINK INT, GOSSL INT, KAT_GOS_CODE VARCHAR(10),
GR_GOS_CODE VARCHAR(10), CHIN INT, EXPIR INT, [TYPE] INT, ACAD INT,ACAD_ST INT, POSL INT, TWOO INT, SPEC INT,SATISFY int, STUD INT,
SEX INT, AGE INT, NOTWORK INT, NEW_FACE INT, TYPE_MOVE INT, TEMP_LINK INT, DATE_END2 DATETIME)


INSERT	#EMPLS_INFO (LINK, PERS_LINK, GOSSL, KAT_GOS_CODE, GR_GOS_CODE, SEX, AGE, CHIN, EXPIR,
					[TYPE], ACAD,ACAD_ST, POSL, TWOO, SPEC,SATISFY, STUD, NOTWORK, NEW_FACE, TYPE_MOVE, TEMP_LINK, DATE_END2)
SELECT
-- ССЫЛКА НА СОТРУДНИКА
	[LINK] = 			EM_PL.LINK,	
-- ССЫЛКА НА СОТРУДНИКА							
	[PERS_LINK] = 		EM_PL.PERS_LINK,	
-- ТИП ДОЛЖНОСТИ (1- гос.гражд, 2- гос)					
	[GOSSL] = 			ST.GOSSL,		
-- КАТЕГОРИЯ ДОЛЖНОСТИ (1- рук, 2- помощ, 3- спец, 4- об.спец)							
	[KAT_GOS_CODE] =	ST.kat_gos_CODE,
-- ГРУППА ДОЛЖНОСТИ (1- высш, 2- глав, 3- вед, 4-с тар, 5- млад)						
	[GR_GOS_CODE] =		ST.gr_gos_CODE,
-- ПОЛ (1- муж, 2- жен)						
	[SEX] = 			P.SEX,			
-- ВОЗРАСТ							
	[AGE] =				dbo.ku_GetPersAge(P.LINK,@dDate2),		
-- НАЛЧИЧИЕ КЛАССНОГО ЧИНА
	[CHIN] =	CASE										
					WHEN EXISTS(SELECT * FROM dbo.EMPL_CHIN WHERE EMPL_LINK = EM_PL.link and date < @dDate2)
						THEN 1
					ELSE 0
				END,
-- СТАЖ ГОСУДАРСТВЕННОЙ ГРАЖДАНСКОЙ СЛУЖБЫ (В ГОДАХ),
	[EXPIR] = 	 dbo.ku_GetEmplExpir(EM_PL.LINK,'YEAR','GOS_NADB',@dDate2),
-- СВЕДЕНИЯ ПО ОБРАЗОВАНИЮ	
	EDUC.TYPE, EDUC.ACAD, EDUC.ACAD_ST, EDUC.POSL, EDUC.TWOO, EDUC.SPEC,EDUC.[SATISFY], EDUC.[STUD],
	-- ДАННЫЕ ДЛЯ УСЛОВИЙ ВЫБОРКИ СОТРУДНИКОВ
	[NOTWORK] =		EM_PL.NOTWORK,
	[NEW_FACE] =	IM.NEW_FACE,
	[TYPE_MOVE] = 	IM.TYPE,
	[TEMP_LINK] =	IM.TEMP_LINK,
	[DATE_END2] = 	IM.DATE_END2
FROM	#EMPL_FAKT ef
		inner join dbo.KU_EMPL_PLACING_FN(@dDate2) EM_PL ON ef.EMPL_LINK = EM_PL.LINK
		LEFT JOIN dbo.DICTIONARY_STAFF_FN(@dDate2) ST
			ON EM_PL.STAFF_LINK = ST.STAFF_LINK
		LEFT JOIN dbo.PERSON P
			ON EM_PL.PERS_LINK = P.LINK
		LEFT JOIN #EDUC_EMPL EDUC
			ON EM_PL.PERS_LINK = EDUC.LINK_PERS
		LEFT JOIN dbo.ITEM_MOVE IM
			ON EM_PL.ITEM_MOVE_LINK = IM.LINK
WHERE	EM_PL.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)		-- СОТРУДНИКИ ТОЛЬКО ТЕКУЩЕЙ ОРГАНИЗАЦИИ
			AND EM_PL.sack = 0										-- ТОЛЬКО РАБОТАЮЩИЕ (ИСКЛЮЧАЕМ УВОЛЕННЫХ)
			AND isnull(EM_PL.DATE_BEGIN,0) != 0						-- ГАРАНТИРОВАННО ПРИНЯТЫХ (ИСКЛЮЧАЕМ ТЕХ, КТО ВИСИТ В ПРОЕКТАХ ПРИКАЗАХ)
			AND ST.GOSSL in (1,2,3,4)



------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------- ВЫБОРКа ДАННЫХ -----------------------------------------------------------------

-- 1 и 2 РАЗДЕЛЫ 
-------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT
	[COL_2]	 = KEP.FIO,									-- фамилия
	[COL_3]	 = ISNULL(KEP.POST_NAME,''),							-- наименование должности
	[COL_4]	 = CASE	WHEN D_ST.KAT_GOS_CODE = 1 THEN 'Рукводители'				-- категория должности
			WHEN D_ST.KAT_GOS_CODE = 2 THEN 'Помощники (советники)'
			WHEN D_ST.KAT_GOS_CODE = 3 THEN 'Специалисты'
			WHEN D_ST.KAT_GOS_CODE = 4 THEN 'Обеспечивающие специалисты'
			ELSE ''
		   END,										
	[COL_5]	 = CASE	WHEN D_ST.GR_GOS_CODE = 1 THEN 'Высшая'					-- группа должности
			WHEN D_ST.GR_GOS_CODE = 2 THEN 'Главная'	
			WHEN D_ST.GR_GOS_CODE = 3 THEN 'Ведущая'	
			WHEN D_ST.GR_GOS_CODE = 4 THEN 'Старшая'	
			WHEN D_ST.GR_GOS_CODE = 5 THEN 'Младшая'	
			ELSE ''
		   END,
	[COL_6]	 = CONVERT(VARCHAR(10),P.BIRTHDATE,104),				-- дата рождения
	[COL_7]	 = CONVERT(VARCHAR(10),KEP.DATE_BEGIN,104),				-- дата поступления на службу в государсвтенный орган
	[COL_8]	 = CONVERT(VARCHAR(10),EDP.DATE,104),					-- дата назначения на должность
	[COL_9]	 = '',							-- Срок действия служебного контракта 
	[COL_10] = SUBSTRING((dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1)), 1,  charindex('м.' , dbo.kj_GetExpirDateDiffStr(EDP.DATE,@dDate2,1))+2),				-- Стаж государственной гражданской службы (лет, мес.)
	[COL_11] = SUBSTRING((dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)), 1,  charindex('м.' , (dbo.ku_EmplExpir_YYMMDD(KEP.LINK,@dDate2,'GOS_PENS',1)))+2),	-- Стаж государственной гражданской службы для назначения пенсии за выслугу лет 
	[COL_12] = CASE WHEN ISNULL(PE.SCHOOL,'') = '' THEN  ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'')
				ELSE ltrim(rtrim(ISNULL(PE.SCHOOL,''))) + ', ' + ISNULL(CONVERT(VARCHAR(10),PE.DIP_DATE,104),'') END ,	-- учебное заведение (образование) и дата диплома (образование)
	[COL_13] = ISNULL(PE.SPEC,''),								-- специальность (образование)
	[COL_14] = CASE	WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	-- ученая степень, ученое звание , дата присвоения ученой степени, ученого звания
			ELSE (SELECT NAME FROM ACAD_DEGREE WHERE LINK = P.ACAD_DEGREE_LINK)
		   END + 
		   CASE	WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 THEN ''
			ELSE CASE WHEN ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''	
				  ELSE ', '
			     END + (SELECT NAME FROM ACAD_STATUS WHERE LINK = P.ACAD_STATUS_LINK)
		   END
		   + CASE WHEN isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE,104),'') = '' THEN ''
			  ELSE 
				CASE WHEN ISNULL(P.ACAD_STATUS_LINK,0) = 0 AND ISNULL(P.ACAD_DEGREE_LINK,0) = 0 THEN ''
				  ELSE ', '
				 END + isnull(CONVERT(VARCHAR(10),P.ACAD_DEGREE_DATE, 104),'') 
			 END ,
	[COL_15] = ltrim(RTRIM(ISNULL(EC.CHIN_NAME,'')))  
			 + CASE WHEN ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'') = '' THEN ''
				  else
				    case when ISNULL(EC.CHIN_NAME,'') = '' THEN ''
					  ELSE ', ' 
					 END + ISNULL(CONVERT(VARCHAR(10),EC.DATE,104),'')
				END  ,				-- наименование классного чина ,  дата присвоения чина
	[COL_16] = ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'')
				 +  CASE WHEN ISNULL(EA.ATT_NAME,'') = '' THEN ''
					else	
						CASE WHEN ISNULL(CONVERT(VARCHAR(10),EA.DATE,104),'') = '' THEN ''
							ELSE ', ' 
					   END + 	ISNULL(EA.ATT_NAME,'')
				   	END 	,				-- дата проведения аттестации, решение аттестационной комиссии

	[COL_17] =  CASE WHEN ISNULL(EP.PLACE,'')= '' 
					 AND  ISNULL(EP.PROG_NAME,'') = '' 
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = ''
					 AND  ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') = ''
					 AND  ISNULL(EP.[TIME],'') = ''
						THEN ''
				 	 ELSE 
						'Проф.переподготовка: ' + (CASE WHEN  ISNULL(EP.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EP.PLACE,''))) + '; ' END )  
										+   (CASE WHEN ISNULL(EP.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EP.PROG_NAME,''))) + '"; ' end )
										+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') =  '' THEN  ''
												ELSE 
													' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EP.DATE_END,104),'') + '; '
												END )	
										+ (CASE WHEN ISNULL(EP.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EP.[TIME]),'') + '; ' END )
					 END 
					, -- проф.переподготовка, наименование учреждения , наименование программы обучения, дата обучения, время обучения.
	
	[COL_18] =  CASE WHEN ISNULL(EI.PLACE,'')= '' 
				 AND  ISNULL(EI.PROG_NAME,'') = '' 
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = ''
				 AND  ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') = ''
				 AND  ISNULL(EI.[TIME],'') = ''
					THEN ''
			 	 ELSE 
					'Последнее повышение квалификации: ' + (CASE WHEN  ISNULL(EI.PLACE,'') = '' THEN '' ELSE ltrim(rtrim(ISNULL(EI.PLACE,''))) + '; ' END )  
									+   (CASE WHEN ISNULL(EI.PROG_NAME,'') = '' THEN '' ELSE ' Наименование программы "'  + ltrim(rtrim(ISNULL(EI.PROG_NAME,''))) + '"; ' end )
									+ (CASE WHEN ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') = '' AND ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') =  '' THEN  ''
											ELSE 
												' Обучение с ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_BEGIN,104),'') + ' по ' + ISNULL(CONVERT(VARCHAR(10),EI.DATE_END,104),'') + '; '
											END )	
									+ (CASE WHEN ISNULL(EI.[TIME],0) = 0 THEN '' ELSE ' Количество часов '  + ISNULL(convert(varchar(5),EI.[TIME]),'') + '; ' END )
				 END 
				, -- последнее повышение квалификации: наименование учреждения , наименование программы обучения, дата обучения, время обучения.
	[COL_19] = LTRIM(rtrim(ISNULL(s.fio,''))), -- фамилия имя отчество лица, замещающего данного гражданского служащего				
-------------------------------------------------------------------------------------------------------------------------------------------------------
	[SUBDIV]	= ISNULL(KEP.SUBDIV_NAME,''),
	[SUBDIV_C]	= ISNULL(KEP.SUBDIV_CODE,''),
	[RAZD] = SE.RAZD
INTO #REP_NEW_TABLE_1 	
FROM	KU_EMPL_PLACING_FN(@dDate2) KEP
	inner join @varKSEMPLS se on KEP.link = se.LINK_EMPL  and se.razd in (1,2)
	LEFT JOIN PERSON P ON P.LINK = KEP.PERS_LINK
	LEFT JOIN DICTIONARY_STAFF_FN(@dDate2) D_ST ON  KEP.STAFF_LINK = D_ST.STAFF_LINK
	LEFT JOIN #EMPL_DATE_POST EDP ON EDP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_CHIN EC ON EC.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_ATTEST EA ON EA.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_PROFP EP ON EP.EMPL_LINK = KEP.LINK
	LEFT JOIN #EMPL_INCQUAL EI ON EI.EMPL_LINK = KEP.LINK
	LEFT JOIN #PERS_EDUC PE ON PE.PERS_LINK = KEP.PERS_LINK
	LEFT JOIN #PERS_AWARD PA ON PA.PERS_LINK = KEP.PERS_LINK
	LEFT JOIN #SUBST s ON s.subst_empl_link = KEP.LINK
WHERE D_ST.GOSSL IN (1,2,3, 4)
ORDER	BY KEP.SUBDIV_CODE


IF (select count(*) from  #REP_NEW_TABLE_1 where [RAZD] = 1  ) <>0  
	SELECT * FROM #REP_NEW_TABLE_1 where [RAZD] = 1
else 
	select [COL_2]= 0, [COL_3]= ' ',[COL_4]= ' ',[COL_5]= ' ',[COL_6]= ' ',[COL_7]= ' ',[COL_8]= ' ',[COL_9]= ' ', [COL_10]= ' ', [COL_11]= ' ', [COL_12]= ' ',
			[COL_13]= ' ',[COL_14]= ' ',[COL_15]= ' ',[COL_16]= ' ',[COL_17]= ' ',[COL_18]= ' ', [COL_19]= ' ', [SUBDIV]= ' ', [SUBDIV_C]= ' ',[RAZD] = 1
		
IF (select count(*) from  #REP_NEW_TABLE_1 where [RAZD] = 2  ) <>0  
	SELECT * FROM #REP_NEW_TABLE_1 where [RAZD] = 2
else 
	select [COL_2]= 0, [COL_3]= ' ',[COL_4]= ' ',[COL_5]= ' ',[COL_6]= ' ',[COL_7]= ' ',[COL_8]= ' ',[COL_9]= ' ', [COL_10]= ' ', [COL_11]= ' ', [COL_12]= ' ',
			[COL_13]= ' ',[COL_14]= ' ',[COL_15]= ' ',[COL_16]= ' ',[COL_17]= ' ',[COL_18]= ' ', [COL_19]= ' ', [SUBDIV]= ' ', [SUBDIV_C]= ' ',[RAZD] = 2




-------------------------------------------
--- 3 РАЗДЕЛ
-------------------------------------------
IF (select count(*) from #REPORT_NEW_TABLE_3 ) <>0 
	SELECT [TYPE] = ISNULL([TYPE],0),	[DATE] = ISNULL([DATE],' '),
	   SUB_LINK = ISNULL(SUB_LINK,' '),SUB_NAME = ISNULL(SUB_NAME,' '),
	   POST_NAME = ISNULL(POST_NAME,' '),FIO = ISNULL(FIO,' '),
	   OSNOV = ISNULL(OSNOV,' '),PRICHINA = ISNULL(PRICHINA,' '), CAT_G_CODE =  ISNULL(CAT_G_CODE,' '),
		NAZ_CNT = @NAZ_CNT,
		NAZ_CNT1 = @NAZ_CNT_1,
		NAZ_CNT2 = @NAZ_CNT_2,
		NAZ_CNT3 = @NAZ_CNT_3,
		NAZ_CNT4 = @NAZ_CNT_4 
	--	UVOL_COUNT	=	@UVOL_COUNT
	FROM #REPORT_NEW_TABLE_3
	ORDER BY SUB_NAME,FIO
else   SELECT  [TYPE]= 0,	[DATE] = ' ',
	   SUB_LINK= ' ',SUB_NAME= ' ',
	   POST_NAME=  ' ',FIO=' ',
	   OSNOV =' ',PRICHINA=' ', CAT_G_CODE =' ',
	   NAZ_CNT =0,
		NAZ_CNT1 = 0,
		NAZ_CNT2 = 0,
		NAZ_CNT3 = 0,
		NAZ_CNT4 = 0 

-------------------------------------------
--- 4 РАЗДЕЛ
-------------------------------------------
SELECT [TYPE],	DATE,SUB_LINK,SUB_NAME,POST_NAME,FIO,OSNOV,PRICHINA
INTO #REPORT_NEW_TABLE_4
FROM #REPORT_DIS_TABLE_4

IF (select count(*) from  #REPORT_NEW_TABLE_4 ) <>0  
	SELECT * FROM #REPORT_NEW_TABLE_4
else 
	select [TYPE] = 0, [DATE] = ' ',SUB_LINK= ' ',SUB_NAME= ' ',POST_NAME= ' ',FIO= ' ',OSNOV= ' ',PRICHINA= ' '		
-------------------------------------------
--- 5 РАЗДЕЛ
-------------------------------------------

	SELECT 
		SUB_LINK	=	DS.SUBDIV_LINK,
		SUB_NAME	=	DS.SUBDIV_NAME,
		POST_NAME	=	DS.POST_NAME,
		POST_COUNT	=	DS.FREE_STAKES,
		DATE_BEGIN  =   SS.DATE_BEGIN,
		COMMENT		=	'',
		COMM_PLAN =  '',
		VAC_ALL		=	'',
		EMPL_POST	=	'',
		EMPL_NAME	=	''
	FROM DBO.DICTIONARY_STAFF_FN(@dDate1)  DS
	INNER JOIN (	SELECT	[STAFF_LINK] = sh.LINK,
			[FREE_STAKES] = s.num_stake - isnull(t.num_stake, 0),
			DATE_BEGIN = s.date_begin 
	FROM	dbo.staff_head sh 
			INNER JOIN dbo.staff s ON s.link_up = sh.link and s.date_begin = isnull((SELECT max(date_begin) FROM staff WHERE link_up=s.link_up and @dDATE1 >= date_begin),
																					(SELECT min(date_begin) FROM staff WHERE link_up=s.link_up and @dDATE1 <= date_begin))
			left join (select STAFF_HEAD, [num_stake] = sum(case when (STAFF_OPT1.OPT = 1 and sei.status = 2) or (STAFF_OPT3.OPT = 1 and sei.status = 3) then 0 else sei.num_stake end)
					   from SA_EMPLS_INFO_PERIOD(@dDATE1, @dDATE1, default, default) sei
							inner join (select OPT = dbo.sa_get_option_by_code('KADRY_OPT1')) STAFF_OPT1 on 1 = 1 
							inner join (select OPT = dbo.sa_get_option_by_code('KADRY_OPT3')) STAFF_OPT3 on 1 = 1
					   where notwork = 0
					   group by STAFF_HEAD
					  ) t on sh.link = t.STAFF_HEAD
	) ss on ss.STAFF_LINK = ds.link 
	WHERE @dDATE1 BETWEEN DS.DATE_BEGIN AND DS.DATE_END
	AND DS.DEP_LINK = (SELECT DEP_LINK FROM USER_DEP)
	AND DS.DEL_SUBDIV = 0 AND DS.FREE_STAKES >0 
	AND ds.gossl in (1,2,3, 4)
	ORDER BY SUB_LINK

-------------------------------------------
--- 6 РАЗДЕЛ
-------------------------------------------
	SELECT  
		PLAN_CHIS	= (SELECT count(*) FROM #ATT_6),	-- Количество гражданских служащих, подлежащих аттестации		
		ATT			= (SELECT count(*) FROM #ATT_6 WHERE ATTEST_LINK = 1 AND ATT_CODE <> '0'),	--Количество аттестованных гражданских служащих
		SOOTV		= (SELECT count(*) FROM #ATT_6 WHERE ATTEST_LINK = 1 AND ATT_CODE = '1'),	--соответствуют замещаемой должности
		RESERV		= (SELECT count(*) FROM #ATT_6 WHERE ATTEST_LINK = 1 AND ATT_CODE = '2'),	--соответствуют и рекомендуются к включению в кадровый резерв		
		PROF		= (SELECT count(*) FROM #ATT_6 WHERE ATTEST_LINK = 1 AND ATT_CODE = '4'),	--соответствуют при условии получения дополнительного профессионального образования			
		DOWN		= (SELECT count(*) FROM #ATT_6 WHERE ATTEST_LINK = 1 AND ATT_CODE = '3')	--не соответствуют замещаемой должности


-------------------------------------------
--- 7 РАЗДЕЛ
-------------------------------------------
	SELECT 
		SH_CNT		=	(select count(*) from #STAFF_REC),	-- штатная численность
		SUBST_CNT	=	(select count(*) from #REPORT_SUBST_TABLE_3),		-- Численность  временно замещающих должности на период отсутствия основного работника
		FACT_CNT	=	(select count(*) from #EMPL_FAKT),		-- фактическая численность
		---------- количество должностей по категориям   1- рук, 2- помощ, 3- спец, 4- об.спец
		RUK_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 1),		-- руководителей
		POM_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 2),		-- помощников
		SP_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 3),		-- специалистов
		OSP_CNT		=	(select count(*) from #EMPLS_INFO where KAT_GOS_CODE = 4),		-- обеспечивающих специалистов
		---------- количество должностей по группам   1- высш, 2- глав, 3- вед, 4-с тар, 5- млад
		GVIS_CNT 	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 1),		-- высших
		GGLAV_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 2),		-- главных
		GVED_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 3),		-- ведущих
		GSTAR_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 4),		-- старших
		GMLAD_CNT	=	(select count(*) from #EMPLS_INFO where GR_GOS_CODE = 5),		-- младших
		---------- Количество гражданских служащих по возрасту
		AGG_30		=	(select count(*) from #EMPLS_INFO where age < 30) ,	-- возраст до 30 лет
		AGG_30_39	=	(select count(*) from #EMPLS_INFO where age between 30 and 39 ),	-- возраст от 30 до 39 лет
		AGG_40_49	=	(select count(*) from #EMPLS_INFO where age between 40 and 49 ),	-- возраст от 40 до 49 лет
		AGG_50_59	=	(select count(*) from #EMPLS_INFO where age between 50 and 59 ),	-- возраст от 50 до 59 лет
		AGG_60_65	=	(select count(*) from #EMPLS_INFO where age between 60 and 65 or age >65),	-- возраст от 60 до 65 лет
		AGG_AVG		=	(select avg(age) from #EMPLS_INFO),	--средний возраст
		---------- Количество гражданских служащих пенсионного возраста (мужчины – 60 лет и старше, женщины – 55 лет и старше)
		AGE_P_All	= ((select count(*) from #EMPLS_INFO where age >=60 AND SEX = 0) + (select count(*) from #EMPLS_INFO where age >=55 AND SEX = 1)),--всего
		AGE_P_Z		= (select count(*) from #EMPLS_INFO where age >=55 AND SEX = 1),-- КОЛИЧЕСТВО ЖЕНЩИН
		AGE_P_M		= (select count(*) from #EMPLS_INFO where age >=60 AND SEX = 0),-- КОЛИЧЕСТВО МУЖЧИН
		---------- Количество гражданских служащих по образованию:
		OBR_VUZ		= (select count(*) from #EMPLS_INFO where [TYPE] = 1),	-- образование 1 высшее
		----------- в том числе по укрупненным группам специальностей и направлениям подготовки:
		SPEC_4  = (select count(*) from #EMPLS_INFO where SPEC = 4), -- ГУМАНИТАРНЫЕ И СОЦИАЛЬНЫЕ НАУКИ
		SPEC_5  = (select count(*) from #EMPLS_INFO where SPEC = 5), -- ЮРИСПРУДЕНЦИЯ
		SPEC_6  = (select count(*) from #EMPLS_INFO where SPEC = 6), -- МЕЖДУНАРОДНЫЕ ОТНОШЕНИЯ
		SPEC_7  = (select count(*) from #EMPLS_INFO where SPEC = 7), -- ЭКОНОМИНИКА И УПРАВЛЕНИЕ
		SPEC_8  = (select count(*) from #EMPLS_INFO where SPEC = 8), -- ЭКОНОМИНИКА
		SPEC_9  = (select count(*) from #EMPLS_INFO where SPEC = 9), -- ГОСУДАРСТВЕННОЕ И МУНИЦИПАЛЬНОЕ УПРАВЛЕНИЕ
		SPEC_10  = (select count(*) from #EMPLS_INFO where SPEC = 10), -- ФИЗИКОМАТЕМАТИЧЕСКИЕ И ЕСТЕСТВЕННЫЕ НАУКИ
		SPEC_11  = (select count(*) from #EMPLS_INFO where SPEC = 11), -- ОБРАЗОВАНИЕ И ПЕДАГОГИКА
		SPEC_12  = (select count(*) from #EMPLS_INFO where SPEC = 12), -- ЗДРАВООХРАНЕНИЕ
		SPEC_13  = (select count(*) from #EMPLS_INFO where SPEC = 13), -- КУЛЬТУРА И ИСКУССТВО
		SPEC_14  = (select count(*) from #EMPLS_INFO where SPEC = 14), -- ИНФОРМАЦИОННАЯ БЕЗОПАСНОСТЬ
		SPEC_15  = (select count(*) from #EMPLS_INFO where SPEC = 15), -- СЕЛЬСКОЕ И РЫБНОЕ ХОЗЯЙСТВО
		SPEC_16  = (select count(*) from #EMPLS_INFO where SPEC = 16), -- ТЕХНИЧЕСКОЕ(ИНЖЕНЕРНОЕ)	
		SPEC_17  = (select count(*) from #EMPLS_INFO where SPEC = 17), -- ДРУГИЕ
		SATISFY  = (select count(*) from #EMPLS_INFO where SATISFY = 1), -- соответствующее профилю деятельности
		OBR_2VUZ = (select count(*) from #EMPLS_INFO where TWOO = 1),	-- образование 2 и более высших
		OBR_SRED = (select count(*) from #EMPLS_INFO where [TYPE] = 2),	-- образование среднее проф.
		OBR_0VUZ = (select count(*) from #EMPLS_INFO where [TYPE] = 0),	-- не имеющие высшего и среднего профессионального образования
		STUD	 = (select count(*) from #EMPLS_INFO where [TYPE] = 0 and STUD = 1), -- не имеющих высшего образования, обучающихся в образовательных организациях
			
		U_ST_CNT = (select count(*) from #EMPLS_INFO where ACAD > 0 OR ACAD_ST > 0),	-- ученая степень, ученое звание
		----------  Количество гражданских служащих по стажу гражданской службы
		S_1			= (select count(*) from #EMPLS_INFO where expir < 1),					-- стаж гос.службы до 1 года
		S_1_5		= (select count(*) from #EMPLS_INFO where expir >=1 and expir < 5),	-- стаж гос.службы от 1 до 5 лет
		S_5_10		= (select count(*) from #EMPLS_INFO where expir >=5 and expir < 10),	-- стаж гос.службы от 5 до 10 лет
		S_10_15		= (select count(*) from #EMPLS_INFO where expir >=10 and expir < 15),	-- стаж гос.службы от 10 до 15 лет
		S_15_25		= (select count(*) from #EMPLS_INFO where expir >=15 and expir < 25),	-- стаж гос.службы от 15 до 25 лет
		S_25		= (select count(*) from #EMPLS_INFO where expir >=25),				-- стаж гос.службы от 25 лет
		W_CNT		= (select count(*) from #EMPLS_INFO where SEX = 1),-- КОЛИЧЕСТВО ЖЕНЩИН
		M_CNT		= (select count(*) from #EMPLS_INFO where SEX = 0),-- КОЛИЧЕСТВО МУЖЧИН	
		VAC_CNT     = @VAC_CNT ,---Количество вакантных должностей в органе		
		USR_PHONE   = LTRIM(RTRIM((select PHONES from RA_GET_USER_INFO(null)))) -- Телефон Составителя 

-------------------------------------------------------------------------------------------------------------------------------------------------------
--- УДАЛЕНИЕ ТАБЛИЦ РАЗДЕЛОВ
-------------------------------------------------------------------------------------------------------------------------------------------------------
--- РАЗДЕЛЫ 1 и 2
	DROP TABLE #EMPL_DATE_POST
	DROP TABLE #EMPL_CHIN
	DROP TABLE #EMPL_ATTEST
	DROP TABLE #EMPL_PROFP
	DROP TABLE #EMPL_INCQUAL
	DROP TABLE #PERS_EDUC
	DROP TABLE #PERS_AWARD
	drop table #SUBST
------------------------------------------------------------------------------------------------------------------
-- РАЗДЕЛ 3
------------------------------------------------------------------------------------------------------------------
	DROP TABLE #REPORT_NEW_TABLE_3
	DROP TABLE #REPORT_SUBST_TABLE_3
	DROP TABLE #REPORT_TABLE_3
------------------------------------------------------------------------------------------------------------------
-- РАЗДЕЛ 4
------------------------------------------------------------------------------------------------------------------
	DROP TABLE #REPORT_NEW_TABLE_4
	DROP TABLE #REPORT_DIS_TABLE_4

------------------------------------------------------------------------------------------------------------------
-- РАЗДЕЛ 6
------------------------------------------------------------------------------------------------------------------
	DROP TABLE #ATT_6
------------------------------------------------------------------------------------------------------------------
-- РАЗДЕЛ 7
------------------------------------------------------------------------------------------------------------------	
	DROP TABLE #EMPL_FAKT
	DROP TABLE #STAFF_INFO
	DROP TABLE #EDUC_EMPL 

GO


GRANT EXECUTE ON dbo.[REP_REESTR_GS] TO PUBLIC

GO

-- dbo.REP_REESTR_GS '2014', 2
--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_N_BOL_FILL2]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_N_BOL_FILL2]

GO


CREATE PROCEDURE [dbo].SA_N_BOL_FILL2 
(
 @LINK_DOC INT OUTPUT, --Ссылка на документ.	
 @LINK_ARCH INT, --Ссылка на больничный
 @LINK_PAYS INT = NULL, --Ссылка на вид начисления
 @TYP_PERIOD TINYINT = 3, --Тип расчетного периода: 1- по текущему месяцу, 2- по двум предыдущим, 3- по 12 предудущим месяцам
 @LIMIT TINYINT = 3,--Тип предела: 1- 2 тарифа, 2- 1 МРОТ, 3- по установленному значению, 4 - без ограничений
 @RECALC TINYINT = 0, -- 0 Полный расчет. расчет начинается с таблицы 3 
			-- 1 - не надо рассчитывать по видам начислений
			-- 2 - не надо рассчитывать по месяцам
			-- 3 - не надо рассчитывать средние суммы
 @OPER TINYINT = 0, -- 1 - сформировать операции
 @LINK_DEP INT = NULL
)
AS

SET NOCOUNT ON

DECLARE
 @LINK_EMPL INT, --Ссылка на сотрудника
 @DATE_BEGIN DATETIME, --Начало больничного
 @DATE_BEGIN_P DATETIME, --Начало больничного
 @DATE_END DATETIME, --Окончание больничного
 @REF_TYP_ARHE INT, --Ссылка на вид больничного
 @STAGE_Y INT, --Стаж
 @STAGE_M INT, --Стаж
 @comment varchar(100),
 @extension_DIS int,
 @dekret tinyint
 
DECLARE @UNAME VARCHAR(30)
SET @UNAME = CASE WHEN DBO.SA_GET_OPTION_BY_CODE('SALARY_OPTIONS_OPT10') = 1 THEN ISNULL(dbo.AdminGetUserFIO(default),'') ELSE '' END
SET @UNAME = @UNAME + CASE WHEN LEN(@UNAME) > 0 THEN ':' ELSE '' END

---инит
SELECT @LINK_EMPL = REF_EMPL, @LINK_PAYS = ISNULL(@LINK_PAYS,LINK_PAYS), @DATE_BEGIN = DATE1, @DATE_END = DATEADD(day,DAYS-1, DATE1),
	@REF_TYP_ARHE = REF_TYP_ARHE,  @STAGE_Y = NEPR_YEAR,  @STAGE_M = NEPR_MONTH,
	@comment = @UNAME + 'Начисление по Б/Л:' + ISNULL(dbo.sd_GetEmplName(@LINK_EMPL),'') + ',' + LEFT(RTRIM(LTRIM([NAME_TYP_ARHE])),30) + ' №'+RTRIM(LTRIM([NUMBER])) + ' от ' + CONVERT(VARCHAR(10),[DATE],104),
	@extension_DIS = REF_DOC, @dekret = ISNULL(D.DEKRET,0),
	@LINK_DEP = ISNULL(@LINK_DEP,LINK_DEP)
FROM dbo.DIS D 
WHERE D.LINK = @LINK_ARCH

---
DECLARE 
 @SystPay INT,
 @RP INT, --Размер расчетного периода 
 @DATE_BEGIN_RP DATETIME, --Начало расчетного периода
 @DATE_END_RP DATETIME, --Конец расчетного периода
 @DATE_BEGIN_WRK DATETIME, --Дата приема сотрудника
 @DATE_END_WRK DATETIME, --Дата увольнения сотрудника
 @LINK_PERS INT, --Ссылка на физ.лицо
 @DEP_LINK INT,
 @MAX_DATE DATETIME,
 @I INT,
 @varKSsoLink INT,
 @UCHET_PREM TINYINT	

SET @TYP_PERIOD = 4 --За 2 года

-- Проверка на продолжение больничного листа
DECLARE @varKSRefDoc int
SET @varKSRefDoc = ISNULL((SELECT TOP 1 FIRST_LINK FROM dbo.DIS_FIRST WHERE LINK = @LINK_ARCH),@LINK_ARCH)

SET @DATE_BEGIN_P = ISNULL((SELECT TOP 1 DATE1 FROM dbo.DIS WHERE LINK = @varKSRefDoc),@DATE_BEGIN)

SET @RP = 2
---Определение расчетного периода
DECLARE @NUMBER VARCHAR(10), @DATE_DOC DATETIME

SELECT 
	@DATE_BEGIN_RP = dbo.DateBeginOfYear(DATE_BEGIN), 
	@DATE_DOC = D.[DATE],
	@LINK_DEP = D.LINK_DEP,
	@NUMBER = D.NUMBER
FROM
	DBO.SDOC D 
	INNER JOIN dbo.sdoc_adis SD ON SD.LINK_UP = D.LINK
WHERE 
	D.LINK = @LINK_DOC

IF ISNULL(@LINK_DOC,0)  = 0
BEGIN
	exec dbo.SALARY_NEXT_NUM @NUMBER OUT, 'DOCUMENTS_ADD_ARCHE'
	SET @DATE_DOC = (Select top 1 WORKDATE from dbo.USER_DATES)
END	

IF @DATE_BEGIN_RP IS NULL OR YEAR(@DATE_BEGIN_RP) >= YEAR(@DATE_BEGIN_P) - @RP
	SET @DATE_BEGIN_RP = dbo.ConvertDMY2Date(1,1,YEAR(@DATE_BEGIN_P)- @RP)

SET @DATE_END_RP = dbo.ConvertDMY2Date(31,12,YEAR(@DATE_BEGIN_RP) + (@RP-1))

---Учитываем заданные года для расчетного периода
DECLARE @YEAR1 INT, @YEAR2 INT, @YEAR_M INT
SELECT TOP 1 @YEAR1 = YEAR1, @YEAR2 = YEAR2 FROM dbo.DIS D INNER JOIN dbo.VAC_PERIOD_CHANGE C ON C.LINK_EMPL = D.REF_EMPL
WHERE D.LINK = @LINK_ARCH AND D.DATE1 BETWEEN C.DATE1 AND C.DATE2

IF ISNULL(@YEAR1,0) > 0 OR ISNULL(@YEAR2,0) > 0
BEGIN

	SET @YEAR_M = (CASE WHEN ISNULL(@YEAR1,0) > ISNULL(@YEAR2,0) THEN ISNULL(@YEAR1,0) ELSE ISNULL(@YEAR2,0) END)
	SET @YEAR1 = (CASE WHEN ISNULL(@YEAR1,0) <= ISNULL(@YEAR2,0) THEN ISNULL(@YEAR1,0) ELSE ISNULL(@YEAR2,0) END)
	SET @YEAR2 = @YEAR_M

	SET @DATE_BEGIN_RP = dbo.ConvertDMY2Date(1,1,@YEAR1)
	SET @DATE_END_RP = dbo.ConvertDMY2Date(31,12,@YEAR2)

END	
ELSE
BEGIN
	SET @YEAR1 = YEAR(@DATE_BEGIN_RP)
	SET @YEAR2 = YEAR(@DATE_END_RP)
END	
-----------------------------------------------------------------

SELECT TOP 1 @LINK_PERS = PERS_LINK,  @SystPay = SYST_PAY, @DEP_LINK = ISNULL(@DEP_LINK,DEP_LINK)
FROM dbo.EMPL WHERE LINK = @LINK_EMPL

--Количество ставок на начало больничного
DECLARE @EmplNumStake NUMERIC(5,2), @DEFAULT_KBK INT
SELECT @EmplNumStake = num_stake, @DEFAULT_KBK = LINK_KBK FROM dbo.SA_EMPLS_INFO(@DATE_BEGIN_P,@LINK_EMPL)
SET @DEFAULT_KBK = ISNULL((SELECT CH.NEW_LINK FROM dbo.SAL_SFIN_CHANGES(@DATE_BEGIN) CH WHERE CH.LINK = @DEFAULT_KBK),@DEFAULT_KBK)

 --если страховой стаж работника менее 6 месяцев, то предел ус-танавливается в размере 1 МРОТ
IF @STAGE_Y < 1 AND @STAGE_M < 6 
	SET @LIMIT = 2

--- Сохранить параметры расчёта
SELECT @varKSsoLink = LINK FROM dbo.s_objects  WHERE CODE = 'DOCUMENTS_ADD_ARCHE'

EXECUTE dbo.SALARY_UPD_SDOC @LINK_DOC OUTPUT, @varKSsoLink, @NUMBER,@DATE_DOC,@comment,0,null,0, @LINK_DEP

IF not exists(select link_up from dbo.sdoc_adis  where link_up =@LINK_DOC)
		INSERT INTO dbo.sdoc_adis WITH (ROWLOCK) (LINK_UP,LINK_EMPL,LINK_PAY,DATE_BEGIN,SR_ZAR,SR_PREM,TYP_PERIOD,LIMIT,REF_DOC)
		VALUES (@LINK_DOC, @LINK_EMPL,@LINK_PAYS,@DATE_BEGIN_RP,0,0,@TYP_PERIOD,@LIMIT,@LINK_ARCH)
ELSE
		UPDATE dbo.sdoc_adis WITH (ROWLOCK) 
		SET 	LINK_EMPL=@LINK_EMPL, LINK_PAY=@LINK_PAYS, DATE_BEGIN=@DATE_BEGIN_RP, 
				SR_PREM=0, TYP_PERIOD=@TYP_PERIOD, LIMIT=@LIMIT, REF_DOC=@LINK_ARCH
		WHERE LINK_UP=@LINK_DOC

---------------------------------------------------------------------------------------
--Ограничивать количество оплачиваемых дней в каленарном году
DECLARE @ARCHE_OPT9 TINYINT
SET @ARCHE_OPT9 = dbo.sa_get_option_by_code('ARCHE_OPT9')

-- Больной член семьи по этому больничному
DECLARE @LINK_DIS_PERSON INT 

--Ограничения по количеству оплачиваемых дней по данному больничному
IF @ARCHE_OPT9 = 1 BEGIN

	SELECT @LINK_DIS_PERSON = ISNULL(REF_PERS_KID, @LINK_PERS) FROM dbo.SDOC_DIS WHERE LINK_UP = @LINK_ARCH

	DECLARE @MAX_DAYS INT, @MAX_DAYS_IVENT INT, @SUM_DAYS INT
	SELECT 
		  @MAX_DAYS = N.MAX_DAYS, 
		  @MAX_DAYS_IVENT = N.MAX_DAYS_IVENT,
		  @SUM_DAYS = ISNULL(
			( --Вычисляем количество дней больничных, за которые начислили больничные
			SELECT SUM(DAYS)
			FROM
			(	SELECT T.DATE1, [DAYS] = MAX(T.[DAYS])
				FROM
					dbo.SDOC D
					INNER JOIN dbo.SDOC_ADIS A ON D.LINK = A.LINK_UP
					INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON T.LINK_UP = D.LINK
					INNER JOIN dbo.SDOC_DIS SD ON A.REF_DOC = SD.LINK_UP AND A.LINK_EMPL = SD.LINK_EMPL
				WHERE
					SD.[TYPE] = N.LINK
					AND YEAR(@DATE_DOC) BETWEEN YEAR(T.DATE1) AND YEAR(T.DATE2)
					AND SD.LINK_EMPL = @LINK_EMPL
					AND ISNULL(SD.REF_PERS_KID, @LINK_PERS) = @LINK_DIS_PERSON
					AND SD.LINK_UP <> @LINK_ARCH --Данный больничный не учитываем
					AND SD.DATE1 <= @DATE_BEGIN --Проверяем только по предыдущим больничным
				GROUP BY T.DATE1
				) D
			)
			,0)
	FROM 
			dbo.NETRUD N
	WHERE
		  N.LINK = @REF_TYP_ARHE
		  AND @ARCHE_OPT9 = 1
END	

SELECT @MAX_DAYS = ISNULL(@MAX_DAYS,9999), @MAX_DAYS_IVENT = ISNULL(@MAX_DAYS_IVENT,9999), @SUM_DAYS = ISNULL(@SUM_DAYS,0)

--Столько осталось оплатить
SET @MAX_DAYS = (CASE WHEN @MAX_DAYS > @SUM_DAYS THEN @MAX_DAYS - @SUM_DAYS ELSE 0 END)
--Можно оплатить столько дней
SET @MAX_DAYS_IVENT = (CASE WHEN @MAX_DAYS_IVENT < @MAX_DAYS THEN @MAX_DAYS_IVENT ELSE @MAX_DAYS END)
-----------------------------------------------------------------------------------

---Определение процента оплаты по стажу
DECLARE @RercStag NUMERIC(18,2)

SELECT TOP 1 
	@RercStag = P 
FROM 
	dbo.DOCUMENTS_ADD_ARCH_SPR1 SPR1 
WHERE 
	@DATE_BEGIN BETWEEN SPR1.DATE_BEGIN AND SPR1.DATE_END
	AND @STAGE_Y BETWEEN SPR1.STAGE1 AND SPR1.STAGE2

DECLARE
	@PERCENT numeric(18,2), --Процент оплаты
	@Opt  tinyint, -- 1 - учитывать настройки справочника, 0 - нет
	@Stag  tinyint, -- 1 за первые N дней учитывать проценты по стажу, 0 - использовать указанй процент Perc1
	@Stag2  tinyint, -- 1 за последующие дни учитывать проценты по стажу, 0 - использовать указанй процент Perc2
	@Day1g  INT, --- количество первых дней, которые оплачивается Perc1
	@Perc1  numeric(18,2),
	@Perc2  numeric(18,2),
	@Day2_Payer  tinyint -- 0 - Первые два дня больничного оплачивает ФСС, 1 - Первые два дня больничного оплачивает Работодатель

SELECT @Stag = ISNULL(stag,0), @Stag2 = ISNULL(stag2,0), @Day2_Payer = (CASE WHEN ISNULL(@extension_DIS,0) = 0 THEN ISNULL(day2_payer,0) ELSE 0 END), 
	@Opt = ISNULL(opt,0), @Perc1 = ISNULL(perc1,0), @Perc2 = ISNULL(perc2,0),
	@Day1g = (CASE WHEN ISNULL(day1,0) = 1 THEN 0 ELSE ISNULL(day1,0) END) 
FROM DBO.KD_NETRUD where link = @REF_TYP_ARHE

IF @RECALC = 0  --- Расчет сумм по видам начислений
BEGIN
	--- Промежуточная база расчета
	CREATE TABLE #BASE1 (
		PERIOD DATETIME,
		CODE_PAY VARCHAR(254),
		NAME_PAY VARCHAR(254), 
		WAY_CALC INT,
		LINK_PAY INT,
		SUMMA NUMERIC(18,2),
		KOEF  NUMERIC(18,2),
		LINK_INC INT,
		LINK_VKR INT,
		DATE1 DATETIME,
		DATE2 DATETIME
	)

	DECLARE @Cur1 CURSOR, @CUR_EPML INT
	DECLARE @Cur2 CURSOR, @M INT, @Y INT, @PER DATETIME

	DECLARE @ARCHE_OPT4 TINYINT
	SET @ARCHE_OPT4 = dbo.sa_get_option_by_code('ARCHE_OPT4')

	SET @Cur1 = CURSOR FORWARD_ONLY
	FOR SELECT DISTINCT LINK FROM dbo.EMPL E-- INNER JOIN dbo.EMPL_STATUS(@DATE_BEGIN) S on E.link = S.empl_link --AND STATUS <= 2
		WHERE DEP_LINK = @LINK_DEP AND (@ARCHE_OPT4 = 1 AND PERS_LINK = @LINK_PERS) OR (@ARCHE_OPT4 = 0 AND E.link = @LINK_EMPL)

	OPEN @Cur1
	FETCH NEXT FROM @Cur1 INTO @CUR_EPML
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN
			
			SET @Cur2 = CURSOR FORWARD_ONLY
			FOR 
				SELECT m, y, DATE_BEGIN FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2
			OPEN @Cur2
			FETCH NEXT FROM @Cur2 INTO @M, @Y, @PER
			WHILE (@@fetch_status <> -1)
			BEGIN
				IF (@@fetch_status <> -2)
				BEGIN
			
				INSERT INTO #BASE1 (CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, SUMMA, KOEF, LINK_INC, LINK_VKR, DATE1, DATE2)
				exec dbo.SALARY_BASE_SUM_PAY_MONTH_DIF_PERIODS @LINK_PAYS, @CUR_EPML, @M, @Y			
				
				UPDATE #BASE1 SET PERIOD = @PER WHERE PERIOD IS NULL
				UPDATE #BASE1 SET LINK_VKR = @DEFAULT_KBK WHERE LINK_VKR IS NULL
			
				END
				FETCH NEXT FROM @Cur2 INTO @M, @Y, @PER
			END
		
			CLOSE @Cur2
			DEALLOCATE @Cur2

		END
		FETCH NEXT FROM @Cur1 INTO @CUR_EPML
	END
	
	CLOSE @Cur1 
	DEALLOCATE @Cur1

	INSERT INTO #BASE1 (PERIOD, CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, SUMMA, KOEF, LINK_INC, LINK_VKR, DATE1, DATE2)
	SELECT dbo.ConvertDMY2Date(01,12,YEAR_SAL), '---', 'Заработок у других работодателей', 1, 0, SUMMA, 1, 0, @DEFAULT_KBK, dbo.ConvertDMY2Date(01,12,YEAR_SAL), dbo.ConvertDMY2Date(31,12,YEAR_SAL)  
	FROM [dbo].[SAL_OTHER_DEP] 
	WHERE ACTIVE = 1 AND YEAR_SAL IN (@YEAR1,@YEAR2) AND LINK_EMPL = @LINK_EMPL 

	--- Определим, делать ли расчет в разрезе КБК
	DECLARE @ARCHE_OPT5 TINYINT
	SET @ARCHE_OPT5 = dbo.sa_get_option_by_code('ARCHE_OPT5')

	/*Заменяем источники финансирования в базовых начислениях с учетом истории изменений источников*/
	UPDATE B SET B.LINK_VKR = CH.NEW_LINK
	FROM #BASE1 B INNER JOIN dbo.SAL_SFIN_CHANGES(@DATE_BEGIN) CH ON CH.LINK = B.LINK_VKR

	--
	Select 
		PERIOD = dbo.ConvertDMY2Date(31,12,YEAR(MIN(PERIOD))), PERIOD1 = YEAR(PERIOD), CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, 
		SUMMA = SUM( CASE WHEN WAY_CALC = 6 AND (DATEDIFF(MONTH,DATE1, DATE2) + 1) <> 0 AND @UCHET_PREM = 1 THEN 
					CONVERT(NUMERIC(18,2), SUMMA * 
						(
							(DATEDIFF(MONTH,CASE WHEN DATE1 <= dbo.ConvertDMY2Date(1,1,@YEAR1) THEN dbo.ConvertDMY2Date(1,1,@YEAR1) ELSE DATE1 END,
								CASE WHEN DATE2 >= dbo.ConvertDMY2Date(31,12,@YEAR1) THEN dbo.ConvertDMY2Date(31,12,@YEAR1) ELSE DATE2 END) + 1)
						+	CASE WHEN @YEAR1 <> @YEAR2 THEN
								(DATEDIFF(MONTH,CASE WHEN DATE1 <= dbo.ConvertDMY2Date(1,1,@YEAR2) THEN dbo.ConvertDMY2Date(1,1,@YEAR2) ELSE DATE1 END,
									CASE WHEN DATE2 >= dbo.ConvertDMY2Date(31,12,@YEAR2) THEN dbo.ConvertDMY2Date(31,12,@YEAR2) ELSE DATE2 END) + 1)								
							ELSE 0 END
						)		
						/ (DATEDIFF(MONTH,DATE1, DATE2) + 1))
				ELSE SUMMA END),
		KOEF, LINK_INC, LINK_VKR = (CASE WHEN @ARCHE_OPT5 = 1 then LINK_VKR else @DEFAULT_KBK end)
	INTO #BASE
	from #BASE1 
	group by YEAR(PERIOD), CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, KOEF, LINK_INC, (CASE WHEN @ARCHE_OPT5 = 1 then LINK_VKR else @DEFAULT_KBK end)

	-- Перевернем таблицу 
	DECLARE @PAYS_MONTS VARCHAR(100)
	EXEC X_GET_TABLE_NAME @PAYS_MONTS OUTPUT

	---
	EXEC M_CROSS_TABLE
		'LINK_PAY, LINK_VKR',
		'PERIOD1', 'INT',
		'SUMMA', 'NUMERIC(18,2)', 'SUM(SUMMA) AS SUMMA',
		'#BASE', @PAYS_MONTS

	DELETE FROM dbo.SDOC_ADIS_TABLE3  WHERE LINK_UP = @LINK_DOC

	DECLARE @SCRIPT VARCHAR(8000)
	
	SET @SCRIPT = ' INSERT INTO dbo.SDOC_ADIS_TABLE3 (LINK_UP, ORDERS, LINK_PAY, LINK_KBK, SUMMA1, SUMMA2)'  
			+ ' Select ' + CONVERT(VARCHAR(20),@LINK_DOC) + ', 0, LINK_PAY, LINK_VKR'  
			+ CASE WHEN EXISTS (SELECT * from #BASE WHERE YEAR(PERIOD) = @YEAR1 )
			THEN ', ISNULL(SUMMA_' 
				+ CONVERT(VARCHAR(10),(Select  COUNT(DISTINCT YEAR(PERIOD)) FROM #BASE WHERE YEAR(PERIOD) <= @YEAR1 ))
				+ ',0)' ELSE ',0' END
			+ CASE WHEN @YEAR1 <> @YEAR2 AND EXISTS (SELECT * from #BASE WHERE YEAR(PERIOD) = @YEAR2 )
			THEN ', ISNULL(SUMMA_' 
				+ CONVERT(VARCHAR(10),(Select  COUNT(DISTINCT YEAR(PERIOD)) FROM #BASE WHERE YEAR(PERIOD) <= @YEAR2 ))
				+ ',0)' ELSE ',0' END
		+ ' from ' + @PAYS_MONTS
	
	EXEC  (@SCRIPT)

	SET @I = 0
	UPDATE dbo.SDOC_ADIS_TABLE3  
	SET @I = @I+1, ORDERS = @I
	WHERE LINK_UP = @LINK_DOC
	
END -- IF @RECALC = 0

-- Время
DECLARE @WTIME TABLE(Y INT)
INSERT INTO @WTIME (Y)
SELECT DISTINCT Y FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2

IF @RECALC < = 1 --- Расчет сумм по месяцам
BEGIN
	-- Расчет отработанного времени для каждого отрезочка времени
		---
	DECLARE @TABLE2 TABLE (Y INT, M INT, LINK_KBK INT, SUMMA_ZP NUMERIC(18,2), SUMMA_PR NUMERIC(18,2), DAYS INT, HOURS NUMERIC(18,2), DAYS_NORM INT, HOURS_NORM NUMERIC(18,2))
	INSERT INTO @TABLE2
	SELECT  
		Y = T.Y,
		M = 12,
		ISNULL(B.LINK_KBK,@DEFAULT_KBK),
		SUMMA_ZP = SUM(SUMMA),
		SUMMA_PR = 0,
		0,0,0,0
	FROM 
		@WTIME T LEFT JOIN
		(
		Select PERIOD = dbo.DateEndOfYear(@DATE_BEGIN_RP), LINK_PAY, LINK_KBK, 
			DATE1 = dbo.DateBeginOfYear(@DATE_BEGIN_RP), 
			DATE2 = dbo.DateEndOfYear(@DATE_BEGIN_RP),	
			SUMMA = T3.SUMMA1 
		FROM dbo.SDOC_ADIS_TABLE3 T3  WHERE LINK_UP = @LINK_DOC AND ISNULL(T3.SUMMA1,0) <> 0
	UNION ALL 
		Select PERIOD = dbo.DateEndOfYear(@DATE_END_RP), LINK_PAY, LINK_KBK, 
			DATE1 = dbo.DateBeginOfYear(@DATE_END_RP), 
			DATE2 = dbo.DateEndOfYear(@DATE_END_RP),	
			SUMMA = T3.SUMMA2  
		FROM dbo.SDOC_ADIS_TABLE3 T3  WHERE LINK_UP = @LINK_DOC AND ISNULL(T3.SUMMA2,0) <> 0
	) AS B ON T.Y = YEAR(B.PERIOD)
	GROUP BY
		T.Y, B.LINK_KBK

	----
	DECLARE @LINK_PAY_FSS INT	
	SET @LINK_PAY_FSS = (SELECT TOP 1 LINK FROM dbo.PAYS WHERE [OBJECT] = 3 AND WAY_CALC = 2)

	----
	UPDATE @TABLE2
	SET SUMMA_PR = 
		(
			SELECT MAX(PREDEL) FROM dbo.DICTIONARY_RANGE D
			WHERE LINK_PAYS = @LINK_PAY_FSS 
					AND TARIF = 1 
					AND [PERCENT] > 0 
					AND [DATE] = (SELECT TOP 1 [DATE] 
										FROM dbo.DICTIONARY_RANGE D1 
										WHERE D1.TARIF = D.TARIF 
												AND D1.LINK_PAYS = D.LINK_PAYS 
												AND [DATE] <= dbo.ConvertDMY2Date(1,1,(CASE WHEN Y < 2010 THEN 2010 ELSE Y END))
									ORDER BY [DATE] DESC) 
		 )


	DECLARE @CurPR CURSOR, @y1 INT, @m1 INT, @y2 INT, @m2 INT, @link_kbk1 INT, @SUM_KBK NUMERIC(18,2)
	
	SET @CurPR = CURSOR FORWARD_ONLY

	FOR select y, m, link_kbk from @TABLE2 order by y, m
	
	OPEN @CurPR
	FETCH NEXT FROM @CurPR INTO @y1, @m1, @link_kbk1
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN

			IF ISNULL(@y2,0) <> ISNULL(@y1,0) OR ISNULL(@m2,0) <> ISNULL(@m1,0)
				SELECT @SUM_KBK = 0, @y2 = @y1, @m2 = @m1

			UPDATE @TABLE2 SET HOURS_NORM = CASE WHEN ISNULL(SUMMA_ZP,0) > ISNULL(SUMMA_PR-@SUM_KBK,0) 
												THEN CASE WHEN ISNULL(SUMMA_PR-@SUM_KBK,0) > 0 THEN ISNULL(SUMMA_PR-@SUM_KBK,0) ELSE 0 END
												ELSE ISNULL(SUMMA_ZP,0) END
			WHERE @y1 = Y AND @m1 = M AND isnull(@link_kbk1,0) = isnull(link_kbk,0)

			SET @SUM_KBK = @SUM_KBK + ISNULL( (SELECT SUMMA = SUMMA_ZP	FROM @TABLE2 WHERE @y1 = Y AND @m1 = M AND isnull(@link_kbk1,0) = isnull(link_kbk,0)),0)

		END
	
		FETCH NEXT FROM @CurPR INTO @y1, @m1, @link_kbk1
	END
	
	CLOSE @CurPR
	DEALLOCATE @CurPR

	UPDATE A
	SET SUMMA_ZP = 
		CASE WHEN (SELECT SUM(B.SUMMA_ZP) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M) > 0 THEN
						A.SUMMA_ZP / (SELECT SUM(B.SUMMA_ZP) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M)
						* (SELECT SUM(B.HOURS_NORM) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M)
					ELSE 0 END	
	FROM @TABLE2 A

	UPDATE @TABLE2 SET SUMMA_PR = 0, HOURS_NORM = 0

	---
	DELETE FROM dbo.SDOC_ADIS_TABLE2  WHERE LINK_UP = @LINK_DOC
	
	INSERT INTO dbo.SDOC_ADIS_TABLE2 (LINK_UP, ORDERS, PERIOD, SUMMA, SUMMA_PREM, [DAYS], [HOURS], DAYS_N, HOURS_N, LINK_KBK)
	SELECT  @LINK_DOC, 0, dbo.ConvertDMY2Date(1, M, Y), SUMMA_ZP, SUMMA_PR, [DAYS],[HOURS],DAYS_NORM,HOURS_NORM, LINK_KBK
	FROM @TABLE2
	ORDER BY Y, M, LINK_KBK

	SET @I = 0
	UPDATE dbo.SDOC_ADIS_TABLE2  
	SET @I = @I+1, ORDERS = @I
	WHERE LINK_UP = @LINK_DOC
END	--IF @RECALC < = 1

DECLARE @RAION NUMERIC(18,2)
exec dbo.SA_EMPL_RAION_KOEF_BL @RAION OUT, @LINK_EMPL, @DATE_BEGIN

SET @RAION = CASE WHEN ISNULL(@RAION,0) <1 THEN 1 ELSE ISNULL(@RAION,0) END

DECLARE @SUM_LIMIT NUMERIC(18,4), @MINROT NUMERIC(18,2)
SET @MINROT = dbo.minrot2(@DATE_BEGIN) * (CASE WHEN @EmplNumStake <= 1 THEN @EmplNumStake ELSE 1 END) * 24

IF @RECALC < = 2 --- Расчет периодов больничного и определение средних сум
BEGIN		
	---Периоды больничного
	DECLARE
	 @DATE_RAB_END DATETIME,
	 @DATE_B DATETIME,
	 @R int	-- Первые 3 дня за счет работодателя
	
	---
	SELECT @R = @Day2_Payer * 3
	SELECT @DATE_RAB_END = DATEADD(DAY,@R-1,@DATE_BEGIN), @DATE_B = CASE WHEN @R > 0 THEN DATEADD(DAY,@R,@DATE_BEGIN) ELSE @DATE_BEGIN END

	/*Если это продолжение, то за счет работодателя ни чего не оплачивается, предполагается, что первый больничный был не менее 2-х дней*/
	
	---Разбивка периодов на периоды по настройкам оплаты больничного
	DECLARE
	 @DATE_BEGIN1 DATETIME,
	 @DATE_END1 DATETIME 

	--Обработка продолжения б/л
	DECLARE @LINK_BL_OLD INT, @DATE_BEG_OLD DATETIME, @DATE_END_OLD DATETIME
	SET @LINK_BL_OLD = (SELECT TOP 1 REF_DOC FROM dbo.DIS WHERE LINK = @LINK_ARCH)

	/*УЧИТЫВАЕМ, ЧТО ЭТО МОЖЕТ БЫТЬ ПРОДОЛЖЕНИЕМ БОЛЬНИЧНОГО ЛИСТА*/
	--Периоды продолжаемого б/л	
	SELECT @DATE_BEG_OLD = DATE1, @DATE_END_OLD = DATE2 FROM dbo.DIS WHERE LINK = @LINK_BL_OLD
	--расширить периоды за счет других продолжений
	IF EXISTS (SELECT LINK FROM dbo.DIS WHERE REF_DOC = @LINK_BL_OLD AND LINK <> @LINK_ARCH AND DATE1 < @DATE_BEGIN)
		SET @DATE_END_OLD = (SELECT MAX(DATE2) FROM dbo.DIS WHERE REF_DOC = @LINK_BL_OLD AND LINK <> @LINK_ARCH AND DATE1 < @DATE_BEGIN)

	IF @DATE_BEG_OLD IS NOT NULL
	BEGIN
		SET @Day1g = @Day1g - (DATEDIFF(DAY,@DATE_BEG_OLD,@DATE_END_OLD) + 1)
		SET @Day1g = CASE WHEN @Day1g < 0 THEN 0 ELSE @Day1g END
	END

	SET @DATE_END1 = (CASE WHEN DATEADD(DAY,@Day1g-1,@DATE_BEGIN) < @DATE_END THEN DATEADD(DAY,@Day1g-1,@DATE_BEGIN) ELSE @DATE_END END)
	SET @DATE_BEGIN1 = (CASE WHEN @DATE_END1 +1 < @DATE_END THEN @DATE_END1 +1 ELSE @DATE_END END)

	--== ФОРМИРНОВАНИЕ ПЕРИОДОВ ДЛЯ ОПЛАТЫ В РАЗРЕЗЕ ГОДА, МЕСЯЦА, ПЛАТЕЛЬЩИКА И ПРОЦЕНТОВ
	DECLARE @PERIODY TABLE ( ord int identity(1,1), DATE_BEGIN DATETIME, DATE_END DATETIME, R TINYINT, PERC NUMERIC(18,2), DH NUMERIC(18,2), DH_NORM NUMERIC(18,6), I TINYINT, SUM_LIMIT NUMERIC(20,4))
	
	--- 1. Разбивка на периоды по плательщикам и календарным месяцам
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, R, PERC, I)
	--- Определение плательщика
	select 
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_RAB_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_RAB_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 1, PERC = 0.00, 1 --Первое преобразование
	from dbo.months_ex(@DATE_BEGIN, @DATE_RAB_END)
	WHERE @R > 0
	UNION ALL
	select 
		DATE_BEGIN = (CASE WHEN @DATE_B > DATE_BEGIN THEN @DATE_B ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = 0.00, 1
	from dbo.months_ex(@DATE_B, @DATE_END)
	UNION
	--- Определение процента в зависимости от настроек больничного
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END1 < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END1 ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = CASE WHEN @Stag = 0 THEN @Perc1 ELSE @RercStag END, 1
	from dbo.months_ex(@DATE_BEGIN, @DATE_END1 )
	WHERE 	ISNULL(@OPT,0) = 1 
	UNION ALL
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN1 > DATE_BEGIN THEN @DATE_BEGIN1 ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = CASE WHEN @Stag2 = 0 THEN @Perc2 ELSE @RercStag END, 1
	from dbo.months_ex(@DATE_BEGIN1, @DATE_END )
	WHERE 	ISNULL(@OPT,0) = 1
	ORDER BY DATE_BEGIN, DATE_END

	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, R, PERC, I)
	--- Установка процента, если настройки не заданы
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = @RercStag, 1
	from dbo.months_ex(@DATE_BEGIN, @DATE_END )
	WHERE 	ISNULL(@OPT,0) = 0 
	ORDER BY DATE_BEGIN, DATE_END

	--- 2. Все границы периодов
	DECLARE @PERIODY1 TABLE (ORD INT IDENTITY(1,1), PER DATETIME)
	INSERT INTO @PERIODY1 (PER)
	SELECT PER FROM (SELECT PER = DATE_BEGIN FROM @PERIODY UNION SELECT PER = DATE_END FROM @PERIODY) as P
	UNION ALL 
	SELECT PER FROM (SELECT PER = DATE_BEGIN FROM @PERIODY UNION SELECT PER = DATE_END FROM @PERIODY) as P
	WHERE PER = dbo.DateEndOfMonth(PER)
	ORDER BY PER	

	--- 3.Получение отрезков времени со сдвинутыми датами начала
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I)
	SELECT 
		(CASE WHEN P1.PER = @DATE_BEGIN OR P1.PER = @DATE_END THEN P1.PER ELSE P1.PER + 1 END),
		ISNULL(P2.PER,P1.PER),
		2  --второе преобразование
	FROM 
		@PERIODY1 P1 LEFT JOIN @PERIODY1 P2 ON P1.ORD = P2.ORD - 1

	---Корректировка
	UPDATE @PERIODY
	SET DATE_BEGIN  = DATE_BEGIN + 1
	WHERE I = 2 AND DATE_BEGIN <> DATE_END AND DATE_BEGIN = dbo.DateEndOfMonth(DATE_BEGIN)

	--- 4. Исключение перекрывающихся периодов
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I)
	SELECT AP.DATE_BEGIN, AP.DATE_END, 3 FROM @PERIODY AP
	WHERE AP.I = 2 AND NOT EXISTS (SELECT * FROM @PERIODY AP1 WHERE AP1.I = 2 AND AP.DATE_BEGIN > AP1.DATE_BEGIN AND AP.DATE_END <= AP1.DATE_END)

	-- Особый случай, когда боьничный один день
	IF @DATE_BEGIN = @DATE_END 
		UPDATE @PERIODY SET DATE_BEGIN = @DATE_BEGIN, DATE_END = @DATE_END
		WHERE DATE_END >= @DATE_BEGIN

	--- 5. Расстановка плательщика и процентов по периодам
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I, R, PERC)
	Select 
		P3.DATE_BEGIN, P3.DATE_END, 4,
		R =  ISNULL((SELECT TOP 1 P1.R FROM @PERIODY P1 WHERE I = 1 AND P1.R = 1 AND (P3.DATE_BEGIN BETWEEN P1.DATE_BEGIN AND P1.DATE_END) AND (P3.DATE_END BETWEEN P1.DATE_BEGIN AND P1.DATE_END)  order by ord),0),
		PERC = ISNULL((SELECT TOP 1 P1.PERC FROM @PERIODY P1 WHERE I = 1 AND P1.PERC > 0 AND (P3.DATE_BEGIN BETWEEN P1.DATE_BEGIN AND P1.DATE_END) AND (P3.DATE_END BETWEEN P1.DATE_BEGIN AND P1.DATE_END) order by ord),0)
	FROM @PERIODY P3 
	WHERE P3.I = 3 
	
	--- 6. Соединение периодов
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I, R, PERC)
	Select 
		MIN(DATE_BEGIN), MAX(DATE_END), 5, R, PERC
	FROM @PERIODY P4 
	WHERE P4.I = 4 
	GROUP BY YEAR(DATE_BEGIN), MONTH(DATE_BEGIN), R, PERC
	
	DECLARE @ARCHE_OPT13 INT --Не начисять суммы за счёт ФСС 
	SET @ARCHE_OPT13 = dbo.SA_GET_OPTION_BY_CODE('ARCHE_OPT13')
	IF @ARCHE_OPT13 = 1
		DELETE FROM @PERIODY WHERE I = 5 AND R = 0
	
	--== ПОЛУЧЕНИЕ ПЕРИОДОВ ЗАВЕРШЕНО!
	
	---Определение предела

	-- увеличенный на размер районного коэффициента
	--Сумма МРОТ должна быть в пределах количества ставок, т.к. по ней идет расчет за полностью отработанное время на полной ставке

	DECLARE @LINK_FSS INT, @MAX_SUM_FSS NUMERIC(18,2)
	SET @LINK_FSS = (SELECT TOP 1 LINK FROM dbo.PAYS WHERE [OBJECT] = 3 AND WAY_CALC = 2)
	
	DECLARE @T_MAX_SUM_FSS TABLE (SUMMA NUMERIC(18,2))

	----
	INSERT INTO @T_MAX_SUM_FSS (SUMMA)
	SELECT MAX_SUM_FSS = 
				(
					SELECT MAX(PREDEL) FROM dbo.DICTIONARY_RANGE D
					WHERE LINK_PAYS = @LINK_FSS 
							AND TARIF = 1 
							AND [PERCENT] > 0 
							AND [DATE] = (SELECT TOP 1 [DATE] 
												FROM dbo.DICTIONARY_RANGE D1 
												WHERE D1.TARIF = D.TARIF 
														AND D1.LINK_PAYS = D.LINK_PAYS 
														AND [DATE] <= dbo.ConvertDMY2Date(1,1,(CASE WHEN Y < 2010 THEN 2010 ELSE Y END))
											ORDER BY [DATE] DESC) 
				 )
	FROM 
		@WTIME T
		
	SET @MAX_SUM_FSS = (SELECT SUM(SUMMA) FROM @T_MAX_SUM_FSS)
		--(SELECT SUM(SUMMA)/(12*COUNT(*)) FROM @T_MAX_SUM_FSS)
	IF ISNULL(@MAX_SUM_FSS,0) = 0
		SET @MAX_SUM_FSS = dbo.sa_get_option_by_code('ARCHE_OPT1')

	DECLARE @D NUMERIC(18,6)
--	IF EXISTS( SELECT * FROM [dbo].[NETRUD] N INNER JOIN [dbo].[SDOC_DIS] SD ON [SD].[TYPE] = [N].[LINK] WHERE [N].[DEKRET] = 1 AND SD.LINK_UP = @LINK_ARCH)
--		SET @D = dbo.sa_get_option_by_code('VAC_CHILD_OPT5') * 24
--	ELSE
	SET @D = 730 --730.000000/24

	----
	UPDATE @PERIODY
	SET 

		DH = DATEDIFF(DAY,DATE_BEGIN, DATE_END)+1,
	
		DH_NORM = 
				CASE WHEN DATE_BEGIN <= '20091231' THEN 
					DAY(dbo.DateEndOfMonth(DATE_BEGIN))
				ELSE
					@D
				END,			
		SUM_LIMIT = 
				CONVERT(NUMERIC(18,2),
					CASE @LIMIT
					WHEN 2 THEN @MINROT * @RAION -- в размере 1 МРОТ
					WHEN 3 THEN 
						CASE WHEN DATE_BEGIN <= '20091231' THEN 	
							(CASE WHEN @dekret = 0 THEN dbo.sa_get_option_by_code('ARCHE_OPT7') ELSE dbo.sa_get_option_by_code('ARCHE_OPT8') END) * @RAION 
						ELSE	
							-- !!! С 1 января 2010 года максимальный размер пособия одинаковый по все территории РФ!!!: Максимум без учета районныйх, но с учетом стажа
							@MAX_SUM_FSS
						END
					ELSE 0
					END 
				)				
	WHERE I = 5

	---------------------------------------------------------------------------------------
	--Откорректируем оплачиваемые дни за каждый период
	DECLARE @Cur3 CURSOR
	Declare @NEXT_DATE DATETIME

	IF @ARCHE_OPT9 = 1
	BEGIN
		SET @Cur3 = CURSOR FORWARD_ONLY

		FOR SELECT DATE_BEGIN FROM @PERIODY WHERE I = 5 AND YEAR(@DATE_DOC) BETWEEN YEAR(DATE_BEGIN) AND YEAR(DATE_END) ORDER BY DATE_BEGIN
		
		OPEN @Cur3
		FETCH NEXT FROM @Cur3 INTO @NEXT_DATE
		WHILE (@@fetch_status <> -1)
		BEGIN
			IF (@@fetch_status <> -2)
			BEGIN

				UPDATE @PERIODY
				SET DH = (CASE WHEN DH < @MAX_DAYS_IVENT THEN DH ELSE @MAX_DAYS_IVENT END)
				WHERE I = 5 AND DATE_BEGIN = @NEXT_DATE
				
				SELECT @MAX_DAYS_IVENT = (CASE WHEN DH < @MAX_DAYS_IVENT THEN @MAX_DAYS_IVENT - DH ELSE 0 END)
				FROM @PERIODY
				WHERE I = 5 AND DATE_BEGIN = @NEXT_DATE

			END
		
			FETCH NEXT FROM @Cur3 INTO @NEXT_DATE
		END
		
		CLOSE @Cur3
		DEALLOCATE @Cur3
	END	
	---------------------------------------------------------------------------------------

	---
	DECLARE @REP_SUMMA_PR NUMERIC(18,2), @SUMMA_ZP NUMERIC(18,2), @SUMMA_PR NUMERIC(18,2), @NORM NUMERIC(18,2), @WORK NUMERIC(18,2), @SR_ZP NUMERIC(20,4)
	
	SELECT 
		@SUMMA_ZP = ISNULL(SUM(SUMMA),0),
		@SUMMA_PR = 0
	FROM dbo.SDOC_ADIS_TABLE2 WHERE LINK_UP = @LINK_DOC

	----	
	DECLARE @KBK_KOEF TABLE (LINK_KBK INT, KOEF NUMERIC(18,4))
	DECLARE @SR_ZP_R numeric(20,4)

	---	
	SET @SR_ZP = CONVERT(NUMERIC(18,2),ISNULL(@SUMMA_ZP,0) / 730)
	SET @SR_ZP_R = @SR_ZP
	
	IF ISNULL(@SR_ZP,0) = 0  BEGIN
		DELETE FROM @KBK_KOEF
		INSERT INTO @KBK_KOEF (LINK_KBK, KOEF) 
		SELECT @DEFAULT_KBK, 1
	END 
	ELSE BEGIN
		---
		DECLARE @S NUMERIC(18,2)
		SET @S = ISNULL((SELECT SUM(SUMMA) FROM dbo.SDOC_ADIS_TABLE2 WHERE LINK_UP = @LINK_DOC),0)

		INSERT INTO @KBK_KOEF (LINK_KBK, KOEF) 
		SELECT LINK_KBK, CASE WHEN @S <> 0 THEN SUM(SUMMA) / @S ELSE 0 END 
		FROM dbo.SDOC_ADIS_TABLE2  WHERE LINK_UP = @LINK_DOC 
		GROUP BY LINK_KBK
	END
	---
	DELETE FROM dbo.SDOC_ADIS_TABLE1  WHERE LINK_UP = @LINK_DOC
	INSERT INTO dbo.SDOC_ADIS_TABLE1 (LINK_UP, ORDERS, DATE1, DATE2, SUM_LIMIT, [DAYS], [HOURS], SR_ZP, SUMMA, PERC, PAYER, LINK_KBK, KOEF_KBK)
	SELECT @LINK_DOC, 0, DATE_BEGIN, DATE_END, 
		LIMIT = CONVERT(NUMERIC(20,2), P.SUM_LIMIT / DH_NORM),
		DH,--(CASE WHEN @SystPay = 1 THEN DH ELSE 0 END),
		0,--(CASE WHEN @SystPay = 1 THEN 0 ELSE DH END),
		SR_ZP = NULL,
		0,
		PERC,
		R,
		K.LINK_KBK,
		K.KOEF
	FROM @PERIODY P INNER JOIN @KBK_KOEF K ON 1=1
	WHERE I = 5
	ORDER BY DATE_BEGIN

	UPDATE sdoc_adis WITH (ROWLOCK) 
	SET 	LINK_EMPL = @LINK_EMPL, LINK_PAY=@LINK_PAYS, DATE_BEGIN=@DATE_BEGIN_RP, SR_ZAR=@SR_ZP_R, SR_PREM=@SUMMA_PR, TYP_PERIOD=@TYP_PERIOD, LIMIT=@LIMIT, REF_DOC=@LINK_ARCH, INSTRUCT = 2
	WHERE LINK_UP = @LINK_DOC
	
END --@RECALC <= 2 

DECLARE @ARCHE_OPT10 TINYINT -- Мин. размер пособия при отсутсвии заработка выплачивать с учётом районного коэффицента
SET @ARCHE_OPT10 = dbo.SA_GET_OPTION_BY_CODE('ARCHE_OPT10')

DECLARE @SR_ZP_MINI numeric(20,4)
SET @SR_ZP_MINI = @MINROT * (CASE WHEN @ARCHE_OPT10 = 1 THEN @RAION ELSE 1 END)  / 730

SET @SR_ZP = ISNULL((SELECT TOP 1 SR_ZAR FROM dbo.sdoc_adis WHERE LINK_UP = @LINK_DOC),0)
SET @SR_ZP = CASE WHEN @SR_ZP < @SR_ZP_MINI THEN @SR_ZP_MINI ELSE @SR_ZP END

UPDATE dbo.SDOC_ADIS_TABLE1
SET 
	SR_ZP = convert(numeric(20,4),
			(CASE WHEN @SR_ZP < SUM_LIMIT OR @LIMIT = 4 AND @LIMIT <> 2 THEN @SR_ZP ELSE SUM_LIMIT END))
			* convert(numeric(20,4),(CASE WHEN PERC > 0 then PERC/100 else 0 end))
FROM 
	dbo.sdoc_adis A 
	INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON A.LINK_UP = T.LINK_UP
WHERE 
	T.LINK_UP = @LINK_DOC AND KOEF_KBK IS NOT NULL

----
Select CJ.DATE_BEGIN, CJ.DATE_END, CJ.LINK_VKR, DAYS = SUM(CJ.DAYS), HOURS = SUM(CJ.HOURS), LINK_EKR, SUMMA = SUM(SUMMA)
INTO #SUM_OLD
from 
	dbo.SDOC_ADIS SA inner join dbo.CALCULATE_JURNAL CJ on CJ.LINK_DOC = SA.LINK_UP
	inner join dbo.sdoc d on CJ.LINK_DOC = d.link 
where
	ISNULL(@LINK_ARCH,0) > 0
	AND
	SA.REF_DOC = @LINK_ARCH
	and
	d.object = (Select top 1 link from s_objects where code = 'DOCUMENTS_ADD_ARCHE')
GROUP BY
	CJ.DATE_BEGIN, CJ.DATE_END, CJ.LINK_VKR, LINK_EKR

DECLARE @LInkEKR213 int
SELECT @LinkEKR213 = LINK FROM dbo.DICTIONARY_ITEM WHERE CODE = '213'

---- сопоставить старые
UPDATE dbo.SDOC_ADIS_TABLE1
SET 
	SUMMA_NEW = CONVERT(NUMERIC(18,2), T.SR_ZP * T.[DAYS] * KOEF_KBK),--(CASE WHEN @SystPay = 1 THEN T.[DAYS] ELSE T.[HOURS] END) * KOEF_KBK),
	SUMMA_OLD = ISNULL(SO.SUMMA,0),
	DAYS = COALESCE(T.DAYS,0) - COALESCE(SO.DAYS,0), 
	HOURS = COALESCE(T.HOURS,0) - COALESCE(SO.HOURS,0)
FROM 
	dbo.sdoc_adis A 
	INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON A.LINK_UP = T.LINK_UP
	LEFT JOIN #SUM_OLD SO ON T.DATE1 = SO.DATE_BEGIN AND T.DATE2 = SO.DATE_END AND T.LINK_KBK = SO.LINK_VKR and PAYER = (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end)
WHERE 
	T.LINK_UP = @LINK_DOC AND KOEF_KBK IS NOT NULL AND SR_ZP IS NOT NULL

-- добавить старые, которых теперь нет
insert into dbo.SDOC_ADIS_TABLE1 
	(link_up, ORDERS, DATE1, DATE2, SUM_LIMIT, DAYS, HOURS, SUMMA, PERC, SR_ZP, PAYER, LINK_KBK, KOEF_KBK, SUMMA_OLD, SUMMA_NEW)
Select 
	@LINK_DOC, 0, DATE_BEGIN, DATE_END, 0, -DAYS, -HOURS, 0, 0, 0, (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end), LINK_VKR, 1, SO.SUMMA, 0
from 
	#SUM_OLD SO
where 
	NOT EXISTS (Select * from dbo.SDOC_ADIS_TABLE1 T where T.LINK_UP = @LINK_DOC and T.DATE1 = SO.DATE_BEGIN AND T.DATE2 = SO.DATE_END 
		AND T.LINK_KBK = SO.LINK_VKR and PAYER = (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end))

---- сравнить
UPDATE dbo.SDOC_ADIS_TABLE1
SET SUMMA = ISNULL(SUMMA_NEW,0) - ISNULL(SUMMA_OLD,0)
WHERE LINK_UP = @LINK_DOC

--удалить пустые строки
DELETE FROM dbo.SDOC_ADIS_TABLE1
WHERE LINK_UP = @LINK_DOC AND ISNULL(SUMMA_NEW,0) = 0

SET @I = 0

UPDATE dbo.SDOC_ADIS_TABLE1  
SET @I = @I+1, ORDERS = @I
WHERE LINK_UP = @LINK_DOC

---
DECLARE @SUMMA NUMERIC(18,2)
SELECT @SUMMA = ISNULL((SELECT SUM(SUMMA) FROM dbo.SDOC_ADIS_TABLE1 WHERE LINK_UP = @LINK_DOC),0), @SUMMA_ZP = ISNULL(@SUMMA_ZP,0), @SUMMA_PR = ISNULL(@SUMMA_PR,0)

---
SELECT @NUMBER = NUMBER,  @DATE_DOC = DATE from SDOC WHERE LINK = @LINK_DOC

if exists (select * from #SUM_OLD)
	set @comment = 'Перерасчет: ' + @comment

--- Сохрание расчета
EXECUTE dbo.SALARY_UPD_SDOC @LINK_DOC OUTPUT, @varKSsoLink, @NUMBER,@DATE_DOC,@comment,0,null,@SUMMA

IF @OPER = 1 
	exec dbo.SD_N_BOL_PROV @LINK_DOC

SET NOCOUNT OFF

GO


GRANT EXECUTE ON dbo.[SA_N_BOL_FILL2] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SAL_CHANGE_KBK]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SAL_CHANGE_KBK]

GO

CREATE    PROC [dbo].SAL_CHANGE_KBK
	@OLD_KBK_LINK	INT,
	@NEW_KBK_LINK	INT,
	@DATE		DATETIME,
	@OPT1		TINYINT = 0,
	@OPT1_1		TINYINT = 0,
	@OPT2		TINYINT = 0,
	@OPT3		TINYINT = 0,
	@OPT4		TINYINT = 0,
	@LINK_EMPL	INT = NULL,
	@OPT5		TINYINT = 0 --Замена у договорников
AS

IF COALESCE(is_member('db_owner'),0) = 0
BEGIN
	RAISERROR('Данная функция работает только для пользователя роли "DB_OWNER" !!!',11,1)
	RETURN 1
END


IF @LINK_EMPL IS NOT NULL
	SET @OPT5 = 0

---
IF @OLD_KBK_LINK IS NULL
OR @OLD_KBK_LINK = 0
OR @NEW_KBK_LINK IS NULL
OR @NEW_KBK_LINK = 0
OR @DATE IS NULL
	RETURN 1


declare @varKSparSFIN varchar(20),  @varKSparSFIN_OLD varchar(20) , @cStr VARCHAR (256)

SELECT 
	@varKSparSFIN_OLD = CODE,
	@varKSparSFIN = (SELECT B.CODE FROM dbo.SAL_SFIN B WHERE B.LINK = A.LINK_CH_SFIN)
FROM dbo.SAL_SFIN A WHERE A.LINK = @OLD_KBK_LINK AND A.LINK_CH_SFIN IS NOT NULL AND A.LINK_CH_SFIN <> @NEW_KBK_LINK

IF @varKSparSFIN IS NOT NULL
BEGIN

		SET @cStr = 'В спраочнике "Источники финансирования" для источника "'+LTRIM(RTRIM(@varKSparSFIN_OLD)) +'" указан новый источник "'+ltrim(rtrim(@varKSparSFIN))+'"!'
		RAISERROR(@cStr, 11, 1)
		RETURN 1
END	



declare @DEP_LINK int
exec dbo.xd_whats_zb @DEP_LINK output

DECLARE @LINK_EMPL1 INT
SET @LINK_EMPL1 = (CASE WHEN @LINK_EMPL IS NULL THEN -1 ELSE @LINK_EMPL END)

SET @OPT1 = COALESCE(@OPT1,0)
SET @OPT2 = COALESCE(@OPT2,0)
SET @OPT3 = COALESCE(@OPT3,0)
SET @OPT4 = COALESCE(@OPT4,0)
SET @OPT5 = COALESCE(@OPT5,0)

---Расширить период редактирования
SELECT * INTO #TMP_DATES FROM dbo.ADMIN_INFO

DECLARE @KASSA INT, @BB DATETIME, @BE DATETIME
SELECT @KASSA = LINK FROM DBO.S_OBJECTS WHERE CODE = 'KASSA'
SELECT @BB = CONVERT(DATETIME, '19000101', 112), @BE = CONVERT(DATETIME, '20990101', 112)
EXECUTE DBO.I_SET_ADMIN_DATE @KASSA, @BB, @BB, @BE

IF @OPT1 = 1 BEGIN

	IF @OPT1_1 = 1 BEGIN

		/*ПОСТОЯННЫЕ НАЧИСЛЕНИЯ*/
		INSERT INTO dbo.PAYS_EMPL (LINK_EMPL, LINK_SOVM, LINK_PAYS, DATE, SUMMA, LINK_MP, LINK_KBK, NO_CALC)
		SELECT 
			PE.LINK_EMPL, PE.LINK_SOVM, PE.LINK_PAYS, [DATE] = @DATE, PE.SUMMA, PE.LINK_MP, LINK_KBK = @NEW_KBK_LINK, PE.NO_CALC
		FROM dbo.sa_dict_pays_empl0(@LINK_EMPL1,DEFAULT,DEFAULT) PE INNER JOIN dbo.EMPL E ON E.LINK = PE.LINK_EMPL
		WHERE
			E.DEP_LINK = @DEP_LINK
			AND PE.LINK_KBK = @OLD_KBK_LINK
			AND @DATE BETWEEN PE.DATE_BEG AND ISNULL(PE.DATE_END,@DATE)
			AND @DATE > PE.[DATE_BEG]
			AND PE.SUMMA > 0
			AND NOT EXISTS (SELECT * FROM dbo.PAYS_EMPL PE2 WHERE PE.LINK_EMPL = PE2.LINK_EMPL 
								AND ISNULL(PE.LINK_SOVM,0) = ISNULL(PE2.LINK_SOVM,0)
								AND PE.[LINK_PAYS] = PE2.[LINK_PAYS]						
								AND @DATE = PE2.[DATE]
								)
		ORDER BY
				PE.LINK_EMPL, PE.LINK_SOVM					

		UPDATE PE
			SET PE.LINK_KBK = @NEW_KBK_LINK
		FROM dbo.PAYS_EMPL PE INNER JOIN dbo.EMPL E ON E.LINK = PE.LINK_EMPL
		WHERE	
			E.DEP_LINK = @DEP_LINK
			AND PE.LINK_KBK = @OLD_KBK_LINK
			AND @DATE = PE.[DATE]
			AND PE.SUMMA > 0
			AND	(@LINK_EMPL IS NULL OR @LINK_EMPL = E.LINK)	
		
		----Часы нагрузки
		if object_id('tempdb..#STO_WEEK_HOURS') is not null
			DROP TABLE #STO_WEEK_HOURS

		SELECT 
			PE.link, PE.link_up, PE.link_tar_empl, PE.link_pay, PE.link_paral, PE.link_clas, PE.link_les, PE.week_hours, PE.[percent], PE.t, 
			DATE1 = @DATE, PE.DATE2, LINK_KBK = @NEW_KBK_LINK, PE.link_empl, PE.NO_CALC, PE.M_STAVKA	
		INTO #STO_WEEK_HOURS	
		FROM dbo.EMPL E INNER JOIN dbo.STO_WEEK_HOURS PE ON PE.LINK_EMPL = E.LINK
		WHERE	
			LINK_KBK = @OLD_KBK_LINK
			AND @DATE BETWEEN PE.DATE1 AND ISNULL(PE.DATE2,@DATE)
			AND @DATE > PE.DATE1
			AND E.dep_link = @DEP_LINK
			AND	(@LINK_EMPL IS NULL OR @LINK_EMPL = E.LINK)	
		---
		INSERT INTO dbo.STO_WEEK_HOURS (link_up, link_tar_empl, link_pay, link_paral, link_clas, link_les, week_hours,[percent], t, DATE1, DATE2, LINK_KBK, link_empl, NO_CALC, M_STAVKA)
		SELECT link_up, link_tar_empl, link_pay, link_paral, link_clas, link_les, week_hours,[percent], t, DATE1, DATE2, LINK_KBK, link_empl, NO_CALC, M_STAVKA
		FROM
			#STO_WEEK_HOURS PE
		WHERE
			(@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)	
			AND
			NOT EXISTS (SELECT * FROM dbo.STO_WEEK_HOURS PE2 WHERE PE.LINK_EMPL = PE2.LINK_EMPL 
								AND ISNULL(PE.link_tar_empl,0) = ISNULL(PE2.link_tar_empl,0)
								AND PE.[link_pay] = PE2.[link_pay]						
								AND @DATE = PE2.[DATE1] )				
		---
		UPDATE PE
		SET PE.DATE2 = DATEADD(DAY,-1,@DATE)
		FROM dbo.STO_WEEK_HOURS PE INNER JOIN #STO_WEEK_HOURS PE2 ON PE.LINK = PE2.LINK
		WHERE (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)

		-----
		UPDATE PE
			SET PE.LINK_KBK = @NEW_KBK_LINK
		FROM dbo.EMPL E INNER JOIN dbo.STO_WEEK_HOURS PE ON PE.LINK_EMPL = E.LINK
		WHERE	
			LINK_KBK = @OLD_KBK_LINK
			AND @DATE = PE.DATE1
			AND E.dep_link = @DEP_LINK
			AND (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)

		----Надбавки по тарификации
		if object_id('tempdb..#STO_ADD_PAYMENT') is not null
			DROP TABLE #STO_ADD_PAYMENT

		SELECT 
			PE.LINK, PE.link_tar_empl, PE.link_pay, date_begin = @DATE, PE.date_end, PE.[percent], PE.comment, PE.ets_only, PE.mode, 
			PE.summa, LINK_KBK = @NEW_KBK_LINK, PE.link_expir, PE.link_empl, PE.NO_CALC
		INTO #STO_ADD_PAYMENT	
		FROM dbo.EMPL E INNER JOIN dbo.STO_ADD_PAYMENT PE ON PE.LINK_EMPL = E.LINK
		WHERE	
			LINK_KBK = @OLD_KBK_LINK
			AND @DATE BETWEEN PE.DATE_BEGIN AND ISNULL(PE.DATE_END,@DATE)
			AND @DATE > PE.DATE_BEGIN
			AND E.dep_link = @DEP_LINK
			AND (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)
		---
		INSERT INTO dbo.STO_ADD_PAYMENT (link_tar_empl, link_pay, date_begin, date_end, [percent], comment, ets_only, mode, 
			summa, LINK_KBK, link_expir, link_empl, NO_CALC)
		SELECT link_tar_empl, link_pay, date_begin, date_end, [percent], comment, ets_only, mode, 
			summa, LINK_KBK, link_expir, link_empl, NO_CALC
		FROM
			#STO_ADD_PAYMENT PE
		WHERE
			(@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)
			AND
			NOT EXISTS (SELECT * FROM dbo.STO_ADD_PAYMENT PE2 WHERE PE.LINK_EMPL = PE2.LINK_EMPL 
								AND ISNULL(PE.link_tar_empl,0) = ISNULL(PE2.link_tar_empl,0)
								AND PE.[link_pay] = PE2.[link_pay]						
								AND @DATE = PE2.[DATE_BEGIN]
								)				
		---
		UPDATE PE
		SET PE.DATE_END = DATEADD(DAY,-1,@DATE)
		FROM dbo.STO_ADD_PAYMENT PE INNER JOIN #STO_ADD_PAYMENT PE2 ON PE.LINK = PE2.LINK
		WHERE (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)

		-----
		UPDATE PE
			SET PE.LINK_KBK = @NEW_KBK_LINK
		FROM dbo.EMPL E INNER JOIN dbo.STO_ADD_PAYMENT PE ON PE.LINK_EMPL = E.LINK
		WHERE	
			LINK_KBK = @OLD_KBK_LINK
			AND @DATE = PE.DATE_BEGIN
			AND E.dep_link = @DEP_LINK			
			AND (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)

	END
	ELSE
		BEGIN

			/*ПОСТОЯННЫЕ НАЧИСЛЕНИЯ*/
			UPDATE PE
				SET PE.LINK_KBK = @NEW_KBK_LINK
			FROM dbo.PAYS_EMPL PE INNER JOIN dbo.EMPL E ON E.LINK = PE.LINK_EMPL
			WHERE	
				E.DEP_LINK = @DEP_LINK
				AND PE.LINK_KBK = @OLD_KBK_LINK
				AND @DATE >= PE.[DATE]
				AND PE.SUMMA > 0
				AND	(@LINK_EMPL IS NULL OR @LINK_EMPL = E.LINK)	
			
			/*ЧАСЫ НАГРУЗКИ*/
			UPDATE PE
				SET PE.LINK_KBK = @NEW_KBK_LINK
			FROM dbo.EMPL E INNER JOIN dbo.STO_WEEK_HOURS PE ON PE.LINK_EMPL = E.LINK
			WHERE	
				LINK_KBK = @OLD_KBK_LINK
				AND @DATE >= PE.DATE1
				AND E.dep_link = @DEP_LINK
				AND (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)
			
			/*НАДБАВКИ ПО ТАРИФИКАЦИИ*/
			UPDATE PE
				SET PE.LINK_KBK = @NEW_KBK_LINK
			FROM dbo.EMPL E INNER JOIN dbo.STO_ADD_PAYMENT PE ON PE.LINK_EMPL = E.LINK
			WHERE	
				LINK_KBK = @OLD_KBK_LINK
				AND @DATE >= PE.DATE_BEGIN
				AND E.dep_link = @DEP_LINK			
				AND (@LINK_EMPL IS NULL OR @LINK_EMPL = PE.LINK_EMPL)
		
		END

	/*НАДБАВКИ ЗА ПРЕДМЕТ*/
	UPDATE	dbo.STO_LESSON_PAYS
	SET	LINK_KBK = @NEW_KBK_LINK
	WHERE	
		ISNULL(LINK_KBK,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE >= [date_begin]
		AND dep_link = @DEP_LINK
		AND @LINK_EMPL IS NULL
		
	/* ПОСТОЯННЫЕ УДЕРЖАНИЯ */
	UPDATE dbo.EMPL_TAX
	SET	LINK_VKR = @NEW_KBK_LINK
	FROM dbo.EMPL E INNER JOIN dbo.EMPL_TAX ET ON ET.LINK_EMPL = E.LINK
	WHERE ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE <= ISNULL(DATE2,@DATE)
		AND E.DEP_LINK = @DEP_LINK
		AND (@LINK_EMPL IS NULL OR @LINK_EMPL = ET.LINK_EMPL)		
	
	/* ШТАТНОЕ РАСПИСАНИЕ */
	SELECT 
		T.LINK_UP, T.SUBDIV_LINK, T.POST_LINK, T.OKLAD, T.NUM_STAKE,
		T.DEY_LINK, T.KAT_LINK, T.GOSSL, T.FIN, T.FIN_FOND, T.KAT_GOS_LINK, 
		DATE_BEGIN = @DATE, T.DATE_END, T.GR_GOS_LINK, T.ETS_RAZR, LINK_KBK = @NEW_KBK_LINK
	INTO	#TMP
	FROM	dbo.STAFF_HEAD H INNER JOIN STAFF T ON H.LINK = T.LINK_UP
	WHERE	@DATE BETWEEN T.DATE_BEGIN AND T.DATE_END
		AND H.DEP_LINK = @DEP_LINK
		AND ISNULL(T.LINK_KBK,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE > T.DATE_BEGIN
		AND (@LINK_EMPL IS NULL OR @LINK_EMPL IS NOT NULL AND EXISTS (SELECT * FROM dbo.ITEM_MOVE IM WHERE IM.EMPL_LINK = @LINK_EMPL AND IM.STAFF_LINK = H.LINK))
		
	---
	ALTER TABLE dbo.STAFF DISABLE TRIGGER ALL

		UPDATE	dbo.STAFF
		SET	DATE_END = DATEADD(DAY,-1,@DATE)
		FROM	dbo.STAFF_HEAD H INNER JOIN dbo.STAFF T ON H.LINK = T.LINK_UP
		WHERE	@DATE BETWEEN T.DATE_BEGIN AND T.DATE_END 
			AND H.DEP_LINK = @DEP_LINK
			AND @DATE > T.DATE_BEGIN
			AND ISNULL(T.LINK_KBK,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND (@LINK_EMPL IS NULL OR @LINK_EMPL IS NOT NULL AND EXISTS (SELECT * FROM dbo.ITEM_MOVE IM WHERE IM.EMPL_LINK = @LINK_EMPL AND IM.STAFF_LINK = H.LINK))

	ALTER TABLE [dbo].[STAFF] ENABLE  TRIGGER ALL

	---

	ALTER TABLE dbo.STAFF DISABLE TRIGGER ALL

		INSERT INTO dbo.STAFF
		(
			LINK_UP, SUBDIV_LINK, POST_LINK, OKLAD, NUM_STAKE, 
			DEY_LINK, KAT_LINK, GOSSL, FIN, FIN_FOND, KAT_GOS_LINK, 
			DATE_BEGIN, DATE_END, GR_GOS_LINK, ETS_RAZR, LINK_KBK
		)
		SELECT 
			LINK_UP, SUBDIV_LINK, POST_LINK, OKLAD, NUM_STAKE, 
			DEY_LINK, KAT_LINK, GOSSL, FIN, FIN_FOND, KAT_GOS_LINK, 
			DATE_BEGIN, DATE_END, GR_GOS_LINK, ETS_RAZR, LINK_KBK
		from	 #TMP

	ALTER TABLE [dbo].[STAFF] ENABLE  TRIGGER ALL
	
	---
	ALTER TABLE dbo.STAFF DISABLE TRIGGER ALL

		UPDATE	dbo.STAFF
		SET	LINK_KBK = @NEW_KBK_LINK
		FROM	dbo.STAFF_HEAD H INNER JOIN dbo.STAFF T ON H.LINK = T.LINK_UP
		WHERE	H.DEP_LINK = @DEP_LINK
			AND T.DATE_BEGIN = @DATE
			AND ISNULL(T.LINK_KBK,@OLD_KBK_LINK) = @OLD_KBK_LINK
			AND (@LINK_EMPL IS NULL OR @LINK_EMPL IS NOT NULL AND EXISTS (SELECT * FROM dbo.ITEM_MOVE IM WHERE IM.EMPL_LINK = @LINK_EMPL AND IM.STAFF_LINK = H.LINK))

	ALTER TABLE [dbo].[STAFF] ENABLE  TRIGGER ALL

	--- Замена в расчетах отчислений ЕСН
	ALTER TABLE dbo.SDOC_ESN_TABLE DISABLE TRIGGER ALL

	UPDATE GT
	SET	
		GT.LINK_VKR = @NEW_KBK_LINK
	FROM 
		dbo.SDOC S 
		INNER JOIN dbo.SDOC_ESN SD on S.LINK = SD.LINK_UP
		INNER JOIN dbo.SDOC_ESN_TABLE GT on S.LINK = GT.LINK_UP
	WHERE
		@DATE <= S.DATE_CALC
		AND
		S.LINK_DEP = @DEP_LINK
		AND
		ISNULL(GT.LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND 
		(@LINK_EMPL IS NULL OR @LINK_EMPL = GT.LINK_EMPL)

	ALTER TABLE [dbo].SDOC_ESN_TABLE ENABLE  TRIGGER ALL

END

 --Замена в журнале операций
IF @OPT2 = 1 BEGIN

	ALTER TABLE [dbo].[CALCULATE_JURNAL]
		DISABLE TRIGGER ALL
	
	UPDATE dbo.CALCULATE_JURNAL 
	SET LINK_VKR = @NEW_KBK_LINK 
	WHERE ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE <= PERIOD_BEGIN -- Сформированные после смены КБК
		AND LINK_DEP = @DEP_LINK
		AND (@LINK_EMPL IS NULL OR LINK_EMPL = @LINK_EMPL)

	ALTER TABLE [dbo].[CALCULATE_JURNAL]
		ENABLE  TRIGGER ALL


	--Замена в предоставленных вычетах
	ALTER TABLE [dbo].[SAL_DED_MONTH]
		DISABLE TRIGGER ALL
	
	UPDATE dbo.SAL_DED_MONTH 
	SET LINK_VKR = @NEW_KBK_LINK 
	FROM SAL_DED_MONTH CJ INNER JOIN dbo.EMPL E ON CJ.LINK_EMPL = E.LINK
	WHERE ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE <= DATE_DED -- Сформированные после смены КБК
		AND E.DEP_LINK = @DEP_LINK
		AND (@LINK_EMPL IS NULL OR CJ.LINK_EMPL = @LINK_EMPL)
	
	ALTER TABLE [dbo].[SAL_DED_MONTH]
		ENABLE  TRIGGER ALL

END

 --Замена в остатках
IF @OPT3 = 1 BEGIN

	ALTER TABLE [dbo].[SAL_REMAIN]
		DISABLE TRIGGER ALL
	
	UPDATE dbo.SAL_REMAIN 
	SET LINK_VKR = @NEW_KBK_LINK 
	FROM dbo.SAL_REMAIN R INNER JOIN dbo.EMPL E ON R.LINK_EMPL = E.LINK
	WHERE ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND year(@DATE) <= YEAR_SAL
		AND E.DEP_LINK = @DEP_LINK
		AND (@LINK_EMPL IS NULL OR R.LINK_EMPL = @LINK_EMPL)
	
	ALTER TABLE [dbo].[SAL_REMAIN]
		ENABLE  TRIGGER ALL
END

IF @OPT4 = 1 BEGIN
	--Замена в исполнительных листах
	ALTER TABLE dbo.SDOC_WRIT DISABLE TRIGGER ALL
	
		UPDATE dbo.SDOC_WRIT
		SET	LINK_VKR = @NEW_KBK_LINK
		FROM dbo.SDOC S INNER JOIN dbo.SDOC_WRIT SD ON S.LINK = SD.LINK_UP 
		WHERE ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
			AND (@DATE <= DATE1 OR @DATE BETWEEN DATE1 AND DATE2)
			AND S.LINK_DEP = @DEP_LINK
			AND (@LINK_EMPL IS NULL OR SD.LINK_EMPL = @LINK_EMPL)
	
	ALTER TABLE [dbo].[SDOC_WRIT] ENABLE  TRIGGER ALL
END

IF @OPT5 = 1 BEGIN

	--Замена в договорах
	CREATE TABLE #REESTR_DGH (NEW_LINK int NOT NULL, OLD_LINK int NOT NULL)

	INSERT INTO dbo.REESTR_DGH 
		(NUMBER, [DATE], DATE1, DATE2, [TYPE], PAYMENT, SUMMA, COMMENT, VZNOS, LINK_PAYS, FLAG_NALOG, DEP_LINK, PERS_LINK, FLAG_ESN, FLAG_TRAVMA, LINK_KBK, AVANCE)
	OUTPUT inserted.LINK, inserted.SUMMA INTO #REESTR_DGH (NEW_LINK, OLD_LINK) --временно вместо суммы копирую страрый линк для истории, сумму потом верну из старой записи
	SELECT
		NUMBER, [DATE], @DATE, DATE2, [TYPE], PAYMENT, LINK, COMMENT, VZNOS, LINK_PAYS, FLAG_NALOG, DEP_LINK, PERS_LINK, FLAG_ESN, FLAG_TRAVMA, @NEW_KBK_LINK, AVANCE
	FROM 
		dbo.REESTR_DGH R
	WHERE
		R.DEP_LINK = @DEP_LINK
		AND
		R.LINK_KBK = @OLD_KBK_LINK
		AND
		@DATE <= ISNULL(DATE2,@DATE)
		AND
		@DATE > ISNULL(DATE1,@DATE)
	
	--	
	UPDATE dbo.REESTR_DGH SET LINK_KBK = @NEW_KBK_LINK WHERE LINK_KBK = @OLD_KBK_LINK AND @DATE <= ISNULL(DATE1,@DATE)		

	UPDATE B SET B.DATE2 = @DATE - 1
	FROM #REESTR_DGH A INNER JOIN dbo.REESTR_DGH B ON B.LINK = A.OLD_LINK

	--в новых копиях возвращаю на место сумму из копий
	UPDATE C
		SET C.SUMMA = B.SUMMA 
	FROM
		#REESTR_DGH A 
		INNER JOIN dbo.REESTR_DGH B ON B.LINK = A.OLD_LINK		
		INNER JOIN dbo.REESTR_DGH C ON C.LINK = A.NEW_LINK

	--Копирую хвост с вычетами
	INSERT INTO dbo.EMPL_DED (DED_LINK, DATE1, DATE2, LINK_DGH)
	SELECT 
		DED_LINK, DATE1, DATE2, A.NEW_LINK
	FROM 
		#REESTR_DGH A INNER JOIN dbo.EMPL_DED B ON B.LINK_DGH = A.OLD_LINK

	--в постоянных удержаниях тоже замена КБК
	--новые строки со старыми линками
	SELECT 
		B.LINK, LINK_TAX, @DATE AS DATE1, DATE2, SUMMA, @NEW_KBK_LINK AS LINK_VKR, B.LINK_DGH
	INTO
		#TMP_EMPL_TAX	
	FROM 
		#REESTR_DGH A INNER JOIN dbo.EMPL_TAX B ON B.LINK_DGH = A.OLD_LINK
	WHERE
		B.LINK_VKR = @OLD_KBK_LINK
		AND
		@DATE <= ISNULL(DATE2,@DATE)
		AND
		@DATE > ISNULL(DATE1,@DATE)
		
	---	
	UPDATE B SET B.LINK_VKR = @NEW_KBK_LINK
	FROM dbo.EMPL_TAX B
	WHERE B.LINK_VKR = @OLD_KBK_LINK AND @DATE <= ISNULL(B.DATE1,@DATE)	
	
	--вставляю новые строки
	INSERT INTO dbo.EMPL_TAX (LINK_TAX, DATE1, DATE2, SUMMA, LINK_VKR, LINK_DGH)
	SELECT LINK_TAX, DATE1, DATE2, SUMMA, LINK_VKR, LINK_DGH FROM #TMP_EMPL_TAX

	--в тех строках, с которых сделал копию закрываю дату
	UPDATE B SET DATE2 = @DATE - 1
	FROM #TMP_EMPL_TAX A INNER JOIN dbo.EMPL_TAX B ON B.LINK = A.LINK

	--Копирую хвост с постоянными удержаниями
	INSERT INTO dbo.EMPL_TAX (LINK_TAX, DATE1, DATE2, SUMMA, LINK_VKR, LINK_DGH)
	SELECT 
		LINK_TAX, DATE1, DATE2, SUMMA, LINK_VKR, A.NEW_LINK
	FROM 
		#REESTR_DGH A INNER JOIN dbo.EMPL_TAX B ON B.LINK_DGH = A.OLD_LINK

	--Замена в журнале операций по договорникам

	ALTER TABLE [dbo].[CALCULATE_JURNAL]
		DISABLE TRIGGER ALL
	
	UPDATE dbo.CALCULATE_JURNAL SET LINK_VKR = @NEW_KBK_LINK 
	WHERE 
		ISNULL(LINK_VKR,@OLD_KBK_LINK) = @OLD_KBK_LINK
		AND @DATE <= PERIOD_BEGIN -- Сформированные после смены КБК
		AND LINK_DEP = @DEP_LINK
		AND PERS_LINK IS NOT NULL

	ALTER TABLE [dbo].[CALCULATE_JURNAL]
		ENABLE  TRIGGER ALL		

END

--
UPDATE dbo.SAL_SFIN SET LINK_CH_SFIN = @NEW_KBK_LINK, DATE_CHANGE = @DATE, USED = 0 WHERE LINK = @OLD_KBK_LINK 

--ВЕРНУТЬ ПРЕЖНИЙ ПЕРИОД РЕДАКТИРОВАНИЯ

SELECT @BB = BEGINDATE, @BE = ENDDATE FROM #TMP_DATES
EXECUTE DBO.I_SET_ADMIN_DATE @KASSA, @BB, @BB, @BE


RETURN 0



GO


GRANT EXECUTE ON dbo.[SAL_CHANGE_KBK] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_N_BOL_FILL3]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_N_BOL_FILL3]

GO

CREATE PROCEDURE [dbo].SA_N_BOL_FILL3 
(
 @LINK_DOC INT OUTPUT, --Ссылка на документ.	
 @LINK_ARCH INT, --Ссылка на больничный
 @LINK_PAYS INT = NULL, --Ссылка на вид начисления
 @TYP_PERIOD TINYINT = 3, --Тип расчетного периода: 1- по текущему месяцу, 2- по двум предыдущим, 3- по 12 предудущим месяцам
 @LIMIT TINYINT = 3,--Тип предела: 1- 2 тарифа, 2- 1 МРОТ, 3- по установленному значению, 4 - без ограничений
 @RECALC TINYINT = 0, -- 0 Полный расчет. расчет начинается с таблицы 3 
			-- 1 - не надо рассчитывать по видам начислений
			-- 2 - не надо рассчитывать по месяцам
			-- 3 - не надо рассчитывать средние суммы
 @OPER TINYINT = 0, -- 1 - сформировать операции
 @LINK_DEP INT = NULL
)
AS

SET NOCOUNT ON

DECLARE
 @LINK_EMPL INT, --Ссылка на сотрудника
 @DATE_BEGIN DATETIME, --Начало больничного
 @DATE_BEGIN_P DATETIME, --Начало больничного
 @DATE_END DATETIME, --Окончание больничного
 @REF_TYP_ARHE INT, --Ссылка на вид больничного
 @STAGE_Y INT, --Стаж
 @STAGE_M INT, --Стаж
 @comment varchar(100),
 @extension_DIS int,
 @dekret tinyint
 
DECLARE @UNAME VARCHAR(30)
SET @UNAME = CASE WHEN DBO.SA_GET_OPTION_BY_CODE('SALARY_OPTIONS_OPT10') = 1 THEN ISNULL(dbo.AdminGetUserFIO(default),'') ELSE '' END
SET @UNAME = @UNAME + CASE WHEN LEN(@UNAME) > 0 THEN ':' ELSE '' END

---инит
SELECT @LINK_EMPL = REF_EMPL, @LINK_PAYS = ISNULL(@LINK_PAYS,LINK_PAYS), @DATE_BEGIN = DATE1, @DATE_END = DATEADD(day,DAYS-1, DATE1),
	@REF_TYP_ARHE = REF_TYP_ARHE,  @STAGE_Y = NEPR_YEAR,  @STAGE_M = NEPR_MONTH,
	@comment = @UNAME + 'Начисление по Б/Л:' + ISNULL(dbo.sd_GetEmplName(@LINK_EMPL),'') + ',' + LEFT(RTRIM(LTRIM([NAME_TYP_ARHE])),30) + ' №'+RTRIM(LTRIM([NUMBER])) + ' от ' + CONVERT(VARCHAR(10),[DATE],104),
	@extension_DIS = REF_DOC, @dekret = ISNULL(D.DEKRET,0),
	@LINK_DEP = ISNULL(@LINK_DEP,LINK_DEP)
FROM dbo.DIS D 
WHERE D.LINK = @LINK_ARCH

---
DECLARE 
 @SystPay INT,
 @RP INT, --Размер расчетного периода 
 @DATE_BEGIN_RP DATETIME, --Начало расчетного периода
 @DATE_END_RP DATETIME, --Конец расчетного периода
 @DATE_BEGIN_WRK DATETIME, --Дата приема сотрудника
 @DATE_END_WRK DATETIME, --Дата увольнения сотрудника
 @LINK_PERS INT, --Ссылка на физ.лицо
 @DEP_LINK INT,
 @MAX_DATE DATETIME,
 @I INT,
 @varKSsoLink INT,
 @UCHET_PREM TINYINT	

SET @TYP_PERIOD = 4 --За 2 года

-- Проверка на продолжение больничного листа
DECLARE @varKSRefDoc int
SET @varKSRefDoc = ISNULL((SELECT TOP 1 FIRST_LINK FROM dbo.DIS_FIRST WHERE LINK = @LINK_ARCH),@LINK_ARCH)

SET @DATE_BEGIN_P = ISNULL((SELECT TOP 1 DATE1 FROM dbo.DIS WHERE LINK = @varKSRefDoc),@DATE_BEGIN)

SET @RP = 2
---Определение расчетного периода
DECLARE @NUMBER VARCHAR(10), @DATE_DOC DATETIME

SELECT 
	@DATE_BEGIN_RP = dbo.DateBeginOfYear(DATE_BEGIN), 
	@DATE_DOC = D.[DATE],
	@LINK_DEP = D.LINK_DEP,
	@NUMBER = D.NUMBER
FROM
	DBO.SDOC D 
	INNER JOIN dbo.sdoc_adis SD ON SD.LINK_UP = D.LINK
WHERE 
	D.LINK = @LINK_DOC
	
IF ISNULL(@LINK_DOC,0)  = 0
BEGIN
	exec dbo.SALARY_NEXT_NUM @NUMBER OUT, 'DOCUMENTS_ADD_ARCHE'
	SET @DATE_DOC = (Select top 1 WORKDATE from dbo.USER_DATES)
END	

IF @DATE_BEGIN_RP IS NULL OR YEAR(@DATE_BEGIN_RP) >= YEAR(@DATE_BEGIN_P) - @RP
	SET @DATE_BEGIN_RP = dbo.ConvertDMY2Date(1,1,YEAR(@DATE_BEGIN_P)- @RP)

SET @DATE_END_RP = dbo.ConvertDMY2Date(31,12,YEAR(@DATE_BEGIN_RP) + (@RP-1))

---Учитываем заданные года для расчетного периода
DECLARE @YEAR1 INT, @YEAR2 INT, @YEAR_M INT
SELECT TOP 1 @YEAR1 = YEAR1, @YEAR2 = YEAR2 FROM dbo.DIS D INNER JOIN dbo.VAC_PERIOD_CHANGE C ON C.LINK_EMPL = D.REF_EMPL
WHERE D.LINK = @LINK_ARCH AND D.DATE1 BETWEEN C.DATE1 AND C.DATE2

IF ISNULL(@YEAR1,0) > 0 OR ISNULL(@YEAR2,0) > 0
BEGIN

	SET @YEAR_M = (CASE WHEN ISNULL(@YEAR1,0) > ISNULL(@YEAR2,0) THEN ISNULL(@YEAR1,0) ELSE ISNULL(@YEAR2,0) END)
	SET @YEAR1 = (CASE WHEN ISNULL(@YEAR1,0) <= ISNULL(@YEAR2,0) THEN ISNULL(@YEAR1,0) ELSE ISNULL(@YEAR2,0) END)
	SET @YEAR2 = @YEAR_M

	SET @DATE_BEGIN_RP = dbo.ConvertDMY2Date(1,1,@YEAR1)
	SET @DATE_END_RP = dbo.ConvertDMY2Date(31,12,@YEAR2)

END	
ELSE
BEGIN
	SET @YEAR1 = YEAR(@DATE_BEGIN_RP)
	SET @YEAR2 = YEAR(@DATE_END_RP)
END	
-----------------------------------------------------------------

SELECT TOP 1 @LINK_PERS = PERS_LINK,  @SystPay = SYST_PAY, @DEP_LINK = ISNULL(@DEP_LINK,DEP_LINK)
FROM dbo.EMPL WHERE LINK = @LINK_EMPL

--Количество ставок на начало больничного
DECLARE @EmplNumStake NUMERIC(5,2), @DEFAULT_KBK INT
SELECT @EmplNumStake = num_stake, @DEFAULT_KBK = LINK_KBK FROM dbo.SA_EMPLS_INFO(@DATE_BEGIN_P,@LINK_EMPL)
SET @DEFAULT_KBK = ISNULL((SELECT CH.NEW_LINK FROM dbo.SAL_SFIN_CHANGES(@DATE_BEGIN) CH WHERE CH.LINK = @DEFAULT_KBK),@DEFAULT_KBK)

 --если страховой стаж работника менее 6 месяцев, то предел ус-танавливается в размере 1 МРОТ
IF @STAGE_Y < 1 AND @STAGE_M < 6 
	SET @LIMIT = 2

--- Сохранить параметры расчёта
SELECT @varKSsoLink = LINK FROM dbo.s_objects  WHERE CODE = 'DOCUMENTS_ADD_ARCHE'

EXECUTE dbo.SALARY_UPD_SDOC @LINK_DOC OUTPUT, @varKSsoLink, @NUMBER,@DATE_DOC,@comment,0,null,0, @LINK_DEP

IF not exists(select link_up from dbo.sdoc_adis  where link_up =@LINK_DOC)
		INSERT INTO dbo.sdoc_adis WITH (ROWLOCK) (LINK_UP,LINK_EMPL,LINK_PAY,DATE_BEGIN,SR_ZAR,SR_PREM,TYP_PERIOD,LIMIT,REF_DOC)
		VALUES (@LINK_DOC, @LINK_EMPL,@LINK_PAYS,@DATE_BEGIN_RP,0,0,@TYP_PERIOD,@LIMIT,@LINK_ARCH)
ELSE
		UPDATE dbo.sdoc_adis WITH (ROWLOCK) 
		SET 	LINK_EMPL=@LINK_EMPL, LINK_PAY=@LINK_PAYS, DATE_BEGIN=@DATE_BEGIN_RP, 
				SR_PREM=0, TYP_PERIOD=@TYP_PERIOD, LIMIT=@LIMIT, REF_DOC=@LINK_ARCH
		WHERE LINK_UP=@LINK_DOC

---------------------------------------------------------------------------------------
--Ограничивать количество оплачиваемых дней в каленарном году
DECLARE @ARCHE_OPT9 TINYINT
SET @ARCHE_OPT9 = dbo.sa_get_option_by_code('ARCHE_OPT9')

-- Больной член семьи по этому больничному
DECLARE @LINK_DIS_PERSON INT 

--Ограничения по количеству оплачиваемых дней по данному больничному
IF @ARCHE_OPT9 = 1 BEGIN

	SELECT @LINK_DIS_PERSON = ISNULL(REF_PERS_KID, @LINK_PERS) FROM dbo.SDOC_DIS WHERE LINK_UP = @LINK_ARCH

	DECLARE @MAX_DAYS INT, @MAX_DAYS_IVENT INT, @SUM_DAYS INT
	SELECT 
		  @MAX_DAYS = N.MAX_DAYS, 
		  @MAX_DAYS_IVENT = N.MAX_DAYS_IVENT,
		  @SUM_DAYS = ISNULL(
			( --Вычисляем количество дней больничных, за которые начислили больничные
			SELECT SUM(DAYS)
			FROM
			(	SELECT T.DATE1, [DAYS] = MAX(T.[DAYS])
				FROM
					dbo.SDOC D
					INNER JOIN dbo.SDOC_ADIS A ON D.LINK = A.LINK_UP
					INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON T.LINK_UP = D.LINK
					INNER JOIN dbo.SDOC_DIS SD ON A.REF_DOC = SD.LINK_UP AND A.LINK_EMPL = SD.LINK_EMPL
				WHERE
					SD.[TYPE] = N.LINK
					AND YEAR(@DATE_DOC) BETWEEN YEAR(T.DATE1) AND YEAR(T.DATE2)
					AND SD.LINK_EMPL = @LINK_EMPL
					AND ISNULL(SD.REF_PERS_KID, @LINK_PERS) = @LINK_DIS_PERSON
					AND SD.LINK_UP <> @LINK_ARCH --Данный больничный не учитываем
					AND SD.DATE1 <= @DATE_BEGIN --Проверяем только по предыдущим больничным
				GROUP BY T.DATE1
				) D
			)
			,0)
	FROM 
			dbo.NETRUD N
	WHERE
		  N.LINK = @REF_TYP_ARHE
		  AND @ARCHE_OPT9 = 1
END	

SELECT @MAX_DAYS = ISNULL(@MAX_DAYS,9999), @MAX_DAYS_IVENT = ISNULL(@MAX_DAYS_IVENT,9999), @SUM_DAYS = ISNULL(@SUM_DAYS,0)

--Столько осталось оплатить
SET @MAX_DAYS = (CASE WHEN @MAX_DAYS > @SUM_DAYS THEN @MAX_DAYS - @SUM_DAYS ELSE 0 END)
--Можно оплатить столько дней
SET @MAX_DAYS_IVENT = (CASE WHEN @MAX_DAYS_IVENT < @MAX_DAYS THEN @MAX_DAYS_IVENT ELSE @MAX_DAYS END)
-----------------------------------------------------------------------------------

---Определение процента оплаты по стажу
DECLARE @RercStag NUMERIC(18,2)

SELECT TOP 1 
	@RercStag = P 
FROM 
	dbo.DOCUMENTS_ADD_ARCH_SPR1 SPR1 
WHERE 
	@DATE_BEGIN BETWEEN SPR1.DATE_BEGIN AND SPR1.DATE_END
	AND @STAGE_Y BETWEEN SPR1.STAGE1 AND SPR1.STAGE2

DECLARE
	@PERCENT numeric(18,2), --Процент оплаты
	@Opt  tinyint, -- 1 - учитывать настройки справочника, 0 - нет
	@Stag  tinyint, -- 1 за первые N дней учитывать проценты по стажу, 0 - использовать указанй процент Perc1
	@Stag2  tinyint, -- 1 за последующие дни учитывать проценты по стажу, 0 - использовать указанй процент Perc2
	@Day1g  INT, --- количество первых дней, которые оплачивается Perc1
	@Perc1  numeric(18,2),
	@Perc2  numeric(18,2),
	@Day2_Payer  tinyint -- 0 - Первые два дня больничного оплачивает ФСС, 1 - Первые два дня больничного оплачивает Работодатель

SELECT @Stag = ISNULL(stag,0), @Stag2 = ISNULL(stag2,0), @Day2_Payer = (CASE WHEN ISNULL(@extension_DIS,0) = 0 THEN ISNULL(day2_payer,0) ELSE 0 END), 
	@Opt = ISNULL(opt,0), @Perc1 = ISNULL(perc1,0), @Perc2 = ISNULL(perc2,0),
	@Day1g = (CASE WHEN ISNULL(day1,0) = 1 THEN 0 ELSE ISNULL(day1,0) END) 
FROM DBO.KD_NETRUD where link = @REF_TYP_ARHE

IF @RECALC = 0  --- Расчет сумм по видам начислений
BEGIN
	--- Промежуточная база расчета
	CREATE TABLE #BASE1 (
		PERIOD DATETIME,
		CODE_PAY VARCHAR(254),
		NAME_PAY VARCHAR(254), 
		WAY_CALC INT,
		LINK_PAY INT,
		SUMMA NUMERIC(18,2),
		KOEF  NUMERIC(18,2),
		LINK_INC INT,
		LINK_VKR INT,
		DATE1 DATETIME,
		DATE2 DATETIME
	)

	DECLARE @Cur1 CURSOR, @CUR_EPML INT
	DECLARE @Cur2 CURSOR, @M INT, @Y INT, @PER DATETIME

	DECLARE @ARCHE_OPT4 TINYINT
	SET @ARCHE_OPT4 = dbo.sa_get_option_by_code('ARCHE_OPT4')

	SET @Cur1 = CURSOR FORWARD_ONLY
	FOR SELECT DISTINCT LINK FROM dbo.EMPL E-- INNER JOIN dbo.EMPL_STATUS(@DATE_BEGIN) S on E.link = S.empl_link --AND STATUS <= 2
		WHERE DEP_LINK = @LINK_DEP AND (@ARCHE_OPT4 = 1 AND PERS_LINK = @LINK_PERS) OR (@ARCHE_OPT4 = 0 AND E.link = @LINK_EMPL)

	OPEN @Cur1
	FETCH NEXT FROM @Cur1 INTO @CUR_EPML
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN
			
			SET @Cur2 = CURSOR FORWARD_ONLY
			FOR SELECT m, y, DATE_BEGIN FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2
			OPEN @Cur2
			FETCH NEXT FROM @Cur2 INTO @M, @Y, @PER
			WHILE (@@fetch_status <> -1)
			BEGIN
				IF (@@fetch_status <> -2)
				BEGIN
			
				INSERT INTO #BASE1 (CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, SUMMA, KOEF, LINK_INC, LINK_VKR, DATE1, DATE2)
				exec dbo.SALARY_BASE_SUM_PAY_MONTH_DIF_PERIODS @LINK_PAYS, @CUR_EPML, @M, @Y			
				
				UPDATE #BASE1 SET PERIOD = @PER WHERE PERIOD IS NULL
				UPDATE #BASE1 SET LINK_VKR = @DEFAULT_KBK WHERE LINK_VKR IS NULL
			
				END
				FETCH NEXT FROM @Cur2 INTO @M, @Y, @PER
			END
		
			CLOSE @Cur2
			DEALLOCATE @Cur2

		END
		FETCH NEXT FROM @Cur1 INTO @CUR_EPML
	END
	
	CLOSE @Cur1 
	DEALLOCATE @Cur1

	INSERT INTO #BASE1 (PERIOD, CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, SUMMA, KOEF, LINK_INC, LINK_VKR, DATE1, DATE2)
	SELECT dbo.ConvertDMY2Date(01,12,YEAR_SAL), '---', 'Заработок у других работодателей', 1, 0, SUMMA, 1, 0, @DEFAULT_KBK, dbo.ConvertDMY2Date(01,12,YEAR_SAL), dbo.ConvertDMY2Date(31,12,YEAR_SAL)  
	FROM [dbo].[SAL_OTHER_DEP] 
	WHERE ACTIVE = 1 AND YEAR_SAL IN (@YEAR1,@YEAR2) AND LINK_EMPL = @LINK_EMPL 

	/*Заменяем источники финансирования в базовых начислениях с учетом истории изменений источников*/
	UPDATE B SET B.LINK_VKR = CH.NEW_LINK
	FROM #BASE1 B INNER JOIN dbo.SAL_SFIN_CHANGES(@DATE_BEGIN) CH ON CH.LINK = B.LINK_VKR

	--- Определим, делать ли расчет в разрезе КБК
	DECLARE @ARCHE_OPT5 TINYINT
	SET @ARCHE_OPT5 = dbo.sa_get_option_by_code('ARCHE_OPT5')

	--
	Select 
		PERIOD = dbo.ConvertDMY2Date(31,12,YEAR(MIN(PERIOD))), PERIOD1 = YEAR(PERIOD), CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, 
		SUMMA = SUM( CASE WHEN WAY_CALC = 6 AND (DATEDIFF(MONTH,DATE1, DATE2) + 1) <> 0 AND @UCHET_PREM = 1 THEN 
					CONVERT(NUMERIC(18,2), SUMMA * 
						(
							(DATEDIFF(MONTH,CASE WHEN DATE1 <= dbo.ConvertDMY2Date(1,1,@YEAR1) THEN dbo.ConvertDMY2Date(1,1,@YEAR1) ELSE DATE1 END,
								CASE WHEN DATE2 >= dbo.ConvertDMY2Date(31,12,@YEAR1) THEN dbo.ConvertDMY2Date(31,12,@YEAR1) ELSE DATE2 END) + 1)
						+	CASE WHEN @YEAR1 <> @YEAR2 THEN
								(DATEDIFF(MONTH,CASE WHEN DATE1 <= dbo.ConvertDMY2Date(1,1,@YEAR2) THEN dbo.ConvertDMY2Date(1,1,@YEAR2) ELSE DATE1 END,
									CASE WHEN DATE2 >= dbo.ConvertDMY2Date(31,12,@YEAR2) THEN dbo.ConvertDMY2Date(31,12,@YEAR2) ELSE DATE2 END) + 1)								
							ELSE 0 END
						)
						/ (DATEDIFF(MONTH,DATE1, DATE2) + 1))
				ELSE SUMMA END),
		KOEF, LINK_INC, LINK_VKR = (CASE WHEN @ARCHE_OPT5 = 1 then LINK_VKR else @DEFAULT_KBK end)
	INTO #BASE
	from #BASE1 
	group by YEAR(PERIOD), CODE_PAY, NAME_PAY, WAY_CALC, LINK_PAY, KOEF, LINK_INC, (CASE WHEN @ARCHE_OPT5 = 1 then LINK_VKR else @DEFAULT_KBK end)

	-- Перевернем таблицу 
	DECLARE @PAYS_MONTS VARCHAR(100)
	EXEC X_GET_TABLE_NAME @PAYS_MONTS OUTPUT

	---
	EXEC M_CROSS_TABLE
		'LINK_PAY, LINK_VKR',
		'PERIOD1', 'INT',
		'SUMMA', 'NUMERIC(18,2)', 'SUM(SUMMA) AS SUMMA',
		'#BASE', @PAYS_MONTS

	DELETE FROM dbo.SDOC_ADIS_TABLE3  WHERE LINK_UP = @LINK_DOC

	DECLARE @SCRIPT VARCHAR(8000)
	
	SET @SCRIPT = ' INSERT INTO dbo.SDOC_ADIS_TABLE3 (LINK_UP, ORDERS, LINK_PAY, LINK_KBK, SUMMA1, SUMMA2)'  
			+ ' Select ' + CONVERT(VARCHAR(20),@LINK_DOC) + ', 0, LINK_PAY, LINK_VKR'  
			+ CASE WHEN EXISTS (SELECT * from #BASE WHERE YEAR(PERIOD) = @YEAR1 )
			THEN ', ISNULL(SUMMA_' 
				+ CONVERT(VARCHAR(10),(Select  COUNT(DISTINCT YEAR(PERIOD)) FROM #BASE WHERE YEAR(PERIOD) <= @YEAR1 ))
				+ ',0)' ELSE ',0' END
			+ CASE WHEN @YEAR1 <> @YEAR2 AND EXISTS (SELECT * from #BASE WHERE YEAR(PERIOD) = @YEAR2 )
			THEN ', ISNULL(SUMMA_' 
				+ CONVERT(VARCHAR(10),(Select  COUNT(DISTINCT YEAR(PERIOD)) FROM #BASE WHERE YEAR(PERIOD) <= @YEAR2 ))
				+ ',0)' ELSE ',0' END
		+ ' from ' + @PAYS_MONTS

	EXEC  (@SCRIPT)

	SET @I = 0
	UPDATE dbo.SDOC_ADIS_TABLE3  
	SET @I = @I+1, ORDERS = @I
	WHERE LINK_UP = @LINK_DOC
	
END -- IF @RECALC = 0

-- Время
DECLARE @WTIME1 TABLE(M INT, Y INT, [DAYS] NUMERIC(18,2))
DECLARE @WTIME TABLE(Y INT, [DAYS] NUMERIC(18,2))

INSERT INTO @WTIME1 (M,Y,[DAYS])
SELECT m,y, 
	CASE WHEN @TYP_PERIOD > 1 THEN 
		ISNULL(CONVERT(NUMERIC(4,0),dbo.SA_CALENDAR_DAYS3_FN(@LINK_EMPL,M,Y)),0)
	ELSE DATEDIFF(DAY,@DATE_BEGIN_RP, @DATE_END_RP)+1 END
FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2

--Если нет календарных дней, считаем календарное в году
IF NOT EXISTS (SELECT * FROM @WTIME1 WHERE [DAYS] > 0)
	INSERT INTO @WTIME1 (Y,M,[DAYS])
	SELECT 
		Y, M, DAY(dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,m,y)))
	FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2

DECLARE @DAYS2YEAR INT
SET @DAYS2YEAR = ISNULL((SELECT SUM(DAY(dbo.DateEndOfMonth(dbo.ConvertDMY2Date(1,m,y)))) FROM dbo.months_ex(@DATE_BEGIN_RP, @DATE_END_RP) WHERE Y = @YEAR1 OR Y = @YEAR2 ),730)

--
INSERT INTO @WTIME (Y,[DAYS])
SELECT Y, SUM([DAYS]) FROM @WTIME1 GROUP BY Y

--
IF @RECALC < = 1 --- Расчет сумм по месяцам
BEGIN
	-- Расчет отработанного времени для каждого отрезочка времени
	---

	DECLARE @TABLE2 TABLE (Y INT, M INT, LINK_KBK INT, SUMMA_ZP NUMERIC(18,2), SUMMA_PR NUMERIC(18,2), [DAYS] INT, [HOURS] NUMERIC(18,2), DAYS_NORM INT, HOURS_NORM NUMERIC(18,2))
	INSERT INTO @TABLE2
	SELECT
		Y = T.Y,
		M = 12,
		ISNULL(B.LINK_KBK,@DEFAULT_KBK),
		SUMMA_ZP = SUM(SUMMA),
		SUMMA_PR = 0,
		ISNULL((SELECT SUM([DAYS]) FROM @WTIME T1 WHERE T1.Y = T.Y),0),
		0,0,0
	FROM 
		@WTIME T LEFT JOIN
		(
		Select PERIOD = dbo.DateEndOfYear(@DATE_BEGIN_RP), LINK_PAY, LINK_KBK, 
			DATE1 = dbo.DateBeginOfYear(@DATE_BEGIN_RP), 
			DATE2 = dbo.DateEndOfYear(@DATE_BEGIN_RP),	
			SUMMA = T3.SUMMA1 
		FROM dbo.SDOC_ADIS_TABLE3 T3  WHERE LINK_UP = @LINK_DOC AND ISNULL(T3.SUMMA1,0) <> 0
	UNION ALL 
		Select PERIOD = dbo.DateEndOfYear(@DATE_END_RP), LINK_PAY, LINK_KBK, 
			DATE1 = dbo.DateBeginOfYear(@DATE_END_RP), 
			DATE2 = dbo.DateEndOfYear(@DATE_END_RP),	
			SUMMA = T3.SUMMA2  
		FROM dbo.SDOC_ADIS_TABLE3 T3  WHERE LINK_UP = @LINK_DOC AND ISNULL(T3.SUMMA2,0) <> 0
	) AS B ON T.Y = YEAR(B.PERIOD)
	GROUP BY
		T.Y, B.LINK_KBK

	----
	DECLARE @LINK_PAY_FSS INT	
	SET @LINK_PAY_FSS = (SELECT TOP 1 LINK FROM dbo.PAYS WHERE [OBJECT] = 3 AND WAY_CALC = 2)

	----
	UPDATE @TABLE2
	SET SUMMA_PR = 
		(
			SELECT MAX(PREDEL) FROM dbo.DICTIONARY_RANGE D
			WHERE LINK_PAYS = @LINK_PAY_FSS 
					AND TARIF = 1 
					AND [PERCENT] > 0 
					AND [DATE] = (SELECT TOP 1 [DATE] 
										FROM dbo.DICTIONARY_RANGE D1 
										WHERE D1.TARIF = D.TARIF 
												AND D1.LINK_PAYS = D.LINK_PAYS 
												AND [DATE] <= dbo.ConvertDMY2Date(1,1,(CASE WHEN Y < 2010 THEN 2010 ELSE Y END))
									ORDER BY [DATE] DESC) 
		 )


	DECLARE @CurPR CURSOR, @y1 INT, @m1 INT, @y2 INT, @m2 INT, @link_kbk1 INT, @SUM_KBK NUMERIC(18,2)
	
	SET @CurPR = CURSOR FORWARD_ONLY

	FOR select y, m, link_kbk from @TABLE2 order by y, m
	
	OPEN @CurPR
	FETCH NEXT FROM @CurPR INTO @y1, @m1, @link_kbk1
	WHILE (@@fetch_status <> -1)
	BEGIN
		IF (@@fetch_status <> -2)
		BEGIN

			IF ISNULL(@y2,0) <> ISNULL(@y1,0) OR ISNULL(@m2,0) <> ISNULL(@m1,0)
				SELECT @SUM_KBK = 0, @y2 = @y1, @m2 = @m1

			UPDATE @TABLE2 SET HOURS_NORM = CASE WHEN ISNULL(SUMMA_ZP,0) > ISNULL(SUMMA_PR-@SUM_KBK,0) 
												THEN CASE WHEN ISNULL(SUMMA_PR-@SUM_KBK,0) > 0 THEN ISNULL(SUMMA_PR-@SUM_KBK,0) ELSE 0 END
												ELSE ISNULL(SUMMA_ZP,0) END
			WHERE @y1 = Y AND @m1 = M AND isnull(@link_kbk1,0) = isnull(link_kbk,0)

			SET @SUM_KBK = @SUM_KBK + ISNULL( (SELECT SUMMA = SUMMA_ZP	FROM @TABLE2 WHERE @y1 = Y AND @m1 = M AND isnull(@link_kbk1,0) = isnull(link_kbk,0)),0)

		END
	
		FETCH NEXT FROM @CurPR INTO @y1, @m1, @link_kbk1
	END
	
	CLOSE @CurPR
	DEALLOCATE @CurPR

	UPDATE A
	SET SUMMA_ZP = 
		CASE WHEN (SELECT SUM(B.SUMMA_ZP) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M) > 0 THEN
						A.SUMMA_ZP / (SELECT SUM(B.SUMMA_ZP) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M)
						* (SELECT SUM(B.HOURS_NORM) FROM @TABLE2 B WHERE A.Y = B.Y AND A.M = B.M)
					ELSE 0 END	
	FROM @TABLE2 A

	UPDATE @TABLE2 SET SUMMA_PR = 0, HOURS_NORM = 0

	---
	DELETE FROM dbo.SDOC_ADIS_TABLE2  WHERE LINK_UP = @LINK_DOC
	
	INSERT INTO dbo.SDOC_ADIS_TABLE2 (LINK_UP, ORDERS, PERIOD, SUMMA, SUMMA_PREM, [DAYS], [HOURS], DAYS_N, HOURS_N, LINK_KBK)
	SELECT  @LINK_DOC, 0, dbo.ConvertDMY2Date(1, M, Y), SUMMA_ZP, SUMMA_PR, [DAYS],[HOURS],DAYS_NORM,HOURS_NORM, LINK_KBK
	FROM @TABLE2
	ORDER BY Y, M, LINK_KBK

	SET @I = 0
	UPDATE dbo.SDOC_ADIS_TABLE2  
	SET @I = @I+1, ORDERS = @I
	WHERE LINK_UP = @LINK_DOC
END	--IF @RECALC < = 1

DECLARE @RAION NUMERIC(18,2)
exec dbo.SA_EMPL_RAION_KOEF_BL @RAION OUT, @LINK_EMPL, @DATE_BEGIN

SET @RAION = CASE WHEN ISNULL(@RAION,0) <1 THEN 1 ELSE ISNULL(@RAION,0) END

DECLARE @SUM_LIMIT NUMERIC(18,4), @MINROT NUMERIC(18,2)
SET @MINROT = dbo.minrot2(@DATE_BEGIN) * (CASE WHEN @EmplNumStake <= 1 THEN @EmplNumStake ELSE 1 END) * 24

IF @RECALC < = 2 --- Расчет периодов больничного и определение средних сум
BEGIN		
	---Периоды больничного
	DECLARE
	 @DATE_RAB_END DATETIME,
	 @DATE_B DATETIME,
	 @R int	-- Первые 3 дня за счет работодателя
	
	---
	SELECT @R = @Day2_Payer * 3
	SELECT @DATE_RAB_END = DATEADD(DAY,@R-1,@DATE_BEGIN), @DATE_B = CASE WHEN @R > 0 THEN DATEADD(DAY,@R,@DATE_BEGIN) ELSE @DATE_BEGIN END

	/*Если это продолжение, то за счет работодателя ни чего не оплачивается, предполагается, что первый больничный был не менее 2-х дней*/
	
	---Разбивка периодов на периоды по настройкам оплаты больничного
	DECLARE
	 @DATE_BEGIN1 DATETIME,
	 @DATE_END1 DATETIME 

	--Обработка продолжения б/л
	DECLARE @LINK_BL_OLD INT, @DATE_BEG_OLD DATETIME, @DATE_END_OLD DATETIME
	SET @LINK_BL_OLD = (SELECT TOP 1 REF_DOC FROM dbo.DIS WHERE LINK = @LINK_ARCH)

	/*УЧИТЫВАЕМ, ЧТО ЭТО МОЖЕТ БЫТЬ ПРОДОЛЖЕНИЕМ БОЛЬНИЧНОГО ЛИСТА*/
	--Периоды продолжаемого б/л	
	SELECT @DATE_BEG_OLD = DATE1, @DATE_END_OLD = DATE2 FROM dbo.DIS WHERE LINK = @LINK_BL_OLD
	--расширить периоды за счет других продолжений
	IF EXISTS (SELECT LINK FROM dbo.DIS WHERE REF_DOC = @LINK_BL_OLD AND LINK <> @LINK_ARCH AND DATE1 < @DATE_BEGIN)
		SET @DATE_END_OLD = (SELECT MAX(DATE2) FROM dbo.DIS WHERE REF_DOC = @LINK_BL_OLD AND LINK <> @LINK_ARCH AND DATE1 < @DATE_BEGIN)

	IF @DATE_BEG_OLD IS NOT NULL
	BEGIN
		SET @Day1g = @Day1g - (DATEDIFF(DAY,@DATE_BEG_OLD,@DATE_END_OLD) + 1)
		SET @Day1g = CASE WHEN @Day1g < 0 THEN 0 ELSE @Day1g END
	END

	SET @DATE_END1 = (CASE WHEN DATEADD(DAY,@Day1g-1,@DATE_BEGIN) < @DATE_END THEN DATEADD(DAY,@Day1g-1,@DATE_BEGIN) ELSE @DATE_END END)
	SET @DATE_BEGIN1 = (CASE WHEN @DATE_END1 +1 < @DATE_END THEN @DATE_END1 +1 ELSE @DATE_END END)

	--== ФОРМИРНОВАНИЕ ПЕРИОДОВ ДЛЯ ОПЛАТЫ В РАЗРЕЗЕ ГОДА, МЕСЯЦА, ПЛАТЕЛЬЩИКА И ПРОЦЕНТОВ
	DECLARE @PERIODY TABLE ( ord int identity(1,1), DATE_BEGIN DATETIME, DATE_END DATETIME, R TINYINT, PERC NUMERIC(18,2), DH NUMERIC(18,2), DH_NORM NUMERIC(18,6), I TINYINT, SUM_LIMIT NUMERIC(20,4))
	
	--- 1. Разбивка на периоды по плательщикам и календарным месяцам
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, R, PERC, I)
	--- Определение плательщика
	select 
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_RAB_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_RAB_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 1, PERC = 0.00, 1 --Первое преобразование
	from dbo.months_ex(@DATE_BEGIN, @DATE_RAB_END)
	WHERE @R > 0
	UNION ALL
	select 
		DATE_BEGIN = (CASE WHEN @DATE_B > DATE_BEGIN THEN @DATE_B ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = 0.00, 1
	from dbo.months_ex(@DATE_B, @DATE_END)
	UNION
	--- Определение процента в зависимости от настроек больничного
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END1 < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END1 ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = CASE WHEN @Stag = 0 THEN @Perc1 ELSE @RercStag END, 1
	from dbo.months_ex(@DATE_BEGIN, @DATE_END1 )
	WHERE 	ISNULL(@OPT,0) = 1 
	UNION ALL
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN1 > DATE_BEGIN THEN @DATE_BEGIN1 ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = CASE WHEN @Stag2 = 0 THEN @Perc2 ELSE @RercStag END, 1
	from dbo.months_ex(@DATE_BEGIN1, @DATE_END )
	WHERE 	ISNULL(@OPT,0) = 1
	ORDER BY DATE_BEGIN, DATE_END

	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, R, PERC, I)
	--- Установка процента, если настройки не заданы
	SELECT  
		DATE_BEGIN = (CASE WHEN @DATE_BEGIN > DATE_BEGIN THEN @DATE_BEGIN ELSE DATE_BEGIN END), 
		DATE_END = (CASE WHEN @DATE_END < dbo.DateEndOfMonth(DATE_BEGIN) THEN @DATE_END ELSE dbo.DateEndOfMonth(DATE_BEGIN) END),
		P = 0, PERC = @RercStag, 1
	from dbo.months_ex(@DATE_BEGIN, @DATE_END )
	WHERE 	ISNULL(@OPT,0) = 0 
	ORDER BY DATE_BEGIN, DATE_END

	--- 2. Все границы периодов
	DECLARE @PERIODY1 TABLE (ORD INT IDENTITY(1,1), PER DATETIME)
	INSERT INTO @PERIODY1 (PER)
	SELECT PER FROM (SELECT PER = DATE_BEGIN FROM @PERIODY UNION SELECT PER = DATE_END FROM @PERIODY) as P
	UNION ALL 
	SELECT PER FROM (SELECT PER = DATE_BEGIN FROM @PERIODY UNION SELECT PER = DATE_END FROM @PERIODY) as P
	WHERE PER = dbo.DateEndOfMonth(PER)
	ORDER BY PER	

	--- 3.Получение отрезков времени со сдвинутыми датами начала
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I)
	SELECT 
		(CASE WHEN P1.PER = @DATE_BEGIN OR P1.PER = @DATE_END THEN P1.PER ELSE P1.PER + 1 END),
		ISNULL(P2.PER,P1.PER),
		2  --второе преобразование
	FROM 
		@PERIODY1 P1 LEFT JOIN @PERIODY1 P2 ON P1.ORD = P2.ORD - 1

	---Корректировка
	UPDATE @PERIODY
	SET DATE_BEGIN  = DATE_BEGIN + 1
	WHERE I = 2 AND DATE_BEGIN <> DATE_END AND DATE_BEGIN = dbo.DateEndOfMonth(DATE_BEGIN)

	--- 4. Исключение перекрывающихся периодов
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I)
	SELECT AP.DATE_BEGIN, AP.DATE_END, 3 FROM @PERIODY AP
	WHERE AP.I = 2 AND NOT EXISTS (SELECT * FROM @PERIODY AP1 WHERE AP1.I = 2 AND AP.DATE_BEGIN > AP1.DATE_BEGIN AND AP.DATE_END <= AP1.DATE_END)

	-- Особый случай, когда боьничный один день
	IF @DATE_BEGIN = @DATE_END 
		UPDATE @PERIODY SET DATE_BEGIN = @DATE_BEGIN, DATE_END = @DATE_END
		WHERE DATE_END >= @DATE_BEGIN

	--- 5. Расстановка плательщика и процентов по периодам
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I, R, PERC)
	Select 
		P3.DATE_BEGIN, P3.DATE_END, 4,
		R =  ISNULL((SELECT TOP 1 P1.R FROM @PERIODY P1 WHERE I = 1 AND P1.R = 1 AND (P3.DATE_BEGIN BETWEEN P1.DATE_BEGIN AND P1.DATE_END) AND (P3.DATE_END BETWEEN P1.DATE_BEGIN AND P1.DATE_END)  order by ord),0),
		PERC = ISNULL((SELECT TOP 1 P1.PERC FROM @PERIODY P1 WHERE I = 1 AND P1.PERC > 0 AND (P3.DATE_BEGIN BETWEEN P1.DATE_BEGIN AND P1.DATE_END) AND (P3.DATE_END BETWEEN P1.DATE_BEGIN AND P1.DATE_END) order by ord),0)
	FROM @PERIODY P3 
	WHERE P3.I = 3 
	
	--- 6. Соединение периодов
	INSERT INTO @PERIODY (DATE_BEGIN, DATE_END, I, R, PERC)
	Select 
		MIN(DATE_BEGIN), MAX(DATE_END), 5, R, PERC
	FROM @PERIODY P4 
	WHERE P4.I = 4 
	GROUP BY YEAR(DATE_BEGIN), MONTH(DATE_BEGIN), R, PERC
	
	DECLARE @ARCHE_OPT13 INT --Не начисять суммы за счёт ФСС 
	SET @ARCHE_OPT13 = dbo.SA_GET_OPTION_BY_CODE('ARCHE_OPT13')
	IF @ARCHE_OPT13 = 1
		DELETE FROM @PERIODY WHERE I = 5 AND R = 0
	
	--== ПОЛУЧЕНИЕ ПЕРИОДОВ ЗАВЕРШЕНО!
	
	---Определение предела

	-- увеличенный на размер районного коэффициента
	--Сумма МРОТ должна быть в пределах количества ставок, т.к. по ней идет расчет за полностью отработанное время на полной ставке

	DECLARE @LINK_FSS INT, @MAX_SUM_FSS NUMERIC(18,2)
	SET @LINK_FSS = (SELECT TOP 1 LINK FROM dbo.PAYS WHERE [OBJECT] = 3 AND WAY_CALC = 2)
	
	DECLARE @T_MAX_SUM_FSS TABLE (SUMMA NUMERIC(18,2))

	----
	INSERT INTO @T_MAX_SUM_FSS (SUMMA)
	SELECT MAX_SUM_FSS = 
				(
					SELECT MAX(PREDEL) FROM dbo.DICTIONARY_RANGE D
					WHERE LINK_PAYS = @LINK_FSS 
							AND TARIF = 1 
							AND [PERCENT] > 0 
							AND [DATE] = (SELECT TOP 1 [DATE] 
												FROM dbo.DICTIONARY_RANGE D1 
												WHERE D1.TARIF = D.TARIF 
														AND D1.LINK_PAYS = D.LINK_PAYS 
														AND [DATE] <= dbo.ConvertDMY2Date(1,1,(CASE WHEN Y < 2010 THEN 2010 ELSE Y END))
											ORDER BY [DATE] DESC) 
				 )
	FROM 
		@WTIME T
		
	SET @MAX_SUM_FSS = (SELECT SUM(SUMMA) FROM @T_MAX_SUM_FSS)
		--(SELECT SUM(SUMMA)/(12*COUNT(*)) FROM @T_MAX_SUM_FSS)
	IF ISNULL(@MAX_SUM_FSS,0) = 0
		SET @MAX_SUM_FSS = dbo.sa_get_option_by_code('ARCHE_OPT1')

	DECLARE @D NUMERIC(18,6)
	SET @D = ISNULL((SELECT SUM([DAYS]) FROM 
			(SELECT PERIOD, MAX([DAYS]) AS DAYS FROM dbo.SDOC_ADIS_TABLE2 WHERE LINK_UP = @LINK_DOC	GROUP BY PERIOD) T
		),0)

	IF @D = 0 SET @D = 730--@DAYS2YEAR

	----
	UPDATE @PERIODY
	SET 

		DH = DATEDIFF(DAY,DATE_BEGIN, DATE_END)+1,
	
		DH_NORM = 
				CASE WHEN DATE_BEGIN <= '20091231' THEN 
					DAY(dbo.DateEndOfMonth(DATE_BEGIN))
				ELSE
					730
				END,			
		SUM_LIMIT = 
				CONVERT(NUMERIC(18,2),
					CASE @LIMIT
					WHEN 2 THEN @MINROT * @RAION -- в размере 1 МРОТ
					WHEN 3 THEN 
						CASE WHEN DATE_BEGIN <= '20091231' THEN 	
							(CASE WHEN @dekret = 0 THEN dbo.sa_get_option_by_code('ARCHE_OPT7') ELSE dbo.sa_get_option_by_code('ARCHE_OPT8') END) * @RAION 
						ELSE	
							-- !!! С 1 января 2010 года максимальный размер пособия одинаковый по все территории РФ!!!: Максимум без учета районныйх, но с учетом стажа
							@MAX_SUM_FSS
						END
					ELSE 0
					END 
				)				
	WHERE I = 5

	---------------------------------------------------------------------------------------
	--Откорректируем оплачиваемые дни за каждый период
	DECLARE @Cur3 CURSOR
	Declare @NEXT_DATE DATETIME

	IF @ARCHE_OPT9 = 1
	BEGIN
		SET @Cur3 = CURSOR FORWARD_ONLY

		FOR SELECT DATE_BEGIN FROM @PERIODY WHERE I = 5 AND YEAR(@DATE_DOC) BETWEEN YEAR(DATE_BEGIN) AND YEAR(DATE_END) ORDER BY DATE_BEGIN
		
		OPEN @Cur3
		FETCH NEXT FROM @Cur3 INTO @NEXT_DATE
		WHILE (@@fetch_status <> -1)
		BEGIN
			IF (@@fetch_status <> -2)
			BEGIN

				UPDATE @PERIODY
				SET DH = (CASE WHEN DH < @MAX_DAYS_IVENT THEN DH ELSE @MAX_DAYS_IVENT END)
				WHERE I = 5 AND DATE_BEGIN = @NEXT_DATE
				
				SELECT @MAX_DAYS_IVENT = (CASE WHEN DH < @MAX_DAYS_IVENT THEN @MAX_DAYS_IVENT - DH ELSE 0 END)
				FROM @PERIODY
				WHERE I = 5 AND DATE_BEGIN = @NEXT_DATE

			END
		
			FETCH NEXT FROM @Cur3 INTO @NEXT_DATE
		END
		
		CLOSE @Cur3
		DEALLOCATE @Cur3
	END	
	---------------------------------------------------------------------------------------

	---
	DECLARE @REP_SUMMA_PR NUMERIC(18,2), @SUMMA_ZP NUMERIC(18,2), @SUMMA_PR NUMERIC(18,2), @NORM NUMERIC(18,2), @WORK NUMERIC(18,2), @SR_ZP NUMERIC(20,4)
	
	SELECT 
		@SUMMA_ZP = ISNULL(SUM(SUMMA),0),
		@SUMMA_PR = 0
	FROM dbo.SDOC_ADIS_TABLE2 WHERE LINK_UP = @LINK_DOC

	----	
	DECLARE @KBK_KOEF TABLE (LINK_KBK INT, KOEF NUMERIC(18,4))
	DECLARE @SR_ZP_R numeric(20,4)

	---	
	SET @SR_ZP = CONVERT(NUMERIC(18,2),ISNULL(@SUMMA_ZP,0) / @D)
	SET @SR_ZP_R = @SR_ZP

	IF ISNULL(@SR_ZP,0) = 0  BEGIN
		DELETE FROM @KBK_KOEF
		INSERT INTO @KBK_KOEF (LINK_KBK, KOEF) 
		SELECT @DEFAULT_KBK, 1
	END 
	ELSE BEGIN
		---
		DECLARE @S NUMERIC(18,2)
		SET @S = ISNULL((SELECT SUM(SUMMA) FROM dbo.SDOC_ADIS_TABLE2 WHERE LINK_UP = @LINK_DOC),0)

		INSERT INTO @KBK_KOEF (LINK_KBK, KOEF) 
		SELECT LINK_KBK, CASE WHEN @S <> 0 THEN SUM(SUMMA) / @S ELSE 0 END 
		FROM dbo.SDOC_ADIS_TABLE2  WHERE LINK_UP = @LINK_DOC 
		GROUP BY LINK_KBK
	END
	---
	DELETE FROM dbo.SDOC_ADIS_TABLE1  WHERE LINK_UP = @LINK_DOC
	INSERT INTO dbo.SDOC_ADIS_TABLE1 (LINK_UP, ORDERS, DATE1, DATE2, SUM_LIMIT, [DAYS], [HOURS], SR_ZP, SUMMA, PERC, PAYER, LINK_KBK, KOEF_KBK)
	SELECT @LINK_DOC, 0, DATE_BEGIN, DATE_END, 
		LIMIT = CONVERT(NUMERIC(20,2), P.SUM_LIMIT / DH_NORM),
		DH,--(CASE WHEN @SystPay = 1 THEN DH ELSE 0 END),
		0,--(CASE WHEN @SystPay = 1 THEN 0 ELSE DH END),
		SR_ZP = NULL,
		0,
		PERC,
		R,
		K.LINK_KBK,
		K.KOEF
	FROM @PERIODY P INNER JOIN @KBK_KOEF K ON 1=1
	WHERE I = 5
	ORDER BY DATE_BEGIN

	UPDATE sdoc_adis WITH (ROWLOCK) 
	SET 	LINK_EMPL = @LINK_EMPL, LINK_PAY=@LINK_PAYS, DATE_BEGIN=@DATE_BEGIN_RP, SR_ZAR=@SR_ZP_R, SR_PREM=@SUMMA_PR, TYP_PERIOD=@TYP_PERIOD, LIMIT=@LIMIT, REF_DOC=@LINK_ARCH, INSTRUCT = 3
	WHERE LINK_UP = @LINK_DOC
	
END --@RECALC <= 2 

DECLARE @ARCHE_OPT10 TINYINT -- Мин. размер пособия при отсутсвии заработка выплачивать с учётом районного коэффицента
SET @ARCHE_OPT10 = dbo.SA_GET_OPTION_BY_CODE('ARCHE_OPT10')

DECLARE @SR_ZP_MINI numeric(20,4)
SET @SR_ZP_MINI = @MINROT * (CASE WHEN @ARCHE_OPT10 = 1 THEN @RAION ELSE 1 END)  / 730--@DAYS2YEAR

SET @SR_ZP = ISNULL((SELECT TOP 1 SR_ZAR FROM dbo.sdoc_adis WHERE LINK_UP = @LINK_DOC),0)
SET @SR_ZP = CASE WHEN @SR_ZP < @SR_ZP_MINI THEN @SR_ZP_MINI ELSE @SR_ZP END

UPDATE dbo.SDOC_ADIS_TABLE1
SET 
	SR_ZP = convert(numeric(20,4),
			(CASE WHEN @SR_ZP < SUM_LIMIT OR @LIMIT = 4 AND @LIMIT <> 2 THEN @SR_ZP ELSE SUM_LIMIT END))
			* convert(numeric(20,4),(CASE WHEN PERC > 0 then PERC/100 else 0 end))
FROM 
	dbo.sdoc_adis A 
	INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON A.LINK_UP = T.LINK_UP
WHERE 
	T.LINK_UP = @LINK_DOC AND KOEF_KBK IS NOT NULL

----
Select CJ.DATE_BEGIN, CJ.DATE_END, CJ.LINK_VKR, DAYS = SUM(CJ.DAYS), HOURS = SUM(CJ.HOURS), LINK_EKR, SUMMA = SUM(SUMMA)
INTO #SUM_OLD
from 
	dbo.SDOC_ADIS SA inner join dbo.CALCULATE_JURNAL CJ on CJ.LINK_DOC = SA.LINK_UP
	inner join dbo.sdoc d on CJ.LINK_DOC = d.link 
where
	ISNULL(@LINK_ARCH,0) > 0
	AND
	SA.REF_DOC = @LINK_ARCH
	and
	d.object = (Select top 1 link from s_objects where code = 'DOCUMENTS_ADD_ARCHE')
GROUP BY
	CJ.DATE_BEGIN, CJ.DATE_END, CJ.LINK_VKR, LINK_EKR

DECLARE @LInkEKR213 int
SELECT @LinkEKR213 = LINK FROM dbo.DICTIONARY_ITEM WHERE CODE = '213'

---- сопоставить старые
UPDATE dbo.SDOC_ADIS_TABLE1
SET 
	SUMMA_NEW = CONVERT(NUMERIC(18,2), T.SR_ZP * T.[DAYS] * KOEF_KBK),--(CASE WHEN @SystPay = 1 THEN T.[DAYS] ELSE T.[HOURS] END) * KOEF_KBK),
	SUMMA_OLD = ISNULL(SO.SUMMA,0),
	DAYS = COALESCE(T.DAYS,0) - COALESCE(SO.DAYS,0), 
	HOURS = COALESCE(T.HOURS,0) - COALESCE(SO.HOURS,0)
FROM 
	dbo.sdoc_adis A 
	INNER JOIN dbo.SDOC_ADIS_TABLE1 T ON A.LINK_UP = T.LINK_UP
	LEFT JOIN #SUM_OLD SO ON T.DATE1 = SO.DATE_BEGIN AND T.DATE2 = SO.DATE_END AND T.LINK_KBK = SO.LINK_VKR and PAYER = (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end)
WHERE 
	T.LINK_UP = @LINK_DOC AND KOEF_KBK IS NOT NULL AND SR_ZP IS NOT NULL

-- добавить старые, которых теперь нет
insert into dbo.SDOC_ADIS_TABLE1 
	(link_up, ORDERS, DATE1, DATE2, SUM_LIMIT, DAYS, HOURS, SUMMA, PERC, SR_ZP, PAYER, LINK_KBK, KOEF_KBK, SUMMA_OLD, SUMMA_NEW)
Select 
	@LINK_DOC, 0, DATE_BEGIN, DATE_END, 0, -DAYS, -HOURS, 0, 0, 0, (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end), LINK_VKR, 1, SO.SUMMA, 0
from 
	#SUM_OLD SO
where 
	NOT EXISTS (Select * from dbo.SDOC_ADIS_TABLE1 T where T.LINK_UP = @LINK_DOC and T.DATE1 = SO.DATE_BEGIN AND T.DATE2 = SO.DATE_END 
		AND T.LINK_KBK = SO.LINK_VKR and PAYER = (CASE WHEN LINK_EKR=@LInkEKR213 then 0 else 1 end))

---- сравнить
UPDATE dbo.SDOC_ADIS_TABLE1
SET SUMMA = ISNULL(SUMMA_NEW,0) - ISNULL(SUMMA_OLD,0)
WHERE LINK_UP = @LINK_DOC

--удалить пустые строки
DELETE FROM dbo.SDOC_ADIS_TABLE1
WHERE LINK_UP = @LINK_DOC AND ISNULL(SUMMA_NEW,0) = 0

SET @I = 0

UPDATE dbo.SDOC_ADIS_TABLE1  
SET @I = @I+1, ORDERS = @I
WHERE LINK_UP = @LINK_DOC

---
DECLARE @SUMMA NUMERIC(18,2)
SELECT @SUMMA = ISNULL((SELECT SUM(SUMMA) FROM dbo.SDOC_ADIS_TABLE1 WHERE LINK_UP = @LINK_DOC),0), @SUMMA_ZP = ISNULL(@SUMMA_ZP,0), @SUMMA_PR = ISNULL(@SUMMA_PR,0)

---
SELECT @NUMBER = NUMBER,  @DATE_DOC = DATE from SDOC WHERE LINK = @LINK_DOC

if exists (select * from #SUM_OLD)
	set @comment = 'Перерасчет: ' + @comment

--- Сохрание расчета
EXECUTE dbo.SALARY_UPD_SDOC @LINK_DOC OUTPUT, @varKSsoLink, @NUMBER,@DATE_DOC,@comment,0,null,@SUMMA

IF @OPER = 1 
	exec dbo.SD_N_BOL_PROV @LINK_DOC

SET NOCOUNT OFF


GO


GRANT EXECUTE ON dbo.[SA_N_BOL_FILL3] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_OKPD_SAVE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_OKPD_SAVE]

GO






/*
© Кейсистемс (Keysystems), 2006
*/




CREATE       PROCEDURE dbo.BB_OKPD_SAVE
	@varKSparLINK	   int	OUTPUT,
	@varKSparCODE	   CHAR(10),
	@varKSparNAME      VARCHAR(254), 
	@varKSparLINK_SELF INT,
	@iUM		   int,
	@bUsed		   bit
AS

DECLARE 	@varKSSQLError	tinyint,
			@varKStrancount	int,
			@varKSEventText	varchar(254),
			@varKSObjLink		int,
			@varKSRowCount 	int 


SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN
	
	SELECT @varKSObjLink = LINK FROM S_OBJECTS WHERE CODE = 'BB_OKPD'
	IF @varKSparLINK is null OR @varKSparLINK = 0
	BEGIN
		INSERT INTO dbo.OKPD WITH (ROWLOCK) (CODE, NAME, LINK_SELF, UM, USED) 
		VALUES (@varKSparCODE, @varKSparNAME, @varKSparLINK_SELF, @iUM, @bUsed)
		SELECT @varKSSQLError = @@ERROR, @varKSparLINK = @@IDENTITY
		IF @varKSSQLError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END
	ELSE
	BEGIN
		UPDATE dbo.OKPD WITH (ROWLOCK) 
		SET 	CODE	  = @varKSparCODE,
			NAME 	  = @varKSparNAME, 
			LINK_SELF = @varKSparLINK_SELF,
			UM	  = @iUM,
			USED 	  = @bUsed
		WHERE LINK =@varKSparLINK
		SELECT @varKSSQLError = @@ERROR, @varKSRowCount = @@ROWCOUNT
		IF @varKSSQLError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
		IF @varKSRowCount = 0
		BEGIN
			ROLLBACK
			RETURN 2
		END
	END	

	
	SET @varKSEventText = 'Справочник Продукция(Услуги)(ОКПД)' + ' ' +  RTRIM(CONVERT(VARCHAR(9),@varKSparCODE))+' '+ RTRIM(CONVERT(VARCHAR(7000), @varKSparNAME))
	EXECUTE WF_GENERATEEVENT 'Сохранение строки справочника', @varKSEventText, @varKSObjLink, 'OKPD', @varKSparLINK

IF @@TRANCOUNT > @varKStrancount
	COMMIT TRAN
RETURN 0












GO


GRANT EXECUTE ON dbo.[BB_OKPD_SAVE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_OKPD_DELETE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_OKPD_DELETE]

GO




/*
© Кейсистемс (Keysystems), 2005
*/


CREATE  PROCEDURE dbo.BB_OKPD_DELETE
	@varKSintLINK	int
AS
DECLARE @varKStrancount	int,
	@varKSObjectLink	int,
	@varKSEventText	varchar(254)

SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN
	SELECT @varKSEventText = 'Справочник Продукция(Услуги)(ОКПД)' + ' ' + CODE + ' ' + NAME FROM dbo.OKPD
	WITH (UPDLOCK) WHERE LINK = @varKSintLINK
	IF @@RowCount = 0 OR @@ERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 2
	END
	DELETE FROM dbo.OKPD WHERE LINK = @varKSintLINK
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 7
	END
IF @@TRANCOUNT > @varKStrancount
	BEGIN
		SELECT @varKSObjectLink = LINK FROM S_OBJECTS WHERE CODE = 'BB_OKPD'
		EXECUTE WF_GENERATEEVENT 'Удаление из справочника', @varKSEventText, @varKSObjectLink, 'OKPD', @varKSintLINK
		COMMIT TRAN
	END
RETURN 0




GO


GRANT EXECUTE ON dbo.[BB_OKPD_DELETE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BV_SAVE_NOMENCLATURE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BV_SAVE_NOMENCLATURE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/


CREATE  PROCEDURE dbo.BV_SAVE_NOMENCLATURE
	@varKSparLINK		INT	OUTPUT,
	@varKSparLINK_GRP	INT = NULL,
	@varKSparCODE		CHAR(20) = NULL,
	@varKSparNAME		VARCHAR(254) = NULL,
	@varKSparSERIES		VARCHAR(30) = NULL,
	@varKSparLINK_UM	INT = NULL,
	@lbIS_EXTRA		BIT = NULL,
	@varKSparLINK_OKDP	INT = NULL,
	@varKSparLINK_OKPD	INT = NULL,
	@nCOEFF			numeric(18,6) = 1,
	@nCOEFF_OKPD	numeric(18,6) = 1,
	@intPRICE_TYPE		TINYINT = 0,
	@intISUSED	TINYINT = 0
	
	
AS
DECLARE @varKSERROR	tinyint,
	@varKSRowCount INT,
	@varKSstrVALUE	varchar(7000),
	@varKStrancount	int,
	@varKSEventText	varchar(254),
	@varKSintObj		int
SET LOCK_TIMEOUT 30000
SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN
	
	IF EXISTS(Select * FROM NOMENCLATURE Where CODE = @varKSparCODE AND LINK <> @varKSparLINK)
	BEGIN
		ROLLBACK
		RETURN 4
	END
	
	IF @varKSparCODE IS NULL OR @varKSparCODE = ''
	BEGIN
		ROLLBACK
		RETURN 5
	END
	IF @varKSparNAME IS NULL OR @varKSparNAME = ''
	BEGIN
		ROLLBACK
		RETURN 5
	END


	IF @varKSparLINK_GRP IS NULL OR @varKSparLINK_GRP = 0
	BEGIN
		ROLLBACK
		RETURN 5
	END

	SET @intISUSED = ISNULL (@intISUSED, 0)

	UPDATE dbo.NOMENCLATURE
	SET 
		CODE = @varKSparCODE,
		[NAME] = @varKSparNAME,
		SERIES = @varKSparSERIES,
		GROUP_INV = @varKSparLINK_GRP,
		UM = @varKSparLINK_UM,
			IS_EXTRA = @lbIS_EXTRA,
		LINK_OKDP = @varKSparLINK_OKDP,
		LINK_OKPD = @varKSparLINK_OKPD,
		COEFF = @nCOEFF,
		COEFF_OKPD = @nCOEFF_OKPD,
		PRICE_TYPE = @intPRICE_TYPE,
		ISUSED = @intISUSED
	WHERE LINK = @varKSparLINK
		
	SELECT @varKSRowCount = @@ROWCOUNT, @varKSERROR = @@ERROR
	IF @varKSERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 7
	END

	IF @varKSRowCount = 0
	BEGIN
		INSERT INTO dbo.NOMENCLATURE   (CODE, [NAME], GROUP_INV, SERIES, UM, IS_EXTRA, LINK_OKDP, COEFF, COEFF_OKPD , PRICE_TYPE, 
			ISUSED, LINK_OKPD)
		VALUES (@varKSparCODE, @varKSparNAME, @varKSparLINK_GRP, @varKSparSERIES, @varKSparLINK_UM,@lbIS_EXTRA,
			@varKSparLINK_OKDP, @nCOEFF, @nCOEFF_OKPD, @intPRICE_TYPE, @intISUSED, @varKSparLINK_OKPD)
		SELECT @varKSERROR = @@ERROR, @varKSparLINK = @@IDENTITY
		IF @varKSERROR <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END

	SET @varKSEventText = 'Номенклатура' + ' ' + NULL+' '+NULL
	SELECT @varKSintObj = LINK FROM dbo.S_OBJECTS WHERE CODE = 'BV_NOMENCLATURE'
	EXECUTE WF_GENERATEEVENT 'Сохранение строки справочника', @varKSEventText, @varKSintObj, 'NOMENCLATURE', @varKSparLINK

	IF @@TRANCOUNT > @varKStrancount
		COMMIT TRAN
RETURN 0


GO


GRANT EXECUTE ON dbo.[BV_SAVE_NOMENCLATURE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_NUO_DGH_FILL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_NUO_DGH_FILL]

GO

CREATE PROCEDURE DBO.SD_NUO_DGH_FILL
	@varKSdDate datetime = NULL,
	@DEP_LINK INT = NULL,
	@MODE TINYINT = 1,
	@BUFFER VARCHAR(20) = NULL
AS 
DECLARE @varKSDateB datetime, @varKSDateE datetime
set @varKSDateB = dbo.DateBeginOfMonth(@varKSdDate)
set @varKSDateE = dbo.DateEndOfMonth(@varKSdDate)

DECLARE @EKR213 INT
SET @EKR213 = (SELECT TOP 1 LINK FROM DICTIONARY_ITEM WHERE CODE = '213')

CREATE TABLE #DOG(LINK_DOG INT)

IF @BUFFER IS NOT NULL
	INSERT INTO #DOG (LINK_DOG)
	SELECT LINK FROM dbo.BUFFER WITH (NOLOCK) WHERE ID = @BUFFER AND SID = SUSER_SID()

DECLARE @EKR211 INT
SET @EKR211 = (SELECT TOP 1 LINK FROM DICTIONARY_ITEM WHERE CODE = '211')

IF @DEP_LINK IS NULL
	exec dbo.xd_whats_zb @DEP_LINK output

--Инвалиды и процент по ним
CREATE TABLE #INV (LINK INT)
INSERT  INTO #INV (LINK)
SELECT
	I.PERS_LINK
FROM	
	dbo.PERS_INVALID I
WHERE
	(YEAR(@varKSDateE) * 100 + MONTH(@varKSDateE)) BETWEEN YEAR(ISNULL(I.DATE_BEGIN,@varKSDateE)) * 100 + MONTH(ISNULL(I.DATE_BEGIN,@varKSDateE))
											AND YEAR(ISNULL(I.DATE_END,@varKSDateE)) * 100 + MONTH(ISNULL(I.DATE_END,@varKSDateE))

--1) РЕЕСТР ДОГОВОРОВ ДЛЯ РАСЧЁТА
CREATE TABLE #DGH(
	PERS_LINK INT,
	FIO VARCHAR(254),
	DATE1 DATETIME,
	DATE2 DATETIME,
	SUMMA NUMERIC(18,2),
	SUMMA_ADD NUMERIC(18,2),
	LINK_PAYS INT,
	CODE_PAYS VARCHAR(10),
	NAME_PAYS VARCHAR(60),
	LINK INT, 
	NUMBER VARCHAR(10),
	[DATE] DATETIME,
	PAYMENT TINYINT,
	VZNOS TINYINT,
	FLAG_NALOG  TINYINT,
	FLAG_ESN TINYINT,
	FLAG_TRAVMA  TINYINT,
	BIRTHDATE DATETIME, 
	SEX TINYINT,
	DATE_BEGIN DATETIME,
	DATE_END DATETIME,
	SUMMA_CALC NUMERIC(18,2),
	LINK_VKR INT,
	NAME_VKR VARCHAR(254),
	LINK_EKR INT,
	CODE_EKR VARCHAR(3),
	LINK_EKR3 INT,
	CODE_EKR3 VARCHAR(3),
	KATEG TINYINT,
	RESIDENT TINYINT
)
INSERT INTO #DGH(
	PERS_LINK,FIO,DATE1,DATE2,SUMMA,SUMMA_ADD,LINK_PAYS,CODE_PAYS,NAME_PAYS,LINK,NUMBER,[DATE],
	PAYMENT,VZNOS,FLAG_NALOG,FLAG_ESN,FLAG_TRAVMA,BIRTHDATE,SEX,DATE_BEGIN,DATE_END,SUMMA_CALC,
	LINK_VKR,NAME_VKR,LINK_EKR,CODE_EKR,LINK_EKR3,CODE_EKR3,KATEG,RESIDENT)
SELECT 
	SRD.PERS_LINK,FIO,DATE1,DATE2,
	[SUMMA] = SRD.SUMMA, 
	[SUMMA_ADD] =  0,
	LINK_PAYS,CODE_PAYS,NAME_PAYS,
	SRD.LINK, SRD.NUMBER,
	SRD.[DATE],PAYMENT,
	VZNOS,FLAG_NALOG,FLAG_ESN,FLAG_TRAVMA,
	BIRTHDATE, SEX,
	[DATE_BEGIN] =(case when date1<@varKSDateB then @varKSDateB else date1 end),
	[DATE_END] =(case when date2>@varKSDateE then @varKSDateE else date2 end),
	[SUMMA_CALC] = SRD.SUMMA *(case when PAYMENT=2 then ((datediff(d,(case when DATE1>@varKSDateB then DATE1 else @varKSDateB end),(case when DATE2<@varKSDateE then DATE2 else @varKSDateE end))+1)/(datediff(d,@varKSDateB,@varKSDateE)+1)) else 1 end),
	[LINK_VKR]=SRD.LINK_KBK,
	[NAME_VKR]= SRD.CODE_KBK,
	[LINK_EKR]= P.link_ekr,
	[CODE_EKR]= DI.CODE,
	[LINK_EKR3]= CASE WHEN P.link_ekr = @EKR211 THEN @EKR213 ELSE P.link_ekr END,
	[CODE_EKR3]= CASE WHEN P.link_ekr = @EKR211 THEN '213' ELSE DI.CODE END,
	KATEG = (CASE WHEN I.LINK IS NULL THEN 1 ELSE 3 END), -- SELECT * FROM SA_PFR_KATEG
	SRD.RESIDENT
FROM 
	dbo.SALARY_REESTR_DGH SRD 
	INNER JOIN dbo.PAYS P ON SRD.LINK_PAYS = P.LINK
	LEFT JOIN dbo.DICTIONARY_ITEM DI ON DI.LINK = P.LINK_EKR
	LEFT JOIN #INV I ON I.LINK = SRD.PERS_LINK
WHERE 
	((date1<=@varKSDateE AND date2>=@varKSDateB  and @varKSdDate is not null ) or @varKSdDate is null )
	AND dep_link = @DEP_LINK
	AND @varKSdDate IS NOT NULL
	AND (@MODE = 1 OR @MODE = 2 AND EXISTS (SELECT * FROM #DOG WHERE LINK_DOG = SRD.LINK))
	

INSERT INTO #DGH(
	PERS_LINK,FIO,DATE1,DATE2,SUMMA,SUMMA_ADD,LINK_PAYS,CODE_PAYS,NAME_PAYS,LINK,NUMBER,[DATE],
	PAYMENT,VZNOS,FLAG_NALOG,FLAG_ESN,FLAG_TRAVMA,BIRTHDATE,SEX,DATE_BEGIN,DATE_END,SUMMA_CALC,
	LINK_VKR,NAME_VKR,LINK_EKR,CODE_EKR,LINK_EKR3,CODE_EKR3,KATEG,RESIDENT)
SELECT 
	SRD.PERS_LINK,FIO,DATE1,DATE2,
	[SUMMA] = 0, 
	[SUMMA_ADD] =  SUM(AD.SUMMA),
	LINK_PAYS,CODE_PAYS,NAME_PAYS,
	SRD.LINK, SRD.NUMBER,
	SRD.[DATE],PAYMENT,
	VZNOS,FLAG_NALOG,FLAG_ESN,FLAG_TRAVMA,
	BIRTHDATE, SEX,
	[DATE_BEGIN] = NULL,
	[DATE_END] =NULL,
	[SUMMA_CALC] = 0,
	[LINK_VKR]= 0,
	[NAME_VKR]= '',
	[LINK_EKR]=0,
	[CODE_EKR]= '',
	[LINK_EKR3]=0,
	[CODE_EKR3]= '',
	KATEG = (CASE WHEN I.LINK IS NULL THEN 1 ELSE 3 END), -- SELECT * FROM SA_PFR_KATEG
	SRD.RESIDENT
FROM 
	dbo.SALARY_REESTR_DGH SRD 
	INNER JOIN dbo.SD_NDFL_ADDITION_DOHOD  AD ON AD.DGH_LINK = SRD.LINK AND AD.PERS_TYPE = 2 
	LEFT JOIN #INV I ON I.LINK = SRD.PERS_LINK	
WHERE 
	dep_link = @DEP_LINK
	AND @varKSdDate IS NULL
	AND (@MODE = 1 OR @MODE = 2 AND EXISTS (SELECT * FROM #DOG WHERE LINK_DOG = SRD.LINK))
GROUP BY
	SRD.PERS_LINK,FIO,DATE1,DATE2,
	LINK_PAYS,CODE_PAYS,NAME_PAYS,
	SRD.LINK, SRD.NUMBER,
	SRD.[DATE],PAYMENT,
	VZNOS,FLAG_NALOG,FLAG_ESN,FLAG_TRAVMA,
	BIRTHDATE, SEX, I.LINK, SRD.RESIDENT

IF @MODE = 1 BEGIN
	SELECT
		[NAME_DOG] = '№ '+rtrim(NUMBER)+' от '+convert(varchar(20),DATE,104),
		*
	FROM #DGH ORDER BY FIO
	RETURN 0
END
	
--2) СПИСОК ВИДОВ ВЗНОСОВ НА ДАННЫЙ ПЕРИОД	
CREATE TABLE #PAYS3	(LINK INT)

INSERT INTO #PAYS3 (LINK)
SELECT 
	T.REF_PAY
FROM
	dbo.MINROT M 
	INNER JOIN dbo.DICTIONARY_MROT_TABLE4 T ON T.LINK_MINROT = M.LINK
WHERE
	M.LINK = ( SELECT TOP 1 M2.LINK FROM dbo.MINROT M2 WHERE M2.PERIOD <= @varKSDateE ORDER BY M2.PERIOD DESC )

--Травматизм
INSERT INTO #PAYS3 (LINK)
SELECT LINK FROM dbo.PAYS P
WHERE 
	[OBJECT] = 3 AND WAY_CALC = 5
	AND NOT EXISTS (SELECT * FROM #PAYS3 PP WHERE PP.LINK = P.LINK)

DECLARE @PERC_TRAVM_IVALID NUMERIC(18,2)
SET @PERC_TRAVM_IVALID = ISNULL((SELECT TOP 1 MP.summa FROM dbo.MINROT_PAYS MP WHERE LINK_MINROT = (SELECT TOP 1 LINK FROM dbo.MINROT WHERE PERIOD<=@varKSDateE ORDER BY PERIOD DESC)),0)

--Базовые начисления
CREATE TABLE #TR(LINK_TAX INT, LINK_PAYS INT)
INSERT INTO #TR(LINK_TAX, LINK_PAYS)
SELECT DISTINCT R.LINK_TAX, R.LINK_PAYS
FROM
	dbo.TAX_REF R
	INNER JOIN dbo.PAYS P ON P.LINK = R.LINK_TAX
WHERE	
	(P.OBJECT = 2) 
	or 
	(P.OBJECT = 3 AND EXISTS (SELECT * FROM #PAYS3 P3 WHERE P3.LINK = P.LINK))	

--
DECLARE @BY DATETIME
SET @BY = dbo.DateBeginOfYear(@varKSDateB)

CREATE TABLE #DICT_VICHET (LINK_DOG INT, LINK_DED INT, PREDEL NUMERIC(18,2), SUMMA NUMERIC(18,2), DATE1 DATETIME, DATE2 DATETIME, MONS INT)

INSERT INTO #DICT_VICHET (LINK_DOG, LINK_DED, PREDEL, SUMMA, DATE1, DATE2)
SELECT 
	LINK_DGH, DED_LINK, SD.PREDEL, SD.SUMMA, 
	
	DATE1 = CASE WHEN (CASE WHEN D.DATE1 < SRD.DATE1 THEN SRD.DATE1 ELSE D.DATE1 END) <= @BY
				THEN @BY
				ELSE (CASE WHEN D.DATE1 < SRD.DATE1 THEN SRD.DATE1 ELSE D.DATE1 END)
			END, 
	
	DATE2 = CASE WHEN (CASE WHEN D.DATE2 > SRD.DATE2 THEN SRD.DATE2 ELSE D.DATE2 END) > @varKSDateE
				THEN @varKSDateE
				ELSE (CASE WHEN D.DATE2 > SRD.DATE2 THEN SRD.DATE2 ELSE D.DATE2 END)
			END
FROM
	#DOG A 
	INNER JOIN dbo.SALARY_REESTR_DGH SRD ON SRD.LINK = A.LINK_DOG
	INNER JOIN dbo.EMPL_DED D ON D.LINK_DGH = A.LINK_DOG
	INNER JOIN dbo.Salary_deductions(@varKSDateE) SD ON SD.REF_PAY = D.DED_LINK
WHERE
	(CASE WHEN D.DATE1 < SRD.DATE1 THEN SRD.DATE1 ELSE D.DATE1 END)<=@varKSDateE 
	AND 
	(CASE WHEN D.DATE2 > SRD.DATE2 THEN SRD.DATE2 ELSE D.DATE2 END)>=@varKSDateB

UPDATE #DICT_VICHET
SET MONS = MONTH(DATE2) - MONTH(DATE1) + 1

---
CREATE TABLE #TAX (	
	ID INT IDENTITY(1,1), ORDERS INT,
	LINK_DOG INT, SUMMA_BASE NUMERIC(18,2), PERS_LINK INT, LINK INT, CODE VARCHAR(10), 
	NAME VARCHAR(254), WAY_CALC TINYINT, [PERCENT] NUMERIC(18,4), [OBJECT] INT,
	BASE_YEAR NUMERIC(18,2), SUMMA_YEAR NUMERIC(18,2), SUMMA_OLD NUMERIC(18,2), SUMMA NUMERIC(18,2), LINK_SFIN INT)

INSERT INTO #TAX (LINK_DOG, SUMMA_BASE, PERS_LINK, LINK, CODE, NAME, WAY_CALC, [PERCENT], [OBJECT])	
SELECT
	LINK_DOG = D.LINK,
	SUMMA_BASE = ISNULL(SUMMA,0) + ISNULL(SUMMA_ADD,0),
	PERS_LINK = D.PERS_LINK,
	P.LINK,
	P.CODE,
	P.NAME,
	P.WAY_CALC,
	[percent] =	(CASE WHEN P.WAY_CALC NOT IN (6,7,8,9) THEN 
					(CASE WHEN 
							WAY_CALC = 5 --ФСС ТРАВМАТИЗМ
							AND 
							(CASE WHEN ISNULL(D.KATEG,0) > (ISNULL(F.ENVD,0) + 1) THEN ISNULL(D.KATEG,0) ELSE (ISNULL(F.ENVD,0) + 1) END) = 3 
						THEN
							@PERC_TRAVM_IVALID
					ELSE 
						ISNULL((	SELECT TOP 1 DR.[percent] 
							from dbo.dictionary_range DR
							where 
								(	
									DR.TARIF = (CASE WHEN ISNULL(D.KATEG,0) > (ISNULL(F.ENVD,0) + 1) THEN ISNULL(D.KATEG,0) ELSE (ISNULL(F.ENVD,0) + 1) END)
									OR --Для подоходного налога по общему тарифу всегда
									DR.TARIF = 1 
									AND 
									EXISTS (SELECT * FROM dbo.PAYS P1 WHERE DR.LINK_PAYS = P1.LINK AND P1.[OBJECT] = 2 AND P1.WAY_CALC IN (4,5,6)) 
								)
								AND DR.LINK_PAYS = P.LINK and [DATE]<=@varKSDateE order by DR.[DATE] desc, DR.PREDEL asc
						),0)  
									
					END)	
			ELSE
				ISNULL((SELECT TOP 1 (CASE WHEN 
								(CASE 
									WHEN YEAR(BIRTHDATE)<=(CASE WHEN D.SEX = 1 THEN 1952 ELSE 1956 END) THEN 1 
									WHEN (YEAR(BIRTHDATE)>(CASE WHEN D.SEX = 1 THEN 1952 ELSE 1956 END) AND YEAR(BIRTHDATE)<1967) THEN 2 
									ELSE 3 
								END) = 1 
								THEN PERCENT1 
							WHEN 
								(CASE 
									WHEN YEAR(BIRTHDATE)<=(CASE WHEN D.SEX = 1 THEN 1952 ELSE 1956 END) THEN 1 
									WHEN (YEAR(BIRTHDATE)>(CASE WHEN D.SEX = 1 THEN 1952 ELSE 1956 END) AND YEAR(BIRTHDATE)<1967) THEN 2 
									ELSE 3 
								END) = 2  
								THEN PERCENT2 
							ELSE PERCENT3 END) 
					FROM 
						DBO.DICTIONARY_RANGE_PF
					WHERE 
							TARIF = (CASE WHEN ISNULL(D.KATEG,0) > (ISNULL(F.ENVD,0) + 1) THEN ISNULL(D.KATEG,0) ELSE (ISNULL(F.ENVD,0) + 1) END) 
							AND SpecO IS NULL
							AND LINK_PAYS = P.LINK 
							AND DATE<=@varKSDateE 
					ORDER BY DATE DESC, PREDEL ASC),0)  
			 END),
	P.[OBJECT]
FROM 
	#DGH D
	INNER JOIN dbo.SAL_SFIN F ON F.LINK = D.LINK_VKR
	INNER JOIN #TR R ON R.LINK_PAYS = D.LINK_PAYS
	INNER JOIN dbo.PAYS P ON P.LINK = R.LINK_TAX
WHERE
	(
		P.[OBJECT] = 2 AND D.FLAG_NALOG = 1 AND (D.RESIDENT = 1 AND P.WAY_CALC = 4 OR D.RESIDENT <> 1 AND P.WAY_CALC = 5)
		OR 
		P.[OBJECT] = 3 
				AND (P.WAY_CALC = 5 AND D.FLAG_TRAVMA = 1 OR P.WAY_CALC = 2 AND D.VZNOS = 1 OR P.WAY_CALC IN (1,3,4,6,7,8,9) AND D.FLAG_ESN = 1)
				AND EXISTS (SELECT * FROM #PAYS3 P3 WHERE P3.LINK = P.LINK)
	)
ORDER BY
	P.OBJECT, D.LINK	

--- Прочие удержания по договорникам
INSERT INTO #TAX (LINK_DOG, SUMMA_BASE, PERS_LINK, LINK, CODE, NAME, WAY_CALC, [PERCENT], [OBJECT], LINK_SFIN)	
SELECT
	LINK_DOG = D.LINK,
	SUMMA_BASE = 
			CASE WHEN P.WAY_CALC IN (2,3) THEN
				ISNULL(D.SUMMA,0) * ISNULL( (SELECT MAX(1) FROM dbo.TAX_REF G WHERE G.LINK_TAX = T.LINK_TAX AND G.LINK_PAYS = D.LINK_PAYS) ,0)
			ELSE
				0
			END,
	PERS_LINK = D.PERS_LINK,
	P.LINK,
	P.CODE,
	P.NAME,
	P.WAY_CALC,	
	[percent] =	T.SUMMA,
	P.[OBJECT],
	(CASE WHEN ISNULL(T.LINK_VKR,0) = 0 THEN D.LINK_VKR ELSE T.LINK_VKR END)
FROM 
	#DGH D
	INNER JOIN dbo.SD_EMPL_TAX T ON T.LINK_DGH = D.LINK
	INNER JOIN dbo.PAYS P ON P.LINK = T.LINK_TAX
WHERE
	P.[OBJECT] = 2
ORDER BY
	P.CODE, D.LINK

--3) РАНЕЕ НАЧИСЛЕННЫЕ ДОХОДЫ,ВЗНОСЫ И НАЛОГИ
CREATE TABLE #OLD (MON INT, PERS_LINK INT, LINK_DOG INT, LINK INT, SUMMA_D NUMERIC(18,2), SUMMA_N NUMERIC(18,2))

INSERT INTO #OLD (MON, PERS_LINK, LINK_DOG, LINK, SUMMA_D, SUMMA_N)
SELECT 
	MONTH(D.[DATE]),
	T2.PERS_LINK,
	D.LINK,
	T2.LINK_PAY,
	SUMMA_D = SUM(T2.SUMMA_BASE),
	SUMMA_N = SUM(T2.SUMMA)
FROM
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DGH_TABLE T2 ON T2.LINK_UP = D.LINK 
	INNER JOIN dbo.PAYS P ON P.LINK = T2.LINK_PAY
WHERE 
	D.LINK_DEP = @DEP_LINK
	AND
	D.FLAG_JC = 1
	AND
	T2.[OBJECT] = 2	
	AND
	P.[OBJECT] = 2 AND P.WAY_CALC IN (4,5,6)
	AND
	YEAR(D.[DATE]) = YEAR(@varKSDateE)
	AND
	MONTH(D.[DATE]) <= MONTH(@varKSDateE)
GROUP BY
	MONTH(D.[DATE]),
	T2.PERS_LINK,
	D.LINK,
	T2.LINK_PAY
	
INSERT INTO #OLD (MON, PERS_LINK, LINK_DOG, LINK, SUMMA_D, SUMMA_N)
SELECT 
	MONTH(D.[DATE]),
	T2.PERS_LINK,
	D.LINK,
	T2.LINK_PAY,
	SUMMA_D = SUM(T2.SUMMA_BASE),
	SUMMA_N = SUM(T2.SUMMA)
FROM
	dbo.SDOC D
	INNER JOIN dbo.SDOC_DGH_TABLE T2 ON T2.LINK_UP = D.LINK 
	INNER JOIN dbo.PAYS P ON P.LINK = T2.LINK_PAY
WHERE 
	D.LINK_DEP = @DEP_LINK
	AND
	D.FLAG_JC = 1
	AND
	T2.[OBJECT] = 3	
	AND
	P.[OBJECT] = 3 AND EXISTS (SELECT * FROM #PAYS3 P3 WHERE P3.LINK = P.LINK)
	AND
	YEAR(D.[DATE]) = YEAR(@varKSDateE)
	AND
	MONTH(D.[DATE]) <= MONTH(@varKSDateE)
GROUP BY
	MONTH(D.[DATE]),
	T2.PERS_LINK,
	D.LINK,
	T2.LINK_PAY	

--4) РАСЧЁТ НАЛОГОВ
--Определение базы с начала года	
UPDATE T SET 
	T.BASE_YEAR =	(
					ISNULL((SELECT SUM(O.SUMMA_D) FROM #OLD O WHERE O.PERS_LINK = T.PERS_LINK AND O.LINK = T.LINK),0)
					+ ISNULL((SELECT SUM(N.SUMMA_BASE) FROM #TAX N WHERE N.PERS_LINK = T.PERS_LINK AND N.LINK = T.LINK),0)
					) 
					* 
					(CASE WHEN ISNULL((SELECT SUM(N.SUMMA_BASE) FROM #TAX N WHERE N.PERS_LINK = T.PERS_LINK AND N.LINK = T.LINK),0) > 0
						THEN T.SUMMA_BASE / ISNULL((SELECT SUM(N.SUMMA_BASE) FROM #TAX N WHERE N.PERS_LINK = T.PERS_LINK AND N.LINK = T.LINK),0)
						ELSE 0
					END)	
	,T.SUMMA_OLD = ISNULL((SELECT SUM(O.SUMMA_N) FROM #OLD O WHERE O.PERS_LINK = T.PERS_LINK AND O.LINK = T.LINK),0)
					* 
					(CASE WHEN ISNULL((SELECT SUM(N.SUMMA_BASE) FROM #TAX N WHERE N.PERS_LINK = T.PERS_LINK AND N.LINK = T.LINK),0) > 0
						THEN T.SUMMA_BASE / ISNULL((SELECT SUM(N.SUMMA_BASE) FROM #TAX N WHERE N.PERS_LINK = T.PERS_LINK AND N.LINK = T.LINK),0)
						ELSE 0
					END)	
FROM 
	#TAX T
WHERE
	T.[OBJECT] = 2 AND T.WAY_CALC IN (4,5,6)
	OR
	T.[OBJECT] = 3

--
CREATE TABLE #DOXOD (LINK_PERS INT, MON INT, SUMMA NUMERIC(18,2), SUMMA2 NUMERIC(18,2))
INSERT INTO #DOXOD (LINK_PERS, MON, SUMMA, SUMMA2)
SELECT PERS_LINK, MON, SUM(SUMMA_D), 0
FROM
	(
	SELECT PERS_LINK, MON, SUMMA_D FROM #OLD O INNER JOIN dbo.PAYS P ON P.LINK = O.LINK WHERE P.[OBJECT] = 2 AND P.WAY_CALC IN (4,5,6)
	UNION ALL	
	SELECT PERS_LINK, MON = MONTH(@varKSdDate), SUMMA_BASE FROM #TAX T INNER JOIN dbo.PAYS P ON P.LINK = T.LINK WHERE P.[OBJECT] = 2 AND P.WAY_CALC IN (4,5,6)
	) T
GROUP BY PERS_LINK, MON

--
UPDATE D
SET SUMMA2 = (SELECT SUM(SUMMA) FROM #DOXOD D2 WHERE D2.LINK_PERS = D.LINK_PERS AND D2.MON <= D.MON)
FROM #DOXOD D

--
DELETE FROM [dbo].[SAL_DED_MONTH]
WHERE EXISTS (SELECT * FROM #DGH H WHERE H.LINK = [dbo].[SAL_DED_MONTH].[LINK_DGH])

--
INSERT INTO [dbo].[SAL_DED_MONTH] (REF_DED, SUMMA, DATE_DED, LINK_VKR, LINK_EKR, [TYPE], KOEF_VKR, KOL, LINK_DGH)
SELECT 
	REF_DED = V.LINK_DED, 
	V.SUMMA,
	DATE_DED = M.DATE_BEGIN,
	LINK_VKR = H.LINK_VKR,
	LINK_EKR = H.LINK_EKR,
	[TYPE] = 1,
	KOEF_VKR = 1,
	KOL = 1,
	LINK_DGH = H.LINK
FROM
	dbo.MONTHS_EX (@BY, @varKSDateE) M
	INNER JOIN #TAX T ON 1=1
	INNER JOIN #DGH H ON H.LINK = T.LINK_DOG
	INNER JOIN #DICT_VICHET V ON T.LINK_DOG = V.LINK_DOG
	LEFT JOIN #DOXOD D ON D.LINK_PERS = T.PERS_LINK AND D.MON = M.M
WHERE
	T.[OBJECT] = 2 AND T.WAY_CALC = 4
	AND
	M.M BETWEEN MONTH(V.DATE1) AND MONTH(V.DATE2)
	AND
	(CASE WHEN ISNULL(D.SUMMA2,0) <= ISNULL(V.PREDEL,0) OR ISNULL(V.PREDEL,0) = 0 THEN ISNULL(V.SUMMA,0) ELSE 0 END) > 0

--определение вычетов с начала года
CREATE TABLE #SUM_VYCH (LINK_DOG INT, LINK INT, SUMMA_YEAR NUMERIC(18,2), SUMMA_M NUMERIC(18,2))
INSERT INTO #SUM_VYCH (LINK_DOG, LINK, SUMMA_YEAR, SUMMA_M)
SELECT 
	T.LINK_DOG,
	T.LINK,
	SUM_VICH = (SELECT SUM(SDM.SUMMA) FROM 
					[dbo].[SAL_DED_MONTH] SDM 
					INNER JOIN dbo.[REESTR_DGH] RD ON SDM.LINK_DGH = RD.LINK
				WHERE 
					RD.DEP_LINK = @DEP_LINK AND T.PERS_LINK = RD.PERS_LINK
					AND YEAR(SDM.DATE_DED) =YEAR(@varKSDateE) AND MONTH(SDM.DATE_DED) <= MONTH(@varKSDateE)),
	SUMMA_M = (SELECT SUM(SDM.SUMMA) FROM 
					[dbo].[SAL_DED_MONTH] SDM 
					INNER JOIN dbo.[REESTR_DGH] RD ON SDM.LINK_DGH = RD.LINK
				WHERE 
					RD.DEP_LINK = @DEP_LINK AND T.PERS_LINK = RD.PERS_LINK
					AND YEAR(SDM.DATE_DED) =YEAR(@varKSDateE) AND MONTH(SDM.DATE_DED) = MONTH(@varKSDateE))
FROM 
	#TAX T
WHERE
	T.[OBJECT] = 2 AND T.WAY_CALC = 4
GROUP BY
	T.LINK_DOG, T.PERS_LINK, T.LINK

--Определенеи налога с начала года
UPDATE T SET 
	T.SUMMA_YEAR = 
		CASE WHEN P.OBJECT = 2 THEN
			ROUND((T.BASE_YEAR - ISNULL(V.SUMMA_YEAR,0)) * ISNULL(T.[PERCENT],0) / 100,0)
		ELSE
			T.BASE_YEAR * ISNULL(T.[PERCENT],0) / 100
		END
FROM 
	#TAX T
	INNER JOIN dbo.PAYS P ON P.LINK = T.LINK
	LEFT JOIN #SUM_VYCH V ON V.LINK_DOG = T.LINK_DOG

--Определенеи налога за месяц
UPDATE T SET 
	T.SUMMA = T.SUMMA_YEAR - T.SUMMA_OLD
FROM 
	#TAX T

--ОКРУГЛЯЕМ МЕСЯЧНЫЙ НАЛОГ ДО КОПЕЕК
CREATE TABLE #TAX1 (PERS_LINK INT,LINK INT,SUMMA NUMERIC(18,2))
INSERT INTO #TAX1 (PERS_LINK,LINK,SUMMA)
SELECT T.PERS_LINK, T.LINK, SUM(T.SUMMA) 
FROM #TAX T INNER JOIN dbo.PAYS P ON T.LINK = P.LINK
WHERE P.[OBJECT] = 2 AND P.WAY_CALC IN (4,5,6)
GROUP BY T.PERS_LINK, T.LINK

--Округление НДФЛ за месяц
UPDATE T SET 
	T.SUMMA = CONVERT(NUMERIC(18,0),T.SUMMA)
FROM 
	#TAX T
WHERE	
	T.[OBJECT] = 2 AND T.WAY_CALC IN (4,5,6)
	
--
UPDATE T SET 
	T.SUMMA = 
		CASE WHEN T.WAY_CALC = 1
			THEN T.[PERCENT] --T.[PERCENT] СОДЕРЖИТ СУММУ
			ELSE SUMMA_BASE * T.[PERCENT] / 100 --T.[PERCENT] СОДЕРЖИТ ПРОЦЕНТ
		END,
	BASE_YEAR = 0,
	SUMMA_YEAR = 0,
	SUMMA_OLD = 0		
FROM 
	#TAX T
WHERE
	T.[OBJECT] = 2 AND T.WAY_CALC IN (1,2,3)	


CREATE TABLE #TAX2 (PERS_LINK INT,LINK_DOG INT,LINK INT,SUMMA NUMERIC(18,2))
INSERT INTO #TAX2 (PERS_LINK, LINK_DOG, LINK, SUMMA)
SELECT PERS_LINK, MAX(LINK_DOG), T.LINK, SUM(SUMMA) 
FROM #TAX T INNER JOIN dbo.PAYS P ON T.LINK = P.LINK
WHERE P.[OBJECT] = 2 AND P.WAY_CALC IN (4,5,6)
GROUP BY T.PERS_LINK, T.LINK

UPDATE T SET 
	T.SUMMA = CONVERT(NUMERIC(18,0), ISNULL(T.SUMMA,0) + ISNULL((SELECT T1.SUMMA FROM #TAX1 T1 WHERE T2.PERS_LINK = T1.PERS_LINK AND T2.LINK = T1.LINK),0) - ISNULL(T2.SUMMA,0))
FROM 
	#TAX T
	INNER JOIN #TAX2 T2 ON T.LINK_DOG = T2.LINK_DOG AND T.LINK = T2.LINK
	
DECLARE @Cur1 CURSOR
DECLARE @ID INT, @OBJECT INT, @OBJECT2 INT, @NEXT INT
SELECT @NEXT = 0, @OBJECT2 = 0
SET @Cur1 = CURSOR FORWARD_ONLY

FOR SELECT ID, OBJECT FROM #TAX ORDER BY ID

OPEN @Cur1
FETCH NEXT FROM @Cur1 INTO @ID, @OBJECT
WHILE (@@fetch_status <> -1)
BEGIN
	IF (@@fetch_status <> -2)
	BEGIN

		IF @OBJECT <> @OBJECT2 BEGIN
			SET @NEXT = 1
			SET @OBJECT2 = @OBJECT
		END			
		ELSE
			SET @NEXT = @NEXT + 1
		
		UPDATE #TAX SET ORDERS = @NEXT WHERE ID = @ID

	END

	FETCH NEXT FROM @Cur1 INTO @ID, @OBJECT
END

CLOSE @Cur1
DEALLOCATE @Cur1


SELECT
	T.ORDERS,
	D.LINK, D.PERS_LINK, D.FIO, D.LINK_VKR, D.NAME_VKR, D.LINK_EKR, D.CODE_EKR,
	LINK_PAY = P.LINK, CODE_PAY = P.CODE, NAME_PAY = P.NAME, P.[OBJECT],
	T.BASE_YEAR, T.SUMMA_BASE, 
	V_SUM_Y = ISNULL(V.SUMMA_YEAR,0), V_SUM_M = ISNULL(V.SUMMA_M,0),
	T.[PERCENT], T.SUMMA_YEAR, T.SUMMA_OLD, T.SUMMA
FROM
	#DGH D 
	INNER JOIN #TAX T ON D.LINK = T.LINK_DOG
	INNER JOIN dbo.PAYS P ON P.LINK = T.LINK
	LEFT JOIN #SUM_VYCH V ON V.LINK = T.LINK AND V.LINK_DOG = T.LINK_DOG
ORDER BY
	P.[OBJECT], D.FIO	

RETURN 0
	


GO


GRANT EXECUTE ON dbo.[SD_NUO_DGH_FILL] TO PUBLIC

GO

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[X_UPDATE_FINANSE_CONTRACT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[X_UPDATE_FINANSE_CONTRACT]
GO





/*
© Кейсистемс (Keysystems), 2005
*/



CREATE	PROCEDURE X_UPDATE_FINANSE_CONTRACT
	@varKSintLINK	int	OUTPUT,
	@varKSintLINK_UP	int,
--	@varKSnRECORD_NO	NUMERIC(10),
--	@varKSnREC_CH_NO	NUMERIC(10),
	@varKScRECORD_NO	char(10),
	@varKScREC_CH_NO	char(10),
	@varKSintVKR		int,
	@varKSintEKR		int,
	@varKSintDop_Class	int,
	@i@iOKDP		int,
	@i@iOKPD		int,
	@nQuantity		numeric(19,4),
	@nCost			numeric(19,2),
	@nSumma			numeric(19,2),
	@varKSP1		numeric(19,2),
	@varKSP2		numeric(19,2),
	@varKSP3		numeric(19,2),
	@varKSP4		numeric(19,2),
	@varKSP5		numeric(19,2),
	@varKSP6		numeric(19,2),
	@varKSP7		numeric(19,2),
	@varKSP8		numeric(19,2),
	@varKSP9		numeric(19,2),
	@varKSP10		numeric(19,2),
	@varKSP11		numeric(19,2),
	@varKSP12		numeric(19,2)
	
AS
Declare
	@varKSERROR	int,
	@varKSRowCount	int,
	@varKStrancount	int
--	@varKScRECORD_NO	char(10),
--	@varKScREC_CH_NO	char(10)

--SET @varKScRECORD_NO = STR(@varKSnRECORD_NO)
--SET @varKScREC_CH_NO = STR(@varKSnREC_CH_NO)
SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
	IF @varKSintLINK is null OR @varKSintLINK = 0
	BEGIN
		INSERT INTO FINANSE_CONTRACT(LINK_UP, RECORD_NO, RECORD_CH_NO, VKR, EKR, Dop_Classif, OKDP,OKPD, QUANTITY, COST, SUMMA, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12)
			VALUES (@varKSintLINK_UP, @varKScRECORD_NO, @varKScREC_CH_NO, @varKSintVKR, @varKSintEKR, @varKSintDop_Class, @i@iOKDP, @i@iOKPD, @nQuantity, @nCost, @nSumma, @varKSP1, @varKSP2, @varKSP3, @varKSP4, @varKSP5, @varKSP6, @varKSP7, @varKSP8, @varKSP9, @varKSP10, @varKSP11, @varKSP12)
		SELECT @varKSERROR = @@ERROR, @varKSintLINK = @@IDENTITY
		IF @varKSERROR <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END
	ELSE
	BEGIN
		UPDATE FINANSE_CONTRACT
			SET LINK_UP 	     = @varKSintLINK_UP,
				RECORD_NO    = @varKScRECORD_NO,
				RECORD_CH_NO =@varKScREC_CH_NO,
				VKR 	     = @varKSintVKR,
				EKR 	     = @varKSintEKR,
				Dop_Classif  = @varKSintDop_Class,
				OKDP 	     = @i@iOKDP, 
				OKPD 	     = @i@iOKPD,
				QUANTITY     = @nQuantity, 
				COST	     = @nCost,
				SUMMA	     = @nSumma,
				P1  = @varKSP1,
				P2  = @varKSP2,
				P3  = @varKSP3,
				P4  = @varKSP4,
				P5  = @varKSP5,
				P6  = @varKSP6,
				P7  = @varKSP7,
				P8  = @varKSP8,
				P9  = @varKSP9,
				P10 = @varKSP10,
				P11 = @varKSP11,
				P12 = @varKSP12
		
		WHERE LINK = @varKSintLINK
		SELECT @varKSERROR = @@ERROR, @varKSRowCount = @@ROWCOUNT
		IF @varKSERROR <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
		IF @varKSRowCount = 0
		BEGIN
			ROLLBACK
			RETURN 2
		END
	END
IF @@TRANCOUNT > @varKStrancount
	COMMIT TRAN
RETURN 0







GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_MANYGRAPH_CARD]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_MANYGRAPH_CARD]

GO

--- МНОГОГРАФНАЯ КАРТОЧКА --- 
-- SELECT * FROM S_ACCOUNTS WHERE CODE = '1.401.01'
-- SELECT * FROM dbo.BK_GetTableDictionByAP ('EKR') 
-- EXEC BK_REPORT_MANYGRAPH_CARD '20070101', '20071231', 1486, 0, 'EKR'
CREATE     PROCEDURE dbo.BK_REPORT_MANYGRAPH_CARD 
	@dDateSTART datetime	/* Начало расч. периода */,
	@dDateEND datetime	/* Конец расч. периода */,
	@nSel_Spr1 int		/* Счет */,
	@nPRN_REST	INT	/* -- Выводить остатки по счету -- */,
	@strCODE_AP	VARCHAR (60) = 'ACCOUNT',
	@cVal_KBK char(1), @nOtborLinkKBK int,	-- Отбор КБК --
	@cVal_KAU char(1) = '', @nOtborLinkKAU int = 0	-- Отбор КАУ
AS 
BEGIN
	DECLARE
		@cCROSS_TABLE_DB	VARCHAR (100),
		@cCROSS_TABLE_KT	VARCHAR (100),
		@intCOUNTER		INT,
		@cCOUNTER		VARCHAR (10),
		@intMAX_REC		INT,
		@cSQL_STR		VARCHAR (1000),
		@DEP_NAME		VARCHAR (254),
		@DEP_OKPO		VARCHAR (20),
		@DEP_LINK		INT,
		@GLBUH_NAME		VARCHAR (100),
		@intCOUNT_COLROW	INT,
		@REST_BEGIN		NUMERIC (28,4),
		@REST_END		NUMERIC (28,4),
		@dDATE_REST_E		DATETIME,
		@cDATE_REST_E		VARCHAR (10)		

	SET @intMAX_REC = 10

	SELECT @DEP_LINK = LINK, @DEP_OKPO = OKPO, @DEP_NAME = [NAME]
	FROM dbo.DICTIONARY_DEPARTMENT
	WHERE LINK = COALESCE (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())

	SELECT @GLBUH_NAME = SHORT_NAME
	FROM dbo.GetOtvFaceData (@DEP_LINK, 'Главный бухгалтер')

	--- ОТБОР КБК --- 
	DECLARE @TAB_KBK TABLE (LINK_KBK INT, KBK_CODE VARCHAR (20))
	IF LEN (@cVal_KBK) > 0
		INSERT INTO @TAB_KBK
		SELECT AP.LINK,
			AP.CODE
		FROM dbo.KL_KBK AP 
		INNER JOIN dbo.OBJECT_VAR_KBK OVR ON (OVR.RECORD = AP.LINK)
		WHERE OVR.LINK_UP = @nOtborLinkKBK
	ELSE
		INSERT INTO @TAB_KBK
		SELECT LINK_AP, AP_CODE
		FROM dbo.BK_GetTableDictionByAP ('KBK')

	--- ОТБОР КАУ --- 
	DECLARE @TAB_KAU TABLE (LINK INT)
	IF LEN (@cVal_KAU) > 0
		INSERT INTO @TAB_KAU
		SELECT
			AP.LINK
		FROM dbo.KAU AP 
		INNER JOIN dbo.OBJECT_VAR_KAU OVR ON (OVR.RECORD = AP.LINK)
		WHERE
			OVR.LINK_UP = @nOtborLinkKAU
	ELSE
		SET @nOtborLinkKAU = -1

	-- Входящий остаток по счету -- 
	SELECT
		@REST_BEGIN = CASE 
						WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
						WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END
	FROM dbo.ARestTableByDate (@dDateSTART, @nSel_Spr1) R
	INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
	INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
	WHERE
		R.DEP_LINK = @DEP_LINK
		AND (@nOtborLinkKAU = -1
				OR @nOtborLinkKAU > 0 AND EXISTS (SELECT * FROM @TAB_KAU TTT
													WHERE TTT.LINK = R.KAU)
				)									
	GROUP BY
		S_ACTIVE, S_PASSIVE

	/* -- Исходящий остаток по счету -- */
	SET @dDATE_REST_E = DATEADD (DAY, 1, @dDateEND)
	SET @cDATE_REST_E = CONVERT (VARCHAR (10), @dDATE_REST_E, 104)
	SELECT
		@REST_END = CASE 
						WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
						WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END
	FROM dbo.ARestTableByDate (@dDATE_REST_E, @nSel_Spr1) R
	INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
	INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
	WHERE
		R.DEP_LINK = @DEP_LINK
		AND (@nOtborLinkKAU = -1
				OR @nOtborLinkKAU > 0 AND EXISTS (SELECT * FROM @TAB_KAU TTT
													WHERE TTT.LINK = R.KAU)
				)									
	GROUP BY S_ACTIVE, S_PASSIVE

	SELECT @REST_BEGIN = ISNULL (@REST_BEGIN, 0), @REST_END = ISNULL (@REST_END, 0)

	--- БЕРЕМ ВСЕ ДЕБЕТОВЫЕ ОБОРОТЫ ЗА ПЕРИОД ПО СЧЕТУ (КРЕДИТОВАЯ КОРРЕСПОНДЕНЦИЯ) --- 
	CREATE TABLE #ACCT_IN_DB
			(DATE_OP		[DATETIME],
				JO_NUM		[VARCHAR] (10),
				NAME_OPER	[VARCHAR] (254),
				AC		[VARCHAR] (60),
				SS		[NUMERIC] (28,4),
				RB		[NUMERIC] (28,4),
				RE		[NUMERIC] (28,4),
				REST_B		[NUMERIC] (28,4),
				REST_E		[NUMERIC] (28,4),
				DATE_E		[VARCHAR] (10))

	INSERT INTO #ACCT_IN_DB
	SELECT OB.DATE_PROV,
		ISNULL (OP.JOUR_CODE, ''),
		OB.NAME_OPER,
		CASE
			WHEN @strCODE_AP = 'ACCOUNT'
				THEN ISNULL (dbo.BK_GetAcctFullCode1 (G_KT.ACCOUNT,
									G_KT.KBK,
									G_KT.SGU,
									DEFAULT, DEFAULT), '')
			ELSE AP.AP_CODE
		END,
		OB.SUMMA,
		0, 0,
		@REST_BEGIN,
		@REST_END,
		@cDATE_REST_E
	FROM dbo.BK_GetTableOborotByDate1 (@dDateSTART, @dDateEND, 0, @nSel_Spr1, @DEP_LINK) OB
	INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = OB.KBK)
	LEFT JOIN dbo.G_PROV_AP G_KT ON (G_KT.LINK_UP = OB.LINK_G2
		AND G_KT.DB_KR = 1)
	LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON (AP.LINK_AP = CASE
									WHEN @strCODE_AP = 'EKR' THEN OB.EKR
									WHEN @strCODE_AP = 'KAU' THEN OB.KAU
								END)
	LEFT OUTER JOIN dbo.BK_TYPE_ECONOM_OPER OP ON (OP.LINK = OB.XOZ_OPER)
	WHERE 
		(@strCODE_AP = 'ACCOUNT' 
			OR (@strCODE_AP = 'EKR' AND AP.LINK_AP IS NOT NULL)
			OR (@strCODE_AP = 'KAU' AND AP.LINK_AP IS NOT NULL)
		)
		AND (@nOtborLinkKAU = -1
				OR @nOtborLinkKAU > 0 AND EXISTS (SELECT * FROM @TAB_KAU TTT
													WHERE TTT.LINK = OB.KAU)
				)									

	--- БЕРЕМ ВСЕ КРЕДИТОВЫЕ ОБОРОТЫ ЗА ПЕРИОД ПО СЧЕТУ (ДЕБЕТОВАЯ КОРРЕСПОНДЕНЦИЯ) --- 
	CREATE TABLE #ACCT_IN_KT (DATE_OP		[DATETIME],
				JO_NUM		[VARCHAR] (10),
				NAME_OPER	[VARCHAR] (254),
				AC		[VARCHAR] (60),
				SS		[NUMERIC] (28,4),
				RB		[NUMERIC] (28,4),
				RE		[NUMERIC] (28,4),
				REST_B		[NUMERIC] (28,4),
				REST_E		[NUMERIC] (28,4),
				DATE_E		[VARCHAR] (10))

	INSERT INTO #ACCT_IN_KT
	SELECT OB.DATE_PROV,
		ISNULL (OP.JOUR_CODE, ''),
		OB.NAME_OPER,
		CASE
			WHEN @strCODE_AP = 'ACCOUNT'
				THEN ISNULL (dbo.BK_GetAcctFullCode1 (G_DB.ACCOUNT,
									G_DB.KBK,
									G_DB.SGU,
									DEFAULT,
									DEFAULT), '')
			ELSE AP.AP_CODE
		END,
		OB.SUMMA,
		0, 0,
		@REST_BEGIN,
		@REST_END,
		@cDATE_REST_E
	FROM dbo.BK_GetTableOborotByDate1 (@dDateSTART, @dDateEND, 1, @nSel_Spr1, @DEP_LINK) OB
	INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = OB.KBK)
	LEFT JOIN dbo.G_PROV_AP G_DB ON (G_DB.LINK_UP = OB.LINK_G2
		AND G_DB.DB_KR = 0)
	LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON (AP.LINK_AP = CASE
									WHEN @strCODE_AP = 'EKR' THEN OB.EKR
									WHEN @strCODE_AP = 'KAU' THEN OB.KAU
								END)
	LEFT OUTER JOIN dbo.BK_TYPE_ECONOM_OPER OP ON (OP.LINK = OB.XOZ_OPER)
	WHERE 
		(@strCODE_AP = 'ACCOUNT' 
			OR (@strCODE_AP = 'EKR' AND AP.LINK_AP IS NOT NULL)
			OR (@strCODE_AP = 'KAU' AND AP.LINK_AP IS NOT NULL)
			)
		AND (@nOtborLinkKAU = -1
				OR @nOtborLinkKAU > 0 AND EXISTS (SELECT * FROM @TAB_KAU TTT
													WHERE TTT.LINK = OB.KAU)
				)				

	--- Остатки по аналитике ---
	IF @strCODE_AP IN ('EKR', 'KAU')
	BEGIN
		-- Входящие ---
		UPDATE T_DB SET RB = ISNULL (R1.R_SUM, 0)
		FROM #ACCT_IN_DB T_DB
		LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON AP.AP_CODE = T_DB.AC
		LEFT JOIN (SELECT CASE 
					WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
					WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END AS R_SUM,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END AS AP
			FROM dbo.ARestTableByDate (@dDateSTART, @nSel_Spr1) R
			INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
			INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
			WHERE R.DEP_LINK = @DEP_LINK
			GROUP BY S_ACTIVE, S_PASSIVE,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END
			) 
				AS R1 ON R1.AP = AP.LINK_AP

		UPDATE T_KT SET RB = R1.R_SUM
		FROM #ACCT_IN_KT T_KT
		LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON AP.AP_CODE = T_KT.AC
		LEFT JOIN (SELECT CASE 
					WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
					WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END AS R_SUM,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END AS AP
			FROM dbo.ARestTableByDate (@dDateSTART, @nSel_Spr1) R
			INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
			INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
			WHERE R.DEP_LINK = @DEP_LINK
			GROUP BY S_ACTIVE, S_PASSIVE,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END
			) 
				AS R1 ON R1.AP = AP.LINK_AP

		-- Исходящие ---
		UPDATE T_DB SET RE = R1.R_SUM
		FROM #ACCT_IN_DB T_DB
		LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON AP.AP_CODE = T_DB.AC
		LEFT JOIN (SELECT CASE 
					WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
					WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END AS R_SUM,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END AS AP
			FROM dbo.ARestTableByDate (@dDATE_REST_E, @nSel_Spr1) R
			INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
			INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
			WHERE R.DEP_LINK = @DEP_LINK
			GROUP BY S_ACTIVE, S_PASSIVE,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END
			) 
				AS R1 ON AP = AP.LINK_AP

		UPDATE T_KT SET RE = R1.R_SUM
		FROM #ACCT_IN_KT T_KT
		LEFT JOIN dbo.BK_GetTableDictionByAP (@strCODE_AP) AP ON AP.AP_CODE = T_KT.AC
		LEFT JOIN (SELECT CASE 
					WHEN S_ACTIVE = 1 THEN SUM (D_SUMMA)
					WHEN S_PASSIVE = 1 THEN SUM (K_SUMMA)
				END AS R_SUM,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END AS AP
			FROM dbo.ARestTableByDate (@dDATE_REST_E, @nSel_Spr1) R
			INNER JOIN @TAB_KBK KBK ON (KBK.LINK_KBK = ISNULL (R.KBK, 0))
			INNER JOIN dbo.S_ACCOUNTS SA ON (R.ACCOUNT = SA.LINK)
			WHERE R.DEP_LINK = @DEP_LINK
			GROUP BY S_ACTIVE, S_PASSIVE,
				CASE
					WHEN @strCODE_AP = 'EKR' THEN ISNULL (R.EKR, 0)
					WHEN @strCODE_AP = 'KAU' THEN ISNULL (R.KAU, 0)
				END
			) 
				AS R1 ON R1.AP = AP.LINK_AP
	END

	EXEC dbo.X_GET_TABLE_NAME @cCROSS_TABLE_DB OUTPUT
	EXEC dbo.X_GET_TABLE_NAME @cCROSS_TABLE_KT OUTPUT

	EXEC dbo.M_CROSS_TABLE 'DATE_OP, JO_NUM, NAME_OPER, REST_B, REST_E, DATE_E', 'AC', 'VARCHAR (60)', 'SS, RB, RE',
			'NUMERIC (28,4)#NUMERIC (28,4)#NUMERIC (28,4)', 'SUM (SS) AS SS, 0 AS RB, 0 AS RE',
			'#ACCT_IN_DB', @cCROSS_TABLE_DB

	EXEC dbo.M_CROSS_TABLE 'DATE_OP, JO_NUM, NAME_OPER, REST_B, REST_E, DATE_E', 'AC', 'VARCHAR (60)', 'SS, RB, RE',
			'NUMERIC (28,4)#NUMERIC (28,4)#NUMERIC (28,4)', 'SUM (SS) AS SS, 0 AS RB, 0 AS RE',
			'#ACCT_IN_KT', @cCROSS_TABLE_KT

	--- Готовим для вывода счет ДБ ---
	SET @intCOUNTER = (SELECT COUNT (DISTINCT AC) FROM #ACCT_IN_DB)
	SET @intCOUNTER = ISNULL (@intCOUNTER, 0)
	SET @intCOUNT_COLROW = @intCOUNTER

	WHILE @intCOUNTER < @intMAX_REC
	BEGIN
		SET @intCOUNTER = @intCOUNTER + 1
		SET @cCOUNTER = LTRIM (STR (@intCOUNTER))
		SET @cSQL_STR = 'ALTER TABLE ' + @cCROSS_TABLE_DB
			+ ' ADD AC_' + @cCOUNTER + ' VARCHAR (60) '
			+ ', SS_' + @cCOUNTER + ' [NUMERIC] (28,4)'
			+ ', RB_' + @cCOUNTER + ' [NUMERIC] (28,4)'
			+ ', RE_' + @cCOUNTER + ' [NUMERIC] (28,4)'
		EXECUTE (@cSQL_STR)
	END 

	SET @intCOUNTER = 0
	WHILE @intCOUNTER < @intCOUNT_COLROW
	BEGIN
		SET @intCOUNTER = @intCOUNTER + 1
		SET @cCOUNTER = LTRIM (STR (@intCOUNTER))
		SET @cSQL_STR = 'DECLARE @SUM_RB NUMERIC (28,4), @SUM_RE NUMERIC (28,4), @KEY_FIELD VARCHAR (20)' + CHAR (10)
			+ 'SET @KEY_FIELD = (SELECT TOP 1 AC_' + @cCOUNTER + ' FROM ' + @cCROSS_TABLE_DB + ')' + CHAR (10) 
			+ 'SET @SUM_RB = (SELECT TOP 1 RB FROM #ACCT_IN_DB WHERE AC =  @KEY_FIELD)' + CHAR (10)
			+ 'SET @SUM_RE = (SELECT TOP 1 RE FROM #ACCT_IN_DB WHERE AC =  @KEY_FIELD)' + CHAR (10)
			+ 'UPDATE ' + @cCROSS_TABLE_DB + ' SET RB_' + @cCOUNTER + ' = ISNULL (@SUM_RB, 0), RE_'
				+ @cCOUNTER + ' = ISNULL (@SUM_RE, 0)'
		EXECUTE (@cSQL_STR)
	END

	IF @intCOUNT_COLROW = 0
		EXEC ('INSERT INTO ' + @cCROSS_TABLE_DB + ' (NAME_OPER) VALUES ('''') ')

	--- Готовим для вывода КТ ---
	SET @intCOUNTER = (SELECT COUNT (DISTINCT AC) FROM #ACCT_IN_KT)
	SET @intCOUNTER = ISNULL (@intCOUNTER, 0)
	SET @intCOUNT_COLROW = @intCOUNTER
	WHILE @intCOUNTER < @intMAX_REC
	BEGIN
		SET @intCOUNTER = @intCOUNTER + 1
		SET @cCOUNTER = LTRIM (STR (@intCOUNTER))
		SET @cSQL_STR = 'ALTER TABLE ' + @cCROSS_TABLE_KT
			+ ' ADD AC_' + @cCOUNTER + ' VARCHAR (60) '
			+ ', SS_' + @cCOUNTER + ' [NUMERIC] (28,4)'
			+ ', RB_' + @cCOUNTER + ' [NUMERIC] (28,4)'
			+ ', RE_' + @cCOUNTER + ' [NUMERIC] (28,4)'
		EXECUTE (@cSQL_STR)
	END 

	SET @intCOUNTER = 0
	WHILE @intCOUNTER < @intCOUNT_COLROW
	BEGIN
		SET @intCOUNTER = @intCOUNTER + 1
		SET @cCOUNTER = LTRIM (STR (@intCOUNTER))
		SET @cSQL_STR = 'DECLARE @SUM_RB NUMERIC (28,4), @SUM_RE NUMERIC (28,4), @KEY_FIELD VARCHAR (20)' + CHAR (10)
			+ 'SET @KEY_FIELD = (SELECT TOP 1 AC_' + @cCOUNTER + ' FROM ' + @cCROSS_TABLE_KT + ')' + CHAR (10) 
			+ 'SET @SUM_RB = (SELECT TOP 1 RB' + ' FROM #ACCT_IN_KT WHERE AC =  @KEY_FIELD)' + CHAR (10)
			+ 'SET @SUM_RE = (SELECT TOP 1 RE' + ' FROM #ACCT_IN_KT WHERE AC =  @KEY_FIELD)' + CHAR (10)
--			+ 'IF @SUM_RB IS NOT NULL OR @SUM_RE IS NOT NULL' + CHAR(10)
			+ 'UPDATE ' + @cCROSS_TABLE_KT + ' SET RB_' + @cCOUNTER + ' = ISNULL (@SUM_RB, 0), RE_'
				+ @cCOUNTER + ' = ISNULL (@SUM_RE, 0)'
--PRINT (@cSQL_STR)
		EXECUTE (@cSQL_STR)
	END

	IF @intCOUNT_COLROW = 0
		EXEC ('INSERT INTO ' + @cCROSS_TABLE_KT + ' (NAME_OPER) VALUES ('''') ')

	SELECT LINK,
		CODE AS ACCT_CODE,
		[NAME] AS ACCT_NAME,
		ISNULL (@DEP_OKPO, '') AS DEP_OKPO,
		ISNULL (@DEP_NAME, '') AS DEP_NAME,
		ISNULL (@GLBUH_NAME, '') AS GLBUH_NAME
	FROM dbo.S_ACCOUNTS
	WHERE LINK = @nSel_Spr1

	EXEC ('SELECT CONVERT (VARCHAR (10), DATE_OP, 104) AS DATE_OP_C, * FROM ' + @cCROSS_TABLE_DB)
	EXEC ('SELECT CONVERT (VARCHAR (10), DATE_OP, 104) AS DATE_OP_C, * FROM ' + @cCROSS_TABLE_KT)

	DROP TABLE #ACCT_IN_DB
	DROP TABLE #ACCT_IN_KT
	EXEC ('DROP TABLE ' + @cCROSS_TABLE_DB)
	EXEC ('DROP TABLE ' + @cCROSS_TABLE_KT)
END






GO


GRANT EXECUTE ON dbo.[BK_REPORT_MANYGRAPH_CARD] TO PUBLIC

GO



GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_UNLOAD_EXPORT_MODEL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].BB_UNLOAD_EXPORT_MODEL
GO



CREATE PROCEDURE dbo.BB_UNLOAD_EXPORT_MODEL @varKSModelLink INT -- ВЫГРУЗКА МОДЕЛЕЙ
as
DECLARE 
	@varKSBlockLink INT,
	@varKSModelCode VARCHAR(5),
	@varKSModelVer  VARCHAR(10)
declare @tTemp table (TXT varchar(8000), ord int identity)

insert into @tTemp(TXT)
SELECT 'update EXPORT_MODELS set DATE_END   = ' + isnull('''' + convert(varchar(10),MO1.DATE_END,104) + '''', 'NULL') 
	+ ' where MODEL_VER = ''' + RTRIM(MO1.Model_Ver) + ''' AND CODE = ''' + RTRIM(MO1.Code) + ''''
FROM dbo.EXPORT_MODELS M1
inner join dbo.EXPORT_MODELS MO1 on MO1.CODE = M1.CODE and MO1.DATE_END is not null
WHERE M1.link_model = @varKSModelLink and MO1.MODEL_VER = (
	SELECT max(MO.MODEL_VER) 
	FROM dbo.EXPORT_MODELS M
	inner join dbo.EXPORT_MODELS MO on MO.CODE = M.CODE AND MO.link_model <> M.link_model
	WHERE M.link_model = @varKSModelLink)

insert into @tTemp(TXT)
SELECT 'DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = ''' + RTRIM(Model_Ver) + ''' AND CODE = ''' + RTRIM(Code) + '''
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT ''' + RTRIM(CODE) + ''',''' + RTRIM(NAME) + ''',''' + RTRIM(MODEL_VER) + ''',' + RTRIM(CONVERT(VARCHAR(10),ISONCE)) + ','''
		+ RTRIM(isnull(NORM_DOC,'')) + ''',''' + RTRIM(isnull(FILE_NAME_MASK,'')) + ''',''' + RTRIM(isnull(FILE_NAME_PROC,'')) + ''','''
		+ RTRIM(isnull(PROC_EXP,'')) + ''',''' + RTRIM(isnull(PROC_DOP_PARAM,'')) + ''',''' + RTRIM(isnull(DEP_NAME,'')) + ''',''' + RTRIM(isnull(PROG_SAVE,'')) + ''','
		+ isnull('''' + convert(varchar(10),DATE_END,104) + '''', 'NULL') + ' 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = ' + RTRIM(CONVERT(VARCHAR(10),ISONCE)) + ',
		NAME   = ''' + RTRIM(isnull(NAME,'')) + ''',
		NORM_DOC   = ''' + RTRIM(isnull(NORM_DOC,'')) + ''',
		FILE_NAME_MASK   = ''' + RTRIM(isnull(FILE_NAME_MASK,'')) + ''',
		FILE_NAME_PROC   = ''' + RTRIM(isnull(FILE_NAME_PROC,'')) + ''',
		PROC_EXP   = ''' + RTRIM(isnull(PROC_EXP,'')) + ''',
		PROC_DOP_PARAM   = ''' + RTRIM(isnull(PROC_DOP_PARAM,'')) + ''',
		PROG_SAVE   = ''' + RTRIM(isnull(PROG_SAVE,'')) + ''',
		DEP_NAME   = ''' + RTRIM(isnull(DEP_NAME,'')) + ''',
		DATE_END   = ' + isnull('''' + convert(varchar(10),DATE_END,104) + '''', 'NULL') + '
	where LINK_MODEL = @varKSModelLink'
FROM dbo.EXPORT_MODELS 
WHERE LINK_MODEL = @varKSModelLink

DECLARE BLOC_CUR CURSOR LOCAL STATIC READ_ONLY FOR
SELECT DISTINCT LINK_BLOCK 
FROM dbo.EXPORT_BLOCKS
WHERE LINK_MODEL = @varKSModelLink

OPEN BLOC_CUR
FETCH NEXT FROM BLOC_CUR INTO @varKSBlockLink

WHILE @@FETCH_STATUS = 0
BEGIN
	insert into @tTemp(TXT)
	SELECT 'set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = ''' + RTRIM(CODE) + '''
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,''' + RTRIM(CODE) + ''',' + RTRIM(ORDERS) + ',' + RTRIM(CONVERT(VARCHAR(10),ISONCE)) + ',''' + RTRIM(NAME) + ''',' + RTRIM(CONVERT(VARCHAR(10),OBLIGATORY)) + '
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = ' + RTRIM(ORDERS) + ',
			ISONCE = ' + RTRIM(CONVERT(VARCHAR(10),ISONCE)) + ',
			NAME   = ''' + RTRIM(NAME) + ''',
			OBLIGATORY = ' + RTRIM(CONVERT(VARCHAR(10),OBLIGATORY)) + '
	where LINK_BLOCK = @varKSBlockLink'
	FROM EXPORT_BLOCKS
	WHERE LINK_BLOCK = @varKSBlockLink
	--select @varKSBlockLink
	insert into @tTemp(TXT)
	SELECT 'if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = ''' + RTRIM(EF.CODE) + ''')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= ' + RTRIM(CONVERT(VARCHAR(10),EF.ORDERS)) + ',
		NAME   		= ''' + RTRIM(ISNULL(EF.NAME,'NULL')) + ''',
		VAL_TYPE 	= ''' + RTRIM(EF.VAL_TYPE) + ''',
		VAL_LEN 	= ' + RTRIM(ISNULL(CONVERT(VARCHAR(10),EF.VAL_LEN),'NULL')) + ',
		VAL_LEN_EQ	= ' + RTRIM(CONVERT(VARCHAR(10),EF.VAL_LEN_EQ)) + ',
		NEED_CHECK	= ' + RTRIM(CONVERT(VARCHAR(10),EF.NEED_CHECK)) + ',
		OBLIGATORY	= ' + RTRIM(CONVERT(VARCHAR(10),EF.OBLIGATORY)) + ',
		ALIAS_CODE	= ''' + RTRIM(ISNULL(EF.ALIAS_CODE,'NULL')) + ''',
		CHECK_PROC	= ''' + RTRIM(EF.CHECK_PROC) + ''',
		VAL_LIST	= ''' + RTRIM(EF.VAL_LIST) + '''
	where LINK_BLOCK = @varKSBlockLink and CODE = ''' + RTRIM(EF.CODE) + '''
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, ' + RTRIM(CONVERT(VARCHAR(10),EF.ORDERS)) + ',''' + RTRIM(EF.CODE) + ''',''' + RTRIM(ISNULL(EF.NAME,'NULL')) + ''',''' + RTRIM(EF.VAL_TYPE) + ''',' + RTRIM(ISNULL(CONVERT(VARCHAR(10),EF.VAL_LEN),'NULL')) + ',' + RTRIM(CONVERT(VARCHAR(10),EF.VAL_LEN_EQ)) + ',' + RTRIM(CONVERT(VARCHAR(10),EF.NEED_CHECK)) + ',' + RTRIM(CONVERT(VARCHAR(10),EF.OBLIGATORY)) + ',''' + RTRIM(ISNULL(EF.ALIAS_CODE,'NULL')) + ''',''' + RTRIM(EF.CHECK_PROC) + ''',''' + RTRIM(EF.VAL_LIST) + ''''
	FROM EXPORT_FIELDS EF
	WHERE EF.LINK_BLOCK = @varKSBlockLink
	order by ORDERS
	FETCH NEXT FROM BLOC_CUR INTO @varKSBlockLink
END
CLOSE BLOC_CUR
DEALLOCATE BLOC_CUR
insert into @tTemp (TXT)
select 'GO'

SELECT TXT as [TEXT] from @tTemp order by ord


 


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RK_CALC_TN_2015]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RK_CALC_TN_2015]

GO
-- Расчет транспотного налога 2015
CREATE PROCEDURE dbo.RK_CALC_TN_2015
	@intDEP_LINK	INT,		-- !!!ПАРАМЕТР!!! ---
	@PERIOD_BEGIN	DATETIME,	-- НАЧАЛО НАЛОГОВОГО ПЕРИОДА
	@PERIOD_END	DATETIME	-- КОНЕЦ НАЛОГОВОГО ПЕРИОДА,
AS 
BEGIN

	DECLARE 
		@intPERIOD_MONTH	INT, 
		@REC_NO INT,
		@DATE_REG DATETIME,
		@DATE_UNREG DATETIME,
		@COL6 NUMERIC (10,2),	-- МОЩНОСТЬ
		@COL12 NUMERIC (10,2),
		@COL10 NUMERIC (10,2), 	-- СТАВКА ТРАНС. НАЛОГА
    	@COL11 NUMERIC (10,2), 	-- Доля в праве 
		@COL114 NUMERIC (20,2), 	-- СУММА К УПЛАТЕ
		@MONTH_USED INT,
		@DATECALC_BEGIN DATETIME,
		@DATECALC_END DATETIME,
		@intORDERS	INT
		

-- exec RK_CALC_TN_2015 74578, '20150101', '20151231'

	SET @intPERIOD_MONTH = DATEDIFF (MONTH, @PERIOD_BEGIN, @PERIOD_END) + 1
	
	DECLARE @TAB_RET TABLE
				(REC_NO INT IDENTITY,
				COL2 VARCHAR (10), 	-- вид ТС
				COL3 VARCHAR (30), 	-- VIN ТС
				COL4 VARCHAR (100), 	-- МАРКА ТС
				COL5 VARCHAR (20), 	-- НОМЕР ТС
				COL6 NUMERIC (10,2),	-- МОЩНОСТЬ
				COL7 VARCHAR (20), 	-- ЕИ(КОД) МОЩНОСТИ ТС
				COL8 VARCHAR (1),	-- ЭКОЛОГИЧЕСКИЙ КЛАСС
				COL9 INT,	-- КОЛ-ВО ЛЕТ, С МОМЕНТА ВЫПУСКА ТС
				COL10	INT,	-- КОЛ-ВО МЕС-ЦЕВ ВЛАДЕНИЯ ТС
				COL11	VARCHAR (21),	-- доля налогоплательщика в праве на транспортное средство
				COL12	NUMERIC (7,4),	-- КОЭФ-Т КВ
				COL13 NUMERIC (10,2), 	-- СТАВКА ТРАНС. НАЛОГА
				COL14	NUMERIC (3,1),	-- КОЭФ-Т КП
				COL15 NUMERIC (20,2), 	-- СУММА ИСЧИСЛЕННОГО НАЛОГА ТС
				COL16	INT,	-- КОЛ-ВО ИСПОЛЬ-ИЯ ЛЬГОТЫ
				COL17	NUMERIC (7,4),	-- КОЭФ-Т КЛ
				COL18 VARCHAR (100), 	-- КОД НАЛОГОВОЙ ЛЬГОТЫ ОСВ. ТС
				COL19 NUMERIC (20,2), 	-- СУММА ЛЬГОТЫ ОСВ.
				COL20 VARCHAR (100), 	-- КОД НАЛОГОВОЙ ЛЬГОТЫ УМ. ТС
				COL21 NUMERIC (20,2), 	-- СУММА ЛЬГОТЫ УМ.
				COL22 VARCHAR (100), 	-- КОД НАЛОГОВОЙ ЛЬГОТЫ СНИЖ. ТС
				COL23 NUMERIC (20,2), 	-- СУММА ЛЬГОТЫ СНИЖ.
				COL24 NUMERIC (20,2), 	-- К УПЛАТЕ.

				DATE_REG DATETIME,	-- ДАТА РЕГИСТРАЦИИ ТС
				DATE_UNREG DATETIME,	-- ДАТА СНЯТИЯ ТС,
				MONTH_USED	NUMERIC (10,2),
				ORDERS INT DEFAULT (0)
		)

	INSERT INTO @TAB_RET (
			COL2,
			COL3,
			COL4,
			COL5,
			COL6,
			COL7,
			COL8,
			COL9,
			COL10,
			COL11,
			COL12,
			COL13,
			COL14,
			COL15,
			COL16,
			COL17,
			COL18,
			COL19,
			COL20,
			COL21,
			COL22,
			COL23,
			COL24,
			DATE_REG,
			DATE_UNREG,
			MONTH_USED
		)

	SELECT
		ISNULL (dbo.BV_GetInvChar3 (INV.LINK, DEFAULT, 'GROUP_CODE'), ''),	-- вид ТС
		ISNULL (dbo.BV_GetInvChar3 (INV.LINK, DEFAULT, 'VIN_CODE'), ''),	-- VIN ТС
		ISNULL (dbo.BV_GetInvChar3 (INV.LINK, DEFAULT, 'AUTO_MARK'), ''),	-- МАРКА ТС
		ISNULL (dbo.BV_GetInvChar3 (INV.LINK, DEFAULT, 'AUTO_NUM'), ''),	-- ГОС. НОМЕР ТС
		ISNULL (dbo.BV_GetInvChar4 (INV.LINK, DEFAULT, 'HORSEPOWER'), 0),	-- МОЩНОСТЬ
	    '251',	-- ЕИ ТС,
		'',	-- ЭК.КЛАСС
		CASE	-- лет с выпуска
			WHEN ASS.DATE_PROD IS NOT NULL AND ASS.DATE_PROD < @PERIOD_BEGIN
				THEN YEAR (@PERIOD_BEGIN) - YEAR (ASS.DATE_PROD) + 1
			ELSE 0	
		END,
		0,	-- 
		ISNULL (dbo.BV_GetInvChar3(INV.LINK, DEFAULT, 'AUTO_SHARE_TAXPAYER'), ''),
		0,
		
		ISNULL (dbo.BV_GetInvChar4 (INV.LINK, DEFAULT, 'STAVKA_TNALOG'), 0.00),	-- СТАВКА ТРАНС. НАЛОГА
		CASE WHEN inv.BALANCE BETWEEN 3000000.0 AND 4999999.0 
			 THEN (CASE WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) = 2 
						THEN 1.1 
						WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) = 1 
						THEN 1.3
						WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) < 1  
						THEN 1.5 
					ELSE 1
			       END ) 
			 WHEN inv.BALANCE BETWEEN 5000000.0 AND 9999999.0  
			 THEN  (CASE WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) < 5
						THEN 2 
						ELSE 1
			       END )  
			 WHEN inv.BALANCE BETWEEN 10000000.0 AND 14999999.0 
			 THEN (CASE WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) < 10
						THEN 3
						ELSE 1
			       END )
			 WHEN inv.BALANCE >= 15000000.0	
			 then (CASE WHEN (SELECT TOP 1 years from dbo.DateDiffReal(DATE_PROD, @PERIOD_END)) < 20
						THEN 3
						ELSE 1
			       END )
			 ELSE 1 end	,
		0,
		0,
		0,
		'',  -- ISNULL (dbo.BV_GetInvChar3 (LINK, DEFAULT, 'AUTO_NUM'), ''),	-- КОД НАЛОГОВОЙ ЛЬГОТЫ ТС
		0,
		'',
		0,
		'',
		0,
		0,
		dbo.BV_GetInvChar1 (INV.LINK, DEFAULT, 'DATE_REG_TC'), 	-- ДАТА РЕГИСТРАЦИИ ТС
		dbo.BV_GetInvChar1 (INV.LINK, DEFAULT, 'DATE_UNREG_TC'),	-- ДАТА СНЯТИЯ ТС
		0
	FROM dbo.INVENTORY_CARD INV
	INNER JOIN dbo.ASSETS ASS ON (ASS.LINK_UP = INV.LINK)
	WHERE DEP_LINK = @intDEP_LINK
		AND CODE_GRP LIKE '101_5%'

 -- select * from @TAB_RET
-- select * from ASSETS

	-- РАСЧЕТ -- 
	DECLARE @COL11_T VARCHAR (21)
	SET @intORDERS = 0
	DECLARE #CALC_CURSOR CURSOR FOR
		SELECT
			REC_NO,
			DATE_REG,
			DATE_UNREG ,
			COL11
		FROM @TAB_RET
		WHERE (DATE_REG IS NULL
				OR DATE_REG <= @PERIOD_END)
			AND (DATE_UNREG IS NULL
				OR DATE_UNREG >= @PERIOD_BEGIN)
			AND COL6 > 0
	OPEN #CALC_CURSOR
	FETCH #CALC_CURSOR
		INTO @REC_NO, @DATE_REG, @DATE_UNREG, @COL11_T
	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @DATECALC_BEGIN = CASE
						WHEN @DATE_REG BETWEEN @PERIOD_BEGIN AND @PERIOD_END THEN @DATE_REG
						WHEN @DATE_REG < @PERIOD_BEGIN THEN @PERIOD_BEGIN
					END
	
		SET @DATECALC_END = CASE
						WHEN @DATE_UNREG IS NULL OR @DATE_UNREG > @PERIOD_END THEN @PERIOD_END
						WHEN @DATE_UNREG BETWEEN @PERIOD_BEGIN AND @PERIOD_END THEN @DATE_UNREG
					END
	
		SET @MONTH_USED = ISNULL (DATEDIFF (MONTH, @DATECALC_BEGIN, @DATECALC_END) + 1, 0)
		SET @COL12 = ISNULL (CONVERT (NUMERIC (10,2), @MONTH_USED)/@intPERIOD_MONTH, 0)

		SET @COL11 = ISNULL (CONVERT (NUMERIC (10,2), substring(@COL11_T,1,charindex('/',@COL11_T)-1))/ CONVERT (NUMERIC (10,2), substring(@COL11_T,charindex('/',@COL11_T)+1,len(@COL11_T))),0)	

		SET @intORDERS = @intORDERS + 1

		UPDATE @TAB_RET
		SET COL12 = @COL12,
			COL15 = @COL12 * COL6 * COL13 * @COL11 * COL14,
			ORDERS = @intORDERS ,
			COL10 = @MONTH_USED
		WHERE REC_NO = @REC_NO
	
		FETCH #CALC_CURSOR
			INTO @REC_NO, @DATE_REG, @DATE_UNREG, @COL11_T
	END
	CLOSE #CALC_CURSOR
	DEALLOCATE #CALC_CURSOR

	
	SELECT 
		RIGHT ('000' + RTRIM (CONVERT (VARCHAR (20), ORDERS)), 3) AS CODE, 
		RIGHT ('000' + RTRIM (CONVERT (VARCHAR (20), ORDERS)), 3) AS COL1,
		COL2,
		COL3,
		COL4,
		COL5,
		COL6,
		COL7,
		COL8,
		COL9,
		COL10,
		COL11,
		COL12,
		COL13,
		COL14,
		COL15,
		COL16,
		COL17,
		COL18,
		COL19,
		COL20,
		COL21,
		COL22,
		COL23,
		COL24
	FROM @TAB_RET
	WHERE ORDERS > 0
	ORDER BY ORDERS

END


GO


GRANT EXECUTE ON dbo.[RK_CALC_TN_2015] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_PRINT_TABEL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_PRINT_TABEL]

GO

CREATE   PROCEDURE dbo.SA_PRINT_TABEL
	@varKSnLINKDoc INT,
	@varKSnOption1 INT= 1,
	@varKSnCheck1 INT = 0,
	@nSort3 int = 0 /*сортировка 3*/,
	@nCheck3 tinyint = 0 /*Фио полностью*/,
	@nCheck5 tinyint = 0 /* Пустой табель */,
	@varKSSUBDIV VARCHAR(254) OUTPUT, 
	@varKSSUBDIV_CODE VARCHAR(10) OUTPUT,
	@varKSDIV_CODE VARCHAR(10) OUTPUT, 
	@varKSDIV_NAME VARCHAR(254) OUTPUT,
	@varKSTI_CODE VARCHAR(10) OUTPUT, 
	@varKSTI_NAME VARCHAR(254) OUTPUT,
	@varKSEXP_CODE VARCHAR(10) OUTPUT, 
	@varKSEXP_NAME VARCHAR(254) OUTPUT

AS
BEGIN

	declare @varKSdDate1 DATETIME, @varKSdDate2 DATETIME
	SELECT @varKSdDate1 = PERIOD FROM TABELS WHERE LINK_DOC = @varKSnLINKDoc
	SELECT @varKSdDate1 = dbo.DateBeginOfMonth(@varKSdDate1)
	SELECT @varKSdDate2 = dbo.DateEndOfMonth(@varKSdDate1)

	CREATE TABLE #T_RES00 (
		ID VARCHAR(20),
		LINK_FACE INT, 
		LINK_EMPL INT,
		LINK_SOVM INT,
		FIO VARCHAR(254),
		NAME_EMPL VARCHAR(254),
		TN VARCHAR(10) ,
		SUBDIV_LINK INT, 
		CODE_SUB VARCHAR(10),
		SUBDIV VARCHAR(254) ,
		POST_LINK INT,
		CODE_POST VARCHAR(10),
		POST VARCHAR(254) ,
		LINK_DAY INT,
		SYMB VARCHAR(4),
		DAY_1 CHAR(2),	DAY_2 CHAR(2),	DAY_3 CHAR(2),	DAY_4 CHAR(2),	DAY_5 CHAR(2),
		DAY_6 CHAR(2),	DAY_7 CHAR(2),	DAY_8 CHAR(2),	DAY_9 CHAR(2),	DAY_10 CHAR(2),
		DAY_11 CHAR(2),	DAY_12 CHAR(2),	DAY_13 CHAR(2),	DAY_14 CHAR(2),	DAY_15 CHAR(2),
		DAY_16 CHAR(2),	DAY_17 CHAR(2),	DAY_18 CHAR(2),	DAY_19 CHAR(2),	DAY_20 CHAR(2),
		DAY_21 CHAR(2),	DAY_22 CHAR(2),	DAY_23 CHAR(2),	DAY_24 CHAR(2),	DAY_25 CHAR(2),
		DAY_26 CHAR(2),	DAY_27 CHAR(2),	DAY_28 CHAR(2),	DAY_29 CHAR(2),	DAY_30 CHAR(2),
		DAY_31 CHAR(2),
		
		H_1 NUMERIC(6,2),  H_2 NUMERIC(6,2),  H_3 NUMERIC(6,2),  H_4 NUMERIC(6,2),  H_5 NUMERIC(6,2),  H_6 NUMERIC(6,2),
		H_7 NUMERIC(6,2),  H_8 NUMERIC(6,2),  H_9 NUMERIC(6,2),  H_10 NUMERIC(6,2), H_11 NUMERIC(6,2), H_12 NUMERIC(6,2),
		H_13 NUMERIC(6,2), H_14 NUMERIC(6,2), H_15 NUMERIC(6,2), H_16 NUMERIC(6,2), H_17 NUMERIC(6,2), H_18 NUMERIC(6,2),
		H_19 NUMERIC(6,2), H_20 NUMERIC(6,2), H_21 NUMERIC(6,2), H_22 NUMERIC(6,2), H_23 NUMERIC(6,2), H_24 NUMERIC(6,2),
		H_25 NUMERIC(6,2), H_26 NUMERIC(6,2), H_27 NUMERIC(6,2), H_28 NUMERIC(6,2), H_29 NUMERIC(6,2), H_30 NUMERIC(6,2),
		H_31 NUMERIC(6,2),
		
		HALF_D INT, HALF_H NUMERIC(6,2), 	
		HALF2_D INT, HALF2_H NUMERIC(6,2), 	
		ALL_D INT, ALL_H NUMERIC(6,2), 		
		NONE_DAYS INT, NONE_HOURS NUMERIC(6,2)	,
		
		TYPE_1 INT, TYPE_1H NUMERIC(6,2), TYPE_2H INT, TYPE_2 INT, TYPE_3 INT, TYPE_4 INT, TYPE_5 INT, TYPE_6 INT, 
		TYPE_7 INT, TYPE_8 INT, TYPE_9 INT, TYPE_10 INT, TYPE_11 INT, TYPE_12 INT,

		TYPE_13 INT,	-- ОТРАБОТАНО В МЕСЯЦ СВЕРУХРОЧНЫХ ЧАСОВ
		TYPE_14 INT,	-- ОТРАБОТАНО В МЕСЯЦ НОЧНЫХ ЧАСОВ
		TYPE_15 INT,	-- ОТРАБОТАНО В МЕСЯЦ ЧАСОВ В ВЫХОДНЫЕ И ПРАЗДНИЧНЫЕ ДНИ
	) 

	---
	DECLARE @ISMINUTES TINYINT
	SET @ISMINUTES = DBO.SA_GET_OPTION_BY_CODE('TABEL_OPT10') --УЧЕТ ВРЕМЕНИ В ЧАСАХ И МИНУТАХ

	---
	declare @def_tdlink int, @def_tdname varchar(254), @def_tdsymb varchar(4)
	Select @def_tdlink = LINK, @def_tdname = [NAME], @def_tdsymb = SYMB from dbo.TYP_DAYS where WORK_D = 1 AND TYP_YAVKA = 1

	select  LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY], 
		SUM([HOUR]) as [HOUR], 
		MAX(WORK_D) as WORK_D,
		MAX(TYP_YAV) AS TYP_YAV,
		(CASE when count(TYPE_DAY) = 1 then MAX(TYPE_DAY) else @def_tdlink end) as TYPE_DAY,
		(CASE when count(SYMB) = 1 then MAX(SYMB) else @def_tdsymb end) as SYMB,	
		(CASE when count(SYMB) = 1 then MAX(TYPE_DATY_NAME) else @def_tdname end) as TYPE_DATY_NAME
	into #tabel 
	from TABEL WHERE LINK_DOC = @varKSnLINKDoc
	group by LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY]
--	having count(SYMB) > 1
--AND TYPE_DAY not in (Select KOD from [dbo].[SA_TYPES_DOP_TAB])

	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_H1 = 
		CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END,

	DAYS_H2 = 
		CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
	+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END,

	HORS_H1 = SUM(W.D1) + SUM(W.D2) + SUM(W.D3) + SUM(W.D4) + SUM(W.D5) + SUM(W.D6) + SUM(W.D7) + SUM(W.D8) + SUM(W.D9) + SUM(W.D10) + SUM(W.D11) + SUM(W.D12) + SUM(W.D13) + SUM(W.D14) + SUM(W.D15),
	HORS_H2 = SUM(W.D16) + SUM(W.D17) + SUM(W.D18) + SUM(W.D19) + SUM(W.D20) + SUM(W.D21) + SUM(W.D22) + SUM(W.D23) + SUM(W.D24) + SUM(W.D25) + SUM(W.D26) + SUM(W.D27) + SUM(W.D28) + SUM(W.D29) + SUM(W.D30) + SUM(W.D31)
		
	INTO 
		#WORK_DAYS
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM

	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_Y7 = 
			CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
		+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END
	INTO 
		#WORK_DAYS1
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
		AND
		TYP_YAVKA = 7
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM			

	--- Информация о неявках сотрудников
	SELECT 
		N.LINK_UP1,
		T.WORK_D,
		COUNT_DAYS = 
			CASE WHEN N.D1 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D2 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D3 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D4 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D5 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D6 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D7 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D8 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D9 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D10 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D11 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D12 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D13 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D14 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D15 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D16 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D17 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D18 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D19 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D20 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D21 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D22 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D23 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D24 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D25 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D26 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D27 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D28 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D29 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D30 = T.LINK THEN 1 ELSE 0 END 
			+ CASE WHEN N.D31 = T.LINK THEN 1 ELSE 0 END 
	INTO 
		#NOTWORK_DAYS
	FROM
		DBO.SA_TABELS_N N, DBO.TYP_DAYS T
	WHERE
		LINK_UP = @varKSnLINKDoc

	---
	INSERT INTO #T_RES00
		(ID,LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST,
		LINK_DAY,
		SYMB,
		DAY_1,  DAY_2,  DAY_3,  DAY_4,  DAY_5,  DAY_6,  DAY_7,  DAY_8,  DAY_9,  DAY_10, 
		DAY_11, DAY_12, DAY_13, DAY_14, DAY_15, DAY_16, DAY_17, DAY_18, DAY_19, DAY_20, 
		DAY_21, DAY_22, DAY_23, DAY_24, DAY_25, DAY_26, DAY_27, DAY_28, DAY_29, DAY_30,
		DAY_31,
		H_1,  H_2, H_3,  H_4,  H_5,  H_6,  H_7,  H_8,  H_9,  H_10, 
		H_11, H_12, H_13, H_14, H_15, H_16, H_17, H_18, H_19, H_20, 
		H_21, H_22, H_23, H_24, H_25, H_26, H_27, H_28, H_29, H_30, 
		H_31,
		HALF_D, HALF_H,
		HALF2_D, HALF2_H,
		ALL_D, ALL_H,
		NONE_DAYS, NONE_HOURS,
		TYPE_1, TYPE_1H, TYPE_2, TYPE_2H, TYPE_3, TYPE_4, TYPE_5, TYPE_6, 
		TYPE_7, TYPE_8, TYPE_9, TYPE_10, TYPE_11, TYPE_12,

		TYPE_13,TYPE_14,TYPE_15

	)
	SELECT
		ID = RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_EMPL),10) +RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_SOVM),10) ,
		[LINK_FACE] = P.LINK,
		WP.LINK_EMPL,
		WP.LINK_SOVM,
		[FIO]  = (case when coalesce(@nCheck3,0) = 1 then  coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),'Не заполнено'))),100), SPACE(100)) 
					else coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30), SPACE(100)) end),
		[NAME_EMPL] = LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30),
		[TN] 		= ISNULL(TE.TAB, SPACE(10)),
		[SUBDIV_LINK] = TE.SUBDIV_LINK,
		[CODE_SUB] = ISNULL( TE.SUBDIV_CODE, SPACE(10) ),
		[SUBDIV] = ISNULL( TE.SUBDIV_NAME, SPACE(254) ),
		[POST_LINK] = WP.POST_LINK,
		[CODE_POST] = ISNULL( WP.POST_CODE, SPACE(10) ),
		[POST] 		= ISNULL( WP.POST_NAME, SPACE(120) ),
		W.LINK_DAY,		
		W.SYMB,
		[DAY_1] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB1, SPACE(2) ) end,
		[DAY_2] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB2, SPACE(2) ) end,
		[DAY_3] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB3, SPACE(2) ) end,
		[DAY_4] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB4, SPACE(2) ) end,
		[DAY_5] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB5, SPACE(2) ) end,
		[DAY_6] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB6, SPACE(2) ) end,
		[DAY_7] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB7, SPACE(2) ) end,
		[DAY_8] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB8, SPACE(2) ) end,
		[DAY_9] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB9, SPACE(2) ) end,
		[DAY_10] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB10, SPACE(2) ) end,

		[DAY_11] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB11, SPACE(2) ) end,
		[DAY_12] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB12, SPACE(2) ) end,
		[DAY_13] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB13, SPACE(2) ) end,
		[DAY_14] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB14, SPACE(2) ) end,
		[DAY_15] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB15, SPACE(2) ) end,
		[DAY_16] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB16, SPACE(2) ) end,
		[DAY_17] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB17, SPACE(2) ) end,
		[DAY_18] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB18, SPACE(2) ) end,
		[DAY_19] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB19, SPACE(2) ) end,
		[DAY_20] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB20, SPACE(2) ) end,

		[DAY_21] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB21, SPACE(2) ) end,
		[DAY_22] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB22, SPACE(2) ) end,
		[DAY_23] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB23, SPACE(2) ) end,
		[DAY_24] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB24, SPACE(2) ) end,
		[DAY_25] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB25, SPACE(2) ) end,
		[DAY_26] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB26, SPACE(2) ) end,
		[DAY_27] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB27, SPACE(2) ) end,
		[DAY_28] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB28, SPACE(2) ) end,
		[DAY_29] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB29, SPACE(2) ) end,
		[DAY_30] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB30, SPACE(2) ) end,
		[DAY_31] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB31, SPACE(2) ) end,

		[H1] = case when @nCheck5 = 1 then 0 else W.D1 end, 
		[H2] = case when @nCheck5 = 1 then 0 else W.D2 end,
		[H3] = case when @nCheck5 = 1 then 0 else W.D3 end,
		[H4] = case when @nCheck5 = 1 then 0 else W.D4 end, 
		[H5] = case when @nCheck5 = 1 then 0 else W.D5 end,
		[H6] = case when @nCheck5 = 1 then 0 else W.D6 end,
		[H7] = case when @nCheck5 = 1 then 0 else W.D7 end,  
		[H8] = case when @nCheck5 = 1 then 0 else W.D8 end, 
		[H9] = case when @nCheck5 = 1 then 0 else W.D9 end, 
		[H10] = case when @nCheck5 = 1 then 0 else W.D10 end,

		[H11] = case when @nCheck5 = 1 then 0 else W.D11 end,
		[H12] = case when @nCheck5 = 1 then 0 else W.D12 end, 
		[H13] = case when @nCheck5 = 1 then 0 else W.D13 end, 
		[H14] = case when @nCheck5 = 1 then 0 else W.D14 end, 
		[H15] = case when @nCheck5 = 1 then 0 else W.D15 end, 
		[H16] = case when @nCheck5 = 1 then 0 else W.D16 end, 
		[H17] = case when @nCheck5 = 1 then 0 else W.D17 end, 
		[H18] = case when @nCheck5 = 1 then 0 else W.D18 end, 
		[H19] = case when @nCheck5 = 1 then 0 else W.D19 end, 
		[H20] = case when @nCheck5 = 1 then 0 else W.D20 end, 

		[H21] = case when @nCheck5 = 1 then 0 else W.D21 end, 
		[H22] = case when @nCheck5 = 1 then 0 else W.D22 end, 
		[H23] = case when @nCheck5 = 1 then 0 else W.D23 end, 
		[H24] = case when @nCheck5 = 1 then 0 else W.D24 end, 
		[H25] = case when @nCheck5 = 1 then 0 else W.D25 end, 
		[H26] = case when @nCheck5 = 1 then 0 else W.D26 end, 
		[H27] = case when @nCheck5 = 1 then 0 else W.D27 end, 
		[H28] = case when @nCheck5 = 1 then 0 else W.D28 end, 
		[H29] = case when @nCheck5 = 1 then 0 else W.D29 end, 
		[H30] = case when @nCheck5 = 1 then 0 else W.D30 end, 
		[H31] = case when @nCheck5 = 1 then 0 else W.D31 end, 
--
		[HALF_D] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H1,0) end, 
		[HALF_H] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H1,0) end,

		[HALF_D2] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H2,0) end,
		[HALF_H2] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H2,0) end,

		[ALL_D] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H1,0) + isnull(WD.DAYS_H2,0) end,
		[ALL_H] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H1,0) + isnull(WD.HORS_H2,0) end,

		[NONE_DAYS] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (4, 5, 6, 7, 8, 9, 10, 13)) end ) end,
		[NONE_HOURS] = case when @nCheck5 = 1 then 0 else 0 end,

		--Дни явок		
		[TYPE_1] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else COALESCE(WD.DAYS_H1,0) + COALESCE(WD.DAYS_H2,0) end) end,
		--Часы явок
		[TYPE_1H] =  case when @nCheck5 = 1 then 0 else 
			DBO.MINUTES_TO_NUM( 
			DBO.NUM_TO_MINUTES(W.D1,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D2,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D3,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D4,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D5,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D6,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D7,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D8,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D9,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D10,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D11,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D12,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D13,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D14,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D15,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D16,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D17,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D18,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D19,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D20,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D21,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D22,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D23,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D24,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D25,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D26,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D27,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D28,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D29,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D30,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D31,@ISMINUTES)
		,@ISMINUTES) end,

		[TYPE_2] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 2) end,		-- командировка (дни)
		[TYPE_2H] = 0,	-- командировка (часы)
		[TYPE_3] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 3),0) + ISNULL(Y.DAYS_Y7,0) end,		-- повышение квалификации (дни)
		[TYPE_4] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 4) end,		-- очередной ежегодный отпуск НЕЯВКА (дни)
		[TYPE_5] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 5) end,		-- учебный отпуск НЕЯВКА (дни)
		[TYPE_6] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 6) end,		-- больничный НЕЯВКА (дни)
		[TYPE_7] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (7,13)) end, 	-- уход за ребенком НЕЯВКА (дни)
		[TYPE_8] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 8) end,		-- с разрешения администрации НЕЯВКА (дни)
		[TYPE_9] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 9) end,		-- прогул НЕЯВКА (дни)
		[TYPE_10] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 10) end,	-- невыясненные причины НЕЯВКА (дни)
		[TYPE_11] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (11,14)) end ) end,	-- выходные и праздничые НЕЯВКА (дни)
		[TYPE_12] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 12) end,
		--
		[TYPE_13] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 4) end,	-- явка сверхурочно
		[TYPE_14] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 2) end, -- явка в ночное время
		[TYPE_15] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 3) end	-- явка в вызодные и праздничные
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN DBO.EMPL E ON E.LINK = TE.LINK_EMPL
		INNER JOIN DBO.PERSON P ON P.LINK = E.PERS_LINK
		LEFT JOIN DBO.SA_TABELS_N N ON TE.LINK = N.LINK_UP1
		LEFT JOIN DBO.SA_TABELS_W W ON TE.LINK = W.LINK_UP1 AND W.LINK_SOVM = WP.LINK_SOVM
		LEFT JOIN #WORK_DAYS WD ON TE.LINK = WD.LINK_UP1 AND WD.LINK_SOVM = WP.LINK_SOVM
		LEFT JOIN #WORK_DAYS1 Y ON TE.LINK = Y.LINK_UP1 AND WD.LINK_SOVM = Y.LINK_SOVM
	WHERE 
		T.LINK_DOC = @varKSnLINKDoc
	ORDER BY 
		1

IF (SELECT COUNT(DISTINCT SUBDIV_LINK) FROM #T_RES00) <> 1 BEGIN
		SELECT @varKSSUBDIV = '', @varKSSUBDIV_CODE = ''
	END
	ELSE 
		BEGIN
			SELECT TOP 1 @varKSSUBDIV = SUBDIV, @varKSSUBDIV_CODE = CODE_SUB FROM  #T_RES00
		END

	DECLARE 
		@varKSCNT1 INT, @varKSCNT2 INT, @varKSCNT3 INT
	
	SELECT TOP 1 
		@varKSCNT1 = COUNT(DISTINCT LINK_FKR_D), 
		@varKSCNT2 = COUNT(DISTINCT LINK_FKR_T), 
		@varKSCNT3 = COUNT(DISTINCT LINK_FKR_E),
		@varKSDIV_CODE = MAX(CODE_FKR_D),
		@varKSDIV_NAME = MAX(NAME_FKR_D),
		@varKSTI_CODE = MAX(CODE_FKR_T),
		@varKSTI_NAME = MAX(NAME_FKR_T),
		@varKSEXP_CODE = MAX(CODE_FKR_E),
		@varKSEXP_NAME = MAX(NAME_FKR_E)
	FROM DICTIONARY_PAYS_EMPL DPE
	INNER JOIN dbo.PAYS P ON DPE.LINK_PAYS = P.LINK
	INNER JOIN bi_diction_vkr VKR ON VKR.LINK = DPE.LINK_KBK
	INNER JOIN #T_RES00 R ON DPE.LINK_EMPL = R.LINK_EMPL
	where date_begin <= @varKSdDate2
		AND (DATE_END >= @varKSdDate1 OR DATE_END IS NULL) 


		declare @LINK_DEP int
		Set @LINK_DEP = Coalesce( (SELECT TOP 1 ZB_LINK FROM dbo.KS_OPTIONS_ZB), dbo.GetOwnDepLink())

		declare @nAVGCount numeric(18,2), @nMCount numeric(18,2)

		Select @nAVGCount = dbo.sa_ssch_empls(@varKSdDate1, @varKSdDate2, null, 0, 1, 0, DEFAULT)
		Select @nMCount = dbo.sa_sch_empls(@varKSdDate2, null, 0, 1, 0, DEFAULT)


	IF @varKSCNT1 <> 1
		SELECT @varKSDIV_CODE = '', @varKSDIV_NAME = ''
	IF @varKSCNT2 <> 1
		SELECT @varKSTI_CODE = '', @varKSTI_NAME = ''
	IF @varKSCNT3 <> 1
		SELECT @varKSEXP_CODE = '', @varKSEXP_NAME = ''

	SELECT *, @nAVGCount as AVGCount, @nMCount as MCount 
	FROM #T_RES00
	ORDER BY 
		LTRIM(RTRIM(CASE @varKSnOption1 
			WHEN 1 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 3 THEN POST
			WHEN 4 THEN FIO
			WHEN 5 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 6 THEN SUBDIV
			ELSE ''
		END)),

		LTRIM(RTRIM(CASE @varKSnCheck1 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN POST
			WHEN 5 THEN FIO
			WHEN 6 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN SUBDIV
			ELSE ''
		END)),
		
		LTRIM(RTRIM(CASE @nSort3 
			WHEN 2 THEN '' + REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN '' +POST
			WHEN 5 THEN '' +FIO
			WHEN 6 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN '' +SUBDIV
			ELSE ''
		END))

END










GO


GRANT EXECUTE ON dbo.[SA_PRINT_TABEL] TO PUBLIC

GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_PRINT_TABEL_421m]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_PRINT_TABEL_421m]

GO

CREATE   PROCEDURE dbo.SA_PRINT_TABEL_421m
	@varKSnLINKDoc INT,
	@varKSnOption1 INT= 1,
	@varKSnCheck1 INT = 0,
	@nSort3 int = 0 /*сортировка 3*/,
	@nCheck3 tinyint = 0 /*Фио полностью*/,
	@nCheck5 tinyint = 0 /* Пустой табель */,
	@varKSSUBDIV VARCHAR(254) OUTPUT, 
	@varKSSUBDIV_CODE VARCHAR(10) OUTPUT,
	@varKSDIV_CODE VARCHAR(10) OUTPUT, 
	@varKSDIV_NAME VARCHAR(254) OUTPUT,
	@varKSTI_CODE VARCHAR(10) OUTPUT, 
	@varKSTI_NAME VARCHAR(254) OUTPUT,
	@varKSEXP_CODE VARCHAR(10) OUTPUT, 
	@varKSEXP_NAME VARCHAR(254) OUTPUT

AS
BEGIN

	declare @varKSdDate1 DATETIME, @varKSdDate2 DATETIME
	SELECT @varKSdDate1 = PERIOD FROM TABELS WHERE LINK_DOC = @varKSnLINKDoc
	SELECT @varKSdDate1 = dbo.DateBeginOfMonth(@varKSdDate1)
	SELECT @varKSdDate2 = dbo.DateEndOfMonth(@varKSdDate1)

	CREATE TABLE #T_RES00 (
		ID VARCHAR(20),
		LINK_FACE INT, 
		LINK_EMPL INT,
		LINK_SOVM INT,
		FIO VARCHAR(254),
		NAME_EMPL VARCHAR(254),
		TN VARCHAR(10) ,
		SUBDIV_LINK INT, 
		CODE_SUB VARCHAR(10),
		SUBDIV VARCHAR(254) ,
		POST_LINK INT,
		CODE_POST VARCHAR(10),
		POST VARCHAR(254) ,
		
		DAY_1 VARCHAR(4),	DAY_2 VARCHAR(4),	DAY_3 VARCHAR(4),	DAY_4 VARCHAR(4),	DAY_5 VARCHAR(4),
		DAY_6 VARCHAR(4),	DAY_7 VARCHAR(4),	DAY_8 VARCHAR(4),	DAY_9 VARCHAR(4),	DAY_10 VARCHAR(4),
		DAY_11 VARCHAR(4),	DAY_12 VARCHAR(4),	DAY_13 VARCHAR(4),	DAY_14 VARCHAR(4),	DAY_15 VARCHAR(4),
		DAY_16 VARCHAR(4),	DAY_17 VARCHAR(4),	DAY_18 VARCHAR(4),	DAY_19 VARCHAR(4),	DAY_20 VARCHAR(4),
		DAY_21 VARCHAR(4),	DAY_22 VARCHAR(4),	DAY_23 VARCHAR(4),	DAY_24 VARCHAR(4),	DAY_25 VARCHAR(4),
		DAY_26 VARCHAR(4),	DAY_27 VARCHAR(4),	DAY_28 VARCHAR(4),	DAY_29 VARCHAR(4),	DAY_30 VARCHAR(4),
		DAY_31 VARCHAR(4),
		
		--HALF_D INT, HALF_H NUMERIC(6,2), 	
		--HALF2_D INT, HALF2_H NUMERIC(6,2), 	
		--ALL_D INT, ALL_H NUMERIC(6,2), 		
		NONE_DAYS INT, 
		--NONE_HOURS NUMERIC(6,2)	,
		
		TYPE_1 INT, 
		--TYPE_1H NUMERIC(6,2),
		--TYPE_2H INT, 
		TYPE_2 NUMERIC(6,2), 
		TYPE_3 INT, TYPE_4 INT, TYPE_5 INT, TYPE_6 INT, TYPE_7 INT, TYPE_8 INT, TYPE_9 INT, 
		--TYPE_10 INT, 
		TYPE_11 INT, 
		--TYPE_12 INT,

		--TYPE_13 INT,	-- ОТРАБОТАНО В МЕСЯЦ СВЕРУХРОЧНЫХ ЧАСОВ
		--TYPE_14 INT,	-- ОТРАБОТАНО В МЕСЯЦ НОЧНЫХ ЧАСОВ
		--TYPE_15 INT,	-- ОТРАБОТАНО В МЕСЯЦ ЧАСОВ В ВЫХОДНЫЕ И ПРАЗДНИЧНЫЕ ДНИ
	) 

	---
	DECLARE @ISMINUTES TINYINT
	SET @ISMINUTES = DBO.SA_GET_OPTION_BY_CODE('TABEL_OPT10') --УЧЕТ ВРЕМЕНИ В ЧАСАХ И МИНУТАХ

	---
	declare @def_tdlink int, @def_tdname varchar(254), @def_tdsymb varchar(4)
	Select @def_tdlink = LINK, @def_tdname = [NAME], @def_tdsymb = SYMB from dbo.TYP_DAYS where WORK_D = 1 AND TYP_YAVKA = 1

	select  LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY], 
		SUM([HOUR]) as [HOUR], 
		MAX(WORK_D) as WORK_D,
		MAX(TYP_YAV) AS TYP_YAV,
		(CASE when count(TYPE_DAY) = 1 then MAX(TYPE_DAY) else @def_tdlink end) as TYPE_DAY,
		(CASE when count(SYMB) = 1 then MAX(SYMB) else @def_tdsymb end) as SYMB,	
		(CASE when count(SYMB) = 1 then MAX(TYPE_DATY_NAME) else @def_tdname end) as TYPE_DATY_NAME
	into #tabel 
	from TABEL WHERE LINK_DOC = @varKSnLINKDoc
	group by LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY]
--	having count(SYMB) > 1
--AND TYPE_DAY not in (Select KOD from [dbo].[SA_TYPES_DOP_TAB])

	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_H1 = 
		CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END,

	DAYS_H2 = 
		CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
	+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END,
	

	[HOURS] = 
			DBO.MINUTES_TO_NUM( 
			SUM(
			DBO.NUM_TO_MINUTES(W.D1,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D2,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D3,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D4,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D5,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D6,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D7,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D8,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D9,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D10,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D11,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D12,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D13,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D14,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D15,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D16,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D17,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D18,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D19,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D20,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D21,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D22,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D23,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D24,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D25,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D26,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D27,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D28,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D29,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D30,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D31,@ISMINUTES)
		)
		,@ISMINUTES)
	INTO 
		#WORK_DAYS
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM
		
	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_Y7 = 
			CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
		+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END
	INTO 
		#WORK_DAYS1
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
		AND
		TYP_YAVKA = 7
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM		

	--- Информация о неявках сотрудников
	SELECT 
		N.LINK_UP1,
		T.WORK_D,
		COUNT_DAYS = 
			CASE WHEN N.D1 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D2 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D3 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D4 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D5 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D6 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D7 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D8 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D9 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D10 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D11 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D12 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D13 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D14 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D15 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D16 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D17 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D18 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D19 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D20 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D21 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D22 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D23 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D24 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D25 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D26 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D27 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D28 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D29 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D30 = T.LINK THEN 1 ELSE 0 END 
			+ CASE WHEN N.D31 = T.LINK THEN 1 ELSE 0 END 
	INTO 
		#NOTWORK_DAYS
	FROM
		DBO.SA_TABELS_N N, DBO.TYP_DAYS T
	WHERE
		LINK_UP = @varKSnLINKDoc

	CREATE TABLE #WS (LINK_EMPL INT, LINK_SOVM INT,
		W1 VARCHAR(6), W2 VARCHAR(6), W3 VARCHAR(6), W4 VARCHAR(6), W5 VARCHAR(6), W6 VARCHAR(6), W7 VARCHAR(6), W8 VARCHAR(6), W9 VARCHAR(6), W10 VARCHAR(6),
		W11 VARCHAR(6), W12 VARCHAR(6), W13 VARCHAR(6), W14 VARCHAR(6), W15 VARCHAR(6), W16 VARCHAR(6), W17 VARCHAR(6), W18 VARCHAR(6), W19 VARCHAR(6), W20 VARCHAR(6), 
		W21 VARCHAR(6), W22 VARCHAR(6), W23 VARCHAR(6), W24 VARCHAR(6), W25 VARCHAR(6), W26 VARCHAR(6), W27 VARCHAR(6), W28 VARCHAR(6), W29 VARCHAR(6), W30 VARCHAR(6), W31 VARCHAR(6)
		)
	---
	INSERT INTO #WS
	SELECT 
		WP.LINK_EMPL, WP.LINK_SOVM, 
		W1 = LEFT(MAX(CASE WHEN W.D1 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W2 = LEFT(MAX(CASE WHEN W.D2 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W3 = LEFT(MAX(CASE WHEN W.D3 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W4 = LEFT(MAX(CASE WHEN W.D4 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W5 = LEFT(MAX(CASE WHEN W.D5 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W6 = LEFT(MAX(CASE WHEN W.D6 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W7 = LEFT(MAX(CASE WHEN W.D7 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W8 = LEFT(MAX(CASE WHEN W.D8 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W9 = LEFT(MAX(CASE WHEN W.D9 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W10 = LEFT(MAX(CASE WHEN W.D10 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),

		W11 = LEFT(MAX(CASE WHEN W.D11 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W12 = LEFT(MAX(CASE WHEN W.D12 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W13 = LEFT(MAX(CASE WHEN W.D13 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W14 = LEFT(MAX(CASE WHEN W.D14 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W15 = LEFT(MAX(CASE WHEN W.D15 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W16 = LEFT(MAX(CASE WHEN W.D16 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W17 = LEFT(MAX(CASE WHEN W.D17 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W18 = LEFT(MAX(CASE WHEN W.D18 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W19 = LEFT(MAX(CASE WHEN W.D19 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W20 = LEFT(MAX(CASE WHEN W.D20 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),

		W21 = LEFT(MAX(CASE WHEN W.D21 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W22 = LEFT(MAX(CASE WHEN W.D22 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W23 = LEFT(MAX(CASE WHEN W.D23 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W24 = LEFT(MAX(CASE WHEN W.D24 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W25 = LEFT(MAX(CASE WHEN W.D25 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W26 = LEFT(MAX(CASE WHEN W.D26 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W27 = LEFT(MAX(CASE WHEN W.D27 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W28 = LEFT(MAX(CASE WHEN W.D28 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W29 = LEFT(MAX(CASE WHEN W.D29 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),
		W30 = LEFT(MAX(CASE WHEN W.D30 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6),

		W31 = LEFT(MAX(CASE WHEN W.D31 <> 0 THEN SPACE((ISNULL(DOP_TAB-1,0))*2) + SYMB ELSE '' END),6)
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		LEFT JOIN DBO.TABELS_W W ON TE.LINK = W.link_up AND WP.LINK_SOVM = COALESCE(W.link_sovm,0)
		LEFT JOIN dbo.TYP_DAYS TD ON TD.LINK = W.LINK_DAY
	WHERE			
		T.LINK_DOC = @varKSnLINKDoc
	GROUP BY 
		WP.LINK_EMPL, WP.LINK_SOVM		
	ORDER BY
		 WP.LINK_EMPL, WP.LINK_SOVM

	---
	CREATE TABLE #S (LINK_EMPL INT, LINK_SOVM INT,
		W1 VARCHAR(4), W2 VARCHAR(4), W3 VARCHAR(4), W4 VARCHAR(4), W5 VARCHAR(4), W6 VARCHAR(4), W7 VARCHAR(4), W8 VARCHAR(4), W9 VARCHAR(4), W10 VARCHAR(4),
		W11 VARCHAR(4), W12 VARCHAR(4), W13 VARCHAR(4), W14 VARCHAR(4), W15 VARCHAR(4), W16 VARCHAR(4), W17 VARCHAR(4), W18 VARCHAR(4), W19 VARCHAR(4), W20 VARCHAR(4), 
		W21 VARCHAR(4), W22 VARCHAR(4), W23 VARCHAR(4), W24 VARCHAR(4), W25 VARCHAR(4), W26 VARCHAR(4), W27 VARCHAR(4), W28 VARCHAR(4), W29 VARCHAR(4), W30 VARCHAR(4), W31 VARCHAR(4)
		 )	

	INSERT INTO #S (LINK_EMPL, LINK_SOVM, W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15, W16, W17, W18, W19, W20, W21, W22, W23, W24, W25, W26, W27, W28, W29, W30, W31 )
	SELECT 
		T.LINK_EMPL, T.LINK_SOVM,
		LTRIM(RTRIM(MAX(W1))), LTRIM(RTRIM(MAX(W2))), LTRIM(RTRIM(MAX(W3))), LTRIM(RTRIM(MAX(W4))), LTRIM(RTRIM(MAX(W5))), LTRIM(RTRIM(MAX(W6))), LTRIM(RTRIM(MAX(W7))), LTRIM(RTRIM(MAX(W8))), LTRIM(RTRIM(MAX(W9))), LTRIM(RTRIM(MAX(W10))), 
		LTRIM(RTRIM(MAX(W11))), LTRIM(RTRIM(MAX(W12))), LTRIM(RTRIM(MAX(W13))), LTRIM(RTRIM(MAX(W14))), LTRIM(RTRIM(MAX(W15))), LTRIM(RTRIM(MAX(W16))), LTRIM(RTRIM(MAX(W17))), LTRIM(RTRIM(MAX(W18))), LTRIM(RTRIM(MAX(W19))), LTRIM(RTRIM(MAX(W20))), 
		LTRIM(RTRIM(MAX(W21))), LTRIM(RTRIM(MAX(W22))), LTRIM(RTRIM(MAX(W23))), LTRIM(RTRIM(MAX(W24))), LTRIM(RTRIM(MAX(W25))), LTRIM(RTRIM(MAX(W26))), LTRIM(RTRIM(MAX(W27))), LTRIM(RTRIM(MAX(W28))), LTRIM(RTRIM(MAX(W29))), LTRIM(RTRIM(MAX(W30))), LTRIM(RTRIM(MAX(W31))) 
	FROM
	(	
		SELECT 
			LINK_EMPL, LINK_SOVM, W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15, W16, W17, W18, W19, W20, W21, W22, W23, W24, W25, W26, W27, W28, W29, W30, W31 
		FROM #WS
		UNION ALL
		SELECT 
			WP.LINK_EMPL, WP.LINK_SOVM, 
			SPACE(4) + ISNULL(SYMB1,''), SPACE(4) + ISNULL(SYMB2,''), SPACE(4) + ISNULL(SYMB3,''), SPACE(4) + ISNULL(SYMB4,''), SPACE(4) + ISNULL(SYMB5,''), SPACE(4) + ISNULL(SYMB6,''), SPACE(4) + ISNULL(SYMB7,''), SPACE(4) + ISNULL(SYMB8,''), SPACE(4) + ISNULL(SYMB9,''), SPACE(4) + ISNULL(SYMB10,''),
			SPACE(4) + ISNULL(SYMB11,''), SPACE(4) + ISNULL(SYMB12,''), SPACE(4) + ISNULL(SYMB13,''), SPACE(4) + ISNULL(SYMB14,''), SPACE(4) + ISNULL(SYMB15,''), SPACE(4) + ISNULL(SYMB16,''), SPACE(4) + ISNULL(SYMB17,''), SPACE(4) + ISNULL(SYMB18,''), SPACE(4) + ISNULL(SYMB19,''), SPACE(4) + ISNULL(SYMB20,''), 
			SPACE(4) + ISNULL(SYMB21,''), SPACE(4) + ISNULL(SYMB22,''), SPACE(4) + ISNULL(SYMB23,''), SPACE(4) + ISNULL(SYMB24,''), SPACE(4) + ISNULL(SYMB25,''), SPACE(4) + ISNULL(SYMB26,''), SPACE(4) + ISNULL(SYMB27,''), SPACE(4) + ISNULL(SYMB28,''), SPACE(4) + ISNULL(SYMB29,''), SPACE(4) + ISNULL(SYMB30,''), SPACE(4) + ISNULL(SYMB31,'')
		FROM 
			DBO.TABELS T 
			INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
			INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
			LEFT JOIN DBO.SA_TABELS_N N ON TE.LINK = N.LINK_UP1
		WHERE			
			T.LINK_DOC = @varKSnLINKDoc
	) T
	GROUP BY
		T.LINK_EMPL, T.LINK_SOVM
	ORDER BY 1,2

	
	INSERT INTO #T_RES00
		(ID,LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST,

		DAY_1,  DAY_2,  DAY_3,  DAY_4,  DAY_5,  DAY_6,  DAY_7,  DAY_8,  DAY_9,  DAY_10, 
		DAY_11, DAY_12, DAY_13, DAY_14, DAY_15, DAY_16, DAY_17, DAY_18, DAY_19, DAY_20, 
		DAY_21, DAY_22, DAY_23, DAY_24, DAY_25, DAY_26, DAY_27, DAY_28, DAY_29, DAY_30, DAY_31,
		
		NONE_DAYS, 

		TYPE_1, 

		TYPE_2, 

		TYPE_3, TYPE_4, TYPE_5, TYPE_6, TYPE_7, TYPE_8, TYPE_9, 

		TYPE_11 

	)
	SELECT
		ID = RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_EMPL),10) +RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_SOVM),10) ,
		[LINK_FACE] = P.LINK,
		WP.LINK_EMPL,
		WP.LINK_SOVM,
		[FIO]  = (case when coalesce(@nCheck3,0) = 1 then  coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),'Не заполнено'))),100), SPACE(100)) 
					else coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30), SPACE(100)) end),
		[NAME_EMPL] = LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30),
		[TN] 		= ISNULL(TE.TAB, SPACE(10)),
		[SUBDIV_LINK] = TE.SUBDIV_LINK,
		[CODE_SUB] = ISNULL( TE.SUBDIV_CODE, SPACE(10) ),
		[SUBDIV] = ISNULL( TE.SUBDIV_NAME, SPACE(254) ),
		[POST_LINK] = WP.POST_LINK,
		[CODE_POST] = ISNULL( WP.POST_CODE, SPACE(10) ),
		[POST] 		= ISNULL( WP.POST_NAME, SPACE(120) ),

		W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, 
		W11, W12, W13, W14, W15, W16, W17, W18, W19, W20, 
		W21, W22, W23, W24, W25, W26, W27, W28, W29, W30, W31, 
		--
		[NONE_DAYS] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1),0) end,
		--Дни явок		
		[TYPE_1] = case when @nCheck5 = 1 then 0 else ISNULL(WD.DAYS_H1,0) + ISNULL(WD.DAYS_H2,0) end,
		----Часы явок
		[TYPE_2] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 2),0) + ISNULL(Y.DAYS_Y7,0) end,		-- командировка (дни)
		[TYPE_3] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 3),0) end,		-- повышение квалификации (дни)
		[TYPE_4] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 4),0) end,		-- очередной ежегодный отпуск НЕЯВКА (дни)
		[TYPE_5] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 5),0) end,		-- учебный отпуск НЕЯВКА (дни)
		[TYPE_6] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 6),0) end,		-- больничный НЕЯВКА (дни)
		[TYPE_7] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (7,13)),0) end, 	-- уход за ребенком НЕЯВКА (дни)
		[TYPE_8] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 8),0) end,		-- с разрешения администрации НЕЯВКА (дни)
		[TYPE_9] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 9),0) end,		-- прогул НЕЯВКА (дни)
		[TYPE_11] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (11,14)),0) end	-- выходные и праздничые НЕЯВКА (дни)
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN DBO.EMPL E ON E.LINK = TE.LINK_EMPL
		INNER JOIN DBO.PERSON P ON P.LINK = E.PERS_LINK
		LEFT JOIN #S S ON WP.LINK_EMPL = S.LINK_EMPL AND WP.LINK_SOVM = S.LINK_SOVM
		LEFT JOIN #WORK_DAYS WD ON TE.LINK = WD.LINK_UP1 AND WD.LINK_SOVM = WP.LINK_SOVM
		LEFT JOIN #WORK_DAYS1 Y ON TE.LINK = Y.LINK_UP1 AND Y.LINK_SOVM = WP.LINK_SOVM
	WHERE 
		T.LINK_DOC = @varKSnLINKDoc
	ORDER BY 
		1

IF (SELECT COUNT(DISTINCT SUBDIV_LINK) FROM #T_RES00) <> 1 BEGIN
		SELECT @varKSSUBDIV = '', @varKSSUBDIV_CODE = ''
	END
	ELSE 
		BEGIN
			SELECT TOP 1 @varKSSUBDIV = SUBDIV, @varKSSUBDIV_CODE = CODE_SUB FROM  #T_RES00
		END

	DECLARE 
		@varKSCNT1 INT, @varKSCNT2 INT, @varKSCNT3 INT
	
	SELECT TOP 1 
		@varKSCNT1 = COUNT(DISTINCT LINK_FKR_D), 
		@varKSCNT2 = COUNT(DISTINCT LINK_FKR_T), 
		@varKSCNT3 = COUNT(DISTINCT LINK_FKR_E),
		@varKSDIV_CODE = MAX(CODE_FKR_D),
		@varKSDIV_NAME = MAX(NAME_FKR_D),
		@varKSTI_CODE = MAX(CODE_FKR_T),
		@varKSTI_NAME = MAX(NAME_FKR_T),
		@varKSEXP_CODE = MAX(CODE_FKR_E),
		@varKSEXP_NAME = MAX(NAME_FKR_E)
	FROM DICTIONARY_PAYS_EMPL DPE
	INNER JOIN dbo.PAYS P ON DPE.LINK_PAYS = P.LINK
	INNER JOIN bi_diction_vkr VKR ON VKR.LINK = DPE.LINK_KBK
	INNER JOIN #T_RES00 R ON DPE.LINK_EMPL = R.LINK_EMPL
	where date_begin <= @varKSdDate2
		AND (DATE_END >= @varKSdDate1 OR DATE_END IS NULL) 


	declare @LINK_DEP int
	Set @LINK_DEP = Coalesce( (SELECT TOP 1 ZB_LINK FROM dbo.KS_OPTIONS_ZB), dbo.GetOwnDepLink())

	declare @nAVGCount numeric(18,2), @nMCount numeric(18,2)

	Select @nAVGCount = dbo.sa_ssch_empls(@varKSdDate1, @varKSdDate2, null, 0, 1, 0, DEFAULT)
	Select @nMCount = dbo.sa_sch_empls(@varKSdDate2, null, 0, 1, 0, DEFAULT)

	IF @varKSCNT1 <> 1
		SELECT @varKSDIV_CODE = '', @varKSDIV_NAME = ''
	IF @varKSCNT2 <> 1
		SELECT @varKSTI_CODE = '', @varKSTI_NAME = ''
	IF @varKSCNT3 <> 1
		SELECT @varKSEXP_CODE = '', @varKSEXP_NAME = ''

	SELECT *, @nAVGCount as AVGCount, @nMCount as MCount 
	FROM #T_RES00
	ORDER BY 
		LTRIM(RTRIM(CASE @varKSnOption1 
			WHEN 1 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 3 THEN POST
			WHEN 4 THEN FIO
			WHEN 5 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 6 THEN SUBDIV
			ELSE ''
		END)),

		LTRIM(RTRIM(CASE @varKSnCheck1 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN POST
			WHEN 5 THEN FIO
			WHEN 6 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN SUBDIV
			ELSE ''
		END)),
		
		LTRIM(RTRIM(CASE @nSort3 
			WHEN 2 THEN '' + REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN '' +POST
			WHEN 5 THEN '' +FIO
			WHEN 6 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN '' +SUBDIV
			ELSE ''
		END))

END


GO


GRANT EXECUTE ON dbo.[SA_PRINT_TABEL_421m] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[KIR_EXEC_SALARY_F49]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[KIR_EXEC_SALARY_F49]

GO

CREATE    PROCEDURE [dbo].KIR_EXEC_SALARY_F49
	@varKSnLink INT
AS BEGIN

	declare @opt_VEDOM_OPTIONS_VEDOM_NAME_PAYS tinyint -- Выводить краткое наименование начислений
	SET @opt_VEDOM_OPTIONS_VEDOM_NAME_PAYS = dbo.SA_GET_OPTION_BY_CODE('VEDOM_OPTIONS_VEDOM_NAME_PAYS')

	DECLARE @nMPAY tinyint -- Объединять начисления
	SET @nMPAY = dbo.SA_GET_OPTION_BY_CODE('VEDOM_OPTIONS_OPT12')

	CREATE TABLE #RES (LINK_EMPL INT, REF_PAY int, CP VARCHAR(11), NP VARCHAR(254), S NUMERIC(20,2) , sum_n NUMERIC(20,2) , s_other NUMERIC(20,2), LINK_EKR int, EKR_CODE varchar(3))
	CREATE TABLE #RES_U (LINK_EMPL2 INT, REF_PAY int, CU VARCHAR(10), NU VARCHAR(254), SU NUMERIC(20,2) , sum_U NUMERIC(20,2), sum_UOPL NUMERIC(20,2) , link_ekr_U INT, EKR_CODE_U varchar(3)  )

	INSERT INTO #RES
	SELECT T.LINK_EMPL, 
		LINK_PAYS = (CASE WHEN @nMPAY = 1 and P.LINK_MPAY is not null THEN MP.LINK ELSE P.LINK END),
		CODE_PAYS = CONVERT(VARCHAR(10), (CASE WHEN @nMPAY = 1 and P.LINK_MPAY is not null THEN MP.CODE ELSE P.CODE END)),
		NAME_PAYS = CONVERT(VARCHAR(254),(CASE WHEN @nMPAY = 1 and P.LINK_MPAY is not null THEN MP.NAME ELSE P.NAME END)),
		T.SUMMA, 
		0, 0,  T.LINK_EKR, T.EKR_CODE
	FROM 
		dbo.DOCUMENTS_DED_PR_TABLE2 T
		INNER JOIN dbo.PAYS P on P.link = T.REF_PAY
		LEFT JOIN dbo.PAYS MP on MP.link = P.LINK_MPAY
	WHERE 
		T.LINK = @varKSnLink AND TYP_PAY = 1
		
 
	UPDATE A
	Set 
		A.CP = LEFT(rtrim(ltrim(A.CP)) + (case rtrim(ltrim(A.EKR_CODE)) when '211' then 'Р' when '213' then 'Ф' else '' end),10), 
		A.NP = LEFT(rtrim(ltrim(A.NP)) + SPACE(1) + (case rtrim(ltrim(A.EKR_CODE)) when '211' then '(за счет работ-ля)' when '213' then '(за счет ФСС)' else '' end),254)
	from 
		#RES A inner join dbo.PAYS P on A.REF_PAY = P.LINK
	where 
		A.link_ekr is not null and P.way_calc in (13,20) and P.OBJECT = 1



	DECLARE @varKSTABLE_N VARCHAR(100), @varKSTABLE_U VARCHAR(120), @varKSTABLE_R VARCHAR(120)
	EXEC X_GET_TABLE_NAME @varKSTABLE_N OUTPUT
	SELECT @varKSTABLE_U = @varKSTABLE_N + '_U', @varKSTABLE_R = @varKSTABLE_N + '_R'

	INSERT INTO #RES_U
	SELECT LINK_EMPL, REF_PAY, CODE_PAY, NAME_PAY, SUMMA, 0, 0 , link_ekr , EKR_CODE
	FROM DOCUMENTS_DED_PR_TABLE2 WHERE LINK = @varKSnLink AND TYP_PAY = 2
	order by REF_PAY



	if @opt_VEDOM_OPTIONS_VEDOM_NAME_PAYS = 1
	Begin
		UPDATE #RES 
		Set #RES.NP = COALESCE(P.SNAME,'')
		from #RES D inner join dbo.Pays P on D.REF_PAY = P.link

		UPDATE #RES_U 
		Set #RES_U.NU = COALESCE(P.SNAME,'')
		from #RES_U D inner join dbo.Pays P on D.REF_PAY = P.link
	End

	UPDATE U 
		SET NU = 'Налог на доходы'
	from #RES_U U where rtrim(ltrim(u.NU)) = 'Подоходный налог'   

	---
	UPDATE R
	SET CP = CP + '*'
	FROM
		#RES R
		INNER JOIN dbo.PAYS P on P.LINK_MPAY = R.REF_PAY
	WHERE
		@nMPAY = 1

	--- 
	UPDATE #RES
	Set NP = CP + '#&' + NP

	--- 
	UPDATE #RES_U
	Set NU = CU + '#&' + NU

	DECLARE @varKSCNT_N INT, @varKSCNT_U INT
	SELECT @varKSCNT_N = COUNT(DISTINCT CP) FROM #RES 
	SELECT @varKSCNT_U = COUNT(DISTINCT CU) FROM #RES_U

	EXEC M_CROSS_TABLE
		'LINK_EMPL, SUM_N, S_OTHER, link_ekr,ekr_code', 
		'NP', 'VARCHAR(254)', 
		'S', 'NUMERIC(20,2)', 'SUM(S) AS S',
		'#RES', @varKSTABLE_N
	
	EXEC M_CROSS_TABLE
		'LINK_EMPL2, SUM_U, SUM_UOPL, link_ekr_U,ekr_code_U', 
		'NU', 'VARCHAR(254)', 
		'SU', 'NUMERIC(20,2)', 'SUM(SU) AS SU',
		'#RES_U', @varKSTABLE_U


		
	EXEC (' SELECT N.*, U.*   INTO ' +  @varKSTABLE_R +'  FROM ' + @varKSTABLE_N +  ' N FULL OUTER JOIN ' + @varKSTABLE_U + ' U 
		ON N.LINK_EMPL = U.LINK_EMPL2 and n.link_ekr = u.link_ekr_u ' )

	EXEC (' UPDATE ' +  @varKSTABLE_R + ' SET SUM_N = (SELECT SUM(S)  FROM #RES R WHERE R.LINK_EMPL = R0.LINK_EMPL and R.LINK_ekr = R0.LINK_ekr) FROM ' +   @varKSTABLE_R + ' R0 ')
	EXEC (' UPDATE ' +  @varKSTABLE_R + ' SET SUM_U= (SELECT SUM(SU)  FROM #RES_U R WHERE R.LINK_EMPL2   = R0.LINK_EMPL and R.LINK_EKR_U   = R0.LINK_EKR_U) FROM ' +   @varKSTABLE_R + ' R0 ')
	EXEC (' UPDATE ' +  @varKSTABLE_R + ' SET SUM_UOPL = (SELECT sum(DISBURS)  FROM DOCUMENTS_DED_PR_TABLE R WHERE r.LINK = '+ @varKSnLink +'  and R.REF_EMPL   = R0.LINK_EMPL and (R.LINK_EKR = R0.LINK_EKR or R.LINK_EKR = R0.LINK_EKR_U)) FROM ' +   @varKSTABLE_R + ' R0 ')

	DECLARE @varKSI INT, @varKSSQL_STR VARCHAR(4000), @varKSFIELD_NAME VARCHAR(100)
	SET @varKSI=1
	WHILE @varKSI <= @varKSCNT_N BEGIN

		SET @varKSFIELD_NAME= 'NP_'  +  RTRIM(LTRIM(STR(@varKSI)))
		SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_R + '  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_N + ' WHERE '+
			@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
		EXEC (@varKSSQL_STR)
		SET @varKSFIELD_NAME= 'S_'  +  RTRIM(LTRIM(STR(@varKSI)))
		SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_R + '  SET '+@varKSFIELD_NAME+ ' = 0  WHERE ' +
			@varKSFIELD_NAME+ '  IS  NULL ' 
		EXEC (@varKSSQL_STR)

		SET @varKSI=@varKSI+1
	END
	SET @varKSI=1
	WHILE @varKSI <= @varKSCNT_U BEGIN

		SET @varKSFIELD_NAME= 'NU_'  +  RTRIM(LTRIM(STR(@varKSI)))
		SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_R + '  SET '+@varKSFIELD_NAME+ ' = (SELECT TOP 1 '+@varKSFIELD_NAME+' FROM ' +@varKSTABLE_U + ' WHERE '+
			@varKSFIELD_NAME+ '  IS NOT NULL ) ' 
		EXEC (@varKSSQL_STR)
		SET @varKSFIELD_NAME= 'SU_'  +  RTRIM(LTRIM(STR(@varKSI)))
		SET @varKSSQL_STR= ' UPDATE '+@varKSTABLE_R + '  SET '+@varKSFIELD_NAME+ ' = 0  WHERE ' +
			@varKSFIELD_NAME+ '  IS  NULL ' 
		EXEC (@varKSSQL_STR)

		SET @varKSI=@varKSI+1
	END
	

	IF @varKSCNT_N = 0 BEGIN
		EXEC (' ALTER TABLE ' + @varKSTABLE_R + ' ADD CP_0 VARCHAR(10), NP_0_0 VARCHAR(254), S_0_0 numeric(20,2) ')
	END
	IF @varKSCNT_U = 0 BEGIN
		EXEC (' ALTER TABLE ' + @varKSTABLE_R + ' ADD CU_0 VARCHAR(10), NU_0_0 VARCHAR(254), SU_0_0 numeric(20,2) ')
	END

	DECLARE @varKSstr VARCHAR(7000), @varKScMODE VARCHAR(100)
	SET @varKSstr = DBO.OBJECT_VAR_GET_OBJECT_VALUE(
		'SALARY_QUERY_PAYROLL_N3',
		'QUERY_NASTR_VALUE',
		1
	)

	SET @varKScMODE = 'CAST( ' + CASE WHEN @varKSstr = 'ФИО' THEN '2' ELSE '1' END + ' AS INT) AS SORT_MODE'

	EXEC (' SELECT *, ' + @varKScMODE  +' FROM ' + @varKSTABLE_R)


	EXEC ('DROP TABLE ' + @varKSTABLE_N)
	EXEC ('DROP TABLE ' + @varKSTABLE_U)
	EXEC ('DROP TABLE ' + @varKSTABLE_R)
END







GO


GRANT EXECUTE ON dbo.[KIR_EXEC_SALARY_F49] TO PUBLIC

GO



GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_EXPORT_VP]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[BB_EXPORT_VP]
GO


CREATE                    PROCEDURE dbo.BB_EXPORT_VP
	@cBuffId	varchar(30) = '',
	@cFormat	varchar(30) = ''

AS

DECLARE @iDepLink	int
set @iDepLink = isnull(dbo.BK_GetDepZB(),dbo.GetOwnDepLink())

-- Таблица 2 (FROM)
SELECT 0 as link,
		0 as link_up,
		KOD_TOFK  = '0000',
		NAME_TOFK = space(2000)

-- Таблица 3 (TO)
SELECT 	0 as link,
		0 as link_up,
		-- Поля для приема выписки
		BUDG_LEVEL  = '0',
		KOD_UBP 	= '00000',
		NAME_UBP	= space(2000)



-- Таблица 4 (PP)
SELECT  LINK 	= 0,
		LINK_UP	= 0,
		LS = space(11),
		[DATE]	= convert(datetime,'20000101',104),
		GUID_FK = space(36)

SELECT  LINK 		= 0,
		LINK_UP		= 0,
		NUM_DOC		= space(15),
		DATE_DOC	= convert(datetime,'20000101',104),
		GUID		= space(36),
		NUM_DOC_UBP = space(15),
		DATE_DOC_UBP= convert(datetime,'20000101',104),
		FAIP_CODE = space(14),
		ADD_KLASS = space(20),
		SUM_OUT	= convert(numeric(18,2),0)




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

grant all on BB_EXPORT_VP to public
GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_PRINT_TABEL_148n]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_PRINT_TABEL_148n]

GO

CREATE   PROCEDURE dbo.SA_PRINT_TABEL_148n
	@varKSnLINKDoc INT,
	@varKSnOption1 INT= 1,
	@varKSnCheck1 INT = 0,
	@nSort3 int = 0 /*сортировка 3*/,
	@nCheck3 tinyint = 0 /*Фио полностью*/,
	@nCheck5 tinyint = 0 /* Пустой табель */,
	@varKSSUBDIV VARCHAR(254) OUTPUT, 
	@varKSSUBDIV_CODE VARCHAR(10) OUTPUT,
	@varKSDIV_CODE VARCHAR(10) OUTPUT, 
	@varKSDIV_NAME VARCHAR(254) OUTPUT,
	@varKSTI_CODE VARCHAR(10) OUTPUT, 
	@varKSTI_NAME VARCHAR(254) OUTPUT,
	@varKSEXP_CODE VARCHAR(10) OUTPUT, 
	@varKSEXP_NAME VARCHAR(254) OUTPUT

AS
BEGIN

	declare @varKSdDate1 DATETIME, @varKSdDate2 DATETIME
	SELECT @varKSdDate1 = PERIOD FROM TABELS WHERE LINK_DOC = @varKSnLINKDoc
	SELECT @varKSdDate1 = dbo.DateBeginOfMonth(@varKSdDate1)
	SELECT @varKSdDate2 = dbo.DateEndOfMonth(@varKSdDate1)

	---
	DECLARE @ISMINUTES TINYINT
	SET @ISMINUTES = DBO.SA_GET_OPTION_BY_CODE('TABEL_OPT10') --УЧЕТ ВРЕМЕНИ В ЧАСАХ И МИНУТАХ

	--
	DECLARE @PERIOD DATETIME
	SET @PERIOD = (SELECT TOP 1 PERIOD FROM DBO.TABELS T WHERE T.LINK_DOC = @varKSnLINKDoc)

	---РАСЧЁТ ОТКЛОНЕНИЙ
	CREATE TABLE #NOWORK (LINK_EMPL INT, LINK_SOVM INT, N_1 VARCHAR(10), N_2 VARCHAR(10), N_3 VARCHAR(10), N_4 VARCHAR(10), N_5 VARCHAR(10), N_6 VARCHAR(10), N_7 VARCHAR(10), N_8 VARCHAR(10), N_9 VARCHAR(10), N_10 VARCHAR(10), N_11 VARCHAR(10), N_12 VARCHAR(10), N_13 VARCHAR(10), N_14 VARCHAR(10), N_15 VARCHAR(10), N_16 VARCHAR(10), N_17 VARCHAR(10), N_18 VARCHAR(10), N_19 VARCHAR(10), N_20 VARCHAR(10), N_21 VARCHAR(10), N_22 VARCHAR(10), N_23 VARCHAR(10), N_24 VARCHAR(10), N_25 VARCHAR(10), N_26 VARCHAR(10), N_27 VARCHAR(10), N_28 VARCHAR(10), N_29 VARCHAR(10), N_30 VARCHAR(10), N_31 VARCHAR(10))

	INSERT INTO #NOWORK (LINK_EMPL, LINK_SOVM, N_1, N_2, N_3, N_4, N_5, N_6, N_7, N_8, N_9, N_10, N_11, N_12, N_13, N_14, N_15, N_16, N_17, N_18, N_19, N_20, N_21, N_22, N_23, N_24, N_25, N_26, N_27, N_28, N_29, N_30, N_31)
	SELECT WP.LINK_EMPL, WP.LINK_SOVM, SYMB1, SYMB2, SYMB3, SYMB4, SYMB5, SYMB6, SYMB7, SYMB8, SYMB9, SYMB10, SYMB11, SYMB12, SYMB13, SYMB14, SYMB15, SYMB16, SYMB17, SYMB18, SYMB19, SYMB20, SYMB21, SYMB22, SYMB23, SYMB24, SYMB25, SYMB26, SYMB27, SYMB28, SYMB29, SYMB30, SYMB31
	FROM
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN DBO.SA_TABELS_N N ON TE.LINK = N.LINK_UP1
	WHERE 
		T.LINK_DOC = @varKSnLINKDoc		
	ORDER BY 
		WP.LINK_EMPL, WP.LINK_SOVM	
	
	---СВЕДЕНИЯ ОБ ОТРАБОТАННОМ ВРЕМЕНИ ПО ГРАФИКАМ
	CREATE TABLE #WORK (LINK_EMPL INT, LINK_SOVM INT, [DAY] TINYINT, [HOURS] NUMERIC(5,2), DAY_TIP INT)
	INSERT INTO #WORK (LINK_EMPL, LINK_SOVM, [DAY], [HOURS], DAY_TIP)
	SELECT 
		WP.LINK_EMPL, WP.LINK_SOVM, GD.[DAY], GD.[HOURS], GD.DAY_TYPE 
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN dbo.GRAPHICS G ON G.GRAPH_LINK = WP.GRAPH_LINK AND YEAR(G.PERIOD) = YEAR(T.PERIOD) AND MONTH(G.PERIOD) = MONTH(T.PERIOD)
		INNER JOIN dbo.GRAPHIC_DAYS GD ON GD.LINK_UP=G.LINK
		INNER JOIN dbo.TYP_DAYS TD ON TD.LINK = GD.DAY_TYPE AND TD.WORK_D = 1
	WHERE 
		T.LINK_DOC = @varKSnLINKDoc
	ORDER BY 
		1

	CREATE INDEX #WORK_LINK_EMPL1 ON #WORK (LINK_EMPL ASC)
		
	---ОБЕСПЕЧИМ НАЛИЧИЕ ВСЕХ ЧИСЕЛ МЕСЯЦА
	DECLARE @I INT
	SET @I = 1
	WHILE @I <= 31 BEGIN
		INSERT INTO #WORK (LINK_EMPL, [DAY], [HOURS], DAY_TIP)
		VALUES (0, @I, 0, 0)
		SET @I = @I + 1
	END

	--
	DECLARE @VARKSTABLE VARCHAR(100)
	EXEC X_GET_TABLE_NAME @VARKSTABLE OUTPUT

	EXEC DBO.CROSSTAB @TABLE = #WORK, @TABLE2 = @VARKSTABLE, @ONROWS = 'LINK_EMPL,LINK_SOVM,DAY_TIP', @ONCOLS = [DAY], @SUMCOL = [HOURS]

	CREATE TABLE #WORK1 (LINK_EMPL INT, LINK_SOVM INT, DAY_TIP INT, C1 NUMERIC(5,2), C10 NUMERIC(5,2), C11 NUMERIC(5,2), C12 NUMERIC(5,2), C13 NUMERIC(5,2), C14 NUMERIC(5,2), C15 NUMERIC(5,2), C16 NUMERIC(5,2), C17 NUMERIC(5,2), C18 NUMERIC(5,2), C19 NUMERIC(5,2), C2 NUMERIC(5,2), C20 NUMERIC(5,2), C21 NUMERIC(5,2), C22 NUMERIC(5,2), C23 NUMERIC(5,2), C24 NUMERIC(5,2), C25 NUMERIC(5,2), C26 NUMERIC(5,2), C27 NUMERIC(5,2), C28 NUMERIC(5,2), C29 NUMERIC(5,2), C3 NUMERIC(5,2), C30 NUMERIC(5,2), C31 NUMERIC(5,2), C4 NUMERIC(5,2), C5 NUMERIC(5,2), C6 NUMERIC(5,2), C7 NUMERIC(5,2), C8 NUMERIC(5,2), C9  NUMERIC(5,2))

	EXEC ( '
	INSERT INTO #WORK1 (LINK_EMPL,LINK_SOVM,DAY_TIP,C1,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C2,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C3,C30,C31,C4,C5,C6,C7,C8,C9)
	SELECT LINK_EMPL,LINK_SOVM,DAY_TIP,C1,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C2,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C3,C30,C31,C4,C5,C6,C7,C8,C9
	FROM ' + @VARKSTABLE  + ' WHERE LINK_EMPL > 0')
	EXEC ('DROP TABLE ' + @VARKSTABLE)
	
	----------
	CREATE TABLE #WORK2 (LINK_EMPL INT, LINK_SOVM INT, DAY_TIP INT, O_1 VARCHAR(10), O_10 VARCHAR(10), O_11 VARCHAR(10), O_12 VARCHAR(10), O_13 VARCHAR(10), O_14 VARCHAR(10), O_15 VARCHAR(10), O_16 VARCHAR(10), O_17 VARCHAR(10), O_18 VARCHAR(10), O_19 VARCHAR(10), O_2 VARCHAR(10), O_20 VARCHAR(10), O_21 VARCHAR(10), O_22 VARCHAR(10), O_23 VARCHAR(10), O_24 VARCHAR(10), O_25 VARCHAR(10), O_26 VARCHAR(10), O_27 VARCHAR(10), O_28 VARCHAR(10), O_29 VARCHAR(10), O_3 VARCHAR(10), O_30 VARCHAR(10), O_31 VARCHAR(10), O_4 VARCHAR(10), O_5 VARCHAR(10), O_6 VARCHAR(10), O_7 VARCHAR(10), O_8 VARCHAR(10), O_9  VARCHAR(10))	

	INSERT INTO #WORK2 (LINK_EMPL,LINK_SOVM,DAY_TIP,O_1,O_2,O_3,O_4,O_5,O_6,O_7,O_8,O_9,O_10,O_11,O_12,O_13,O_14,O_15,O_16,O_17,O_18,O_19,O_20,O_21,O_22,O_23,O_24,O_25,O_26,O_27,O_28,O_29,O_30,O_31)
	SELECT 
		W1.LINK_EMPL, W1.LINK_SOVM, W1.DAY_TIP,
		O1 = ' ' + REPLACE((CASE WHEN ISNULL(C1,0) = ISNULL(D1,0) OR ISNULL(D1,0) = 0 AND NW.N_1 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D1,0)) END),'.00',''),
		O2 = ' ' + REPLACE((CASE WHEN ISNULL(C2,0) = ISNULL(D2,0) OR ISNULL(D2,0) = 0 AND NW.N_2 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D2,0)) END),'.00',''),
		O3 = ' ' + REPLACE((CASE WHEN ISNULL(C3,0) = ISNULL(D3,0) OR ISNULL(D3,0) = 0 AND NW.N_3 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D3,0)) END),'.00',''),
		O4 = ' ' + REPLACE((CASE WHEN ISNULL(C4,0) = ISNULL(D4,0) OR ISNULL(D4,0) = 0 AND NW.N_4 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D4,0)) END),'.00',''),
		O5 = ' ' + REPLACE((CASE WHEN ISNULL(C5,0) = ISNULL(D5,0) OR ISNULL(D5,0) = 0 AND NW.N_5 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D5,0)) END),'.00',''),
		O6 = ' ' + REPLACE((CASE WHEN ISNULL(C6,0) = ISNULL(D6,0) OR ISNULL(D6,0) = 0 AND NW.N_6 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D6,0)) END),'.00',''),
		O7 = ' ' + REPLACE((CASE WHEN ISNULL(C7,0) = ISNULL(D7,0) OR ISNULL(D7,0) = 0 AND NW.N_7 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D7,0)) END),'.00',''),
		O8 = ' ' + REPLACE((CASE WHEN ISNULL(C8,0) = ISNULL(D8,0) OR ISNULL(D8,0) = 0 AND NW.N_8 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D8,0)) END),'.00',''),
		O9 = ' ' + REPLACE((CASE WHEN ISNULL(C9,0) = ISNULL(D9,0) OR ISNULL(D9,0) = 0 AND NW.N_9 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D9,0)) END),'.00',''),
		O10 = ' ' + REPLACE((CASE WHEN ISNULL(C10,0) = ISNULL(D10,0) OR ISNULL(D10,0) = 0 AND NW.N_10 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D10,0)) END),'.00',''),

		O11 = ' ' + REPLACE((CASE WHEN ISNULL(C11,0) = ISNULL(D11,0) OR ISNULL(D11,0) = 0 AND NW.N_11 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D11,0)) END),'.00',''),
		O12 = ' ' + REPLACE((CASE WHEN ISNULL(C12,0) = ISNULL(D12,0) OR ISNULL(D12,0) = 0 AND NW.N_12 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D12,0)) END),'.00',''),
		O13 = ' ' + REPLACE((CASE WHEN ISNULL(C13,0) = ISNULL(D13,0) OR ISNULL(D13,0) = 0 AND NW.N_13 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D13,0)) END),'.00',''),
		O14 = ' ' + REPLACE((CASE WHEN ISNULL(C14,0) = ISNULL(D14,0) OR ISNULL(D14,0) = 0 AND NW.N_14 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D14,0)) END),'.00',''),
		O15 = ' ' + REPLACE((CASE WHEN ISNULL(C15,0) = ISNULL(D15,0) OR ISNULL(D15,0) = 0 AND NW.N_15 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D15,0)) END),'.00',''),
		O16 = ' ' + REPLACE((CASE WHEN ISNULL(C16,0) = ISNULL(D16,0) OR ISNULL(D16,0) = 0 AND NW.N_16 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D16,0)) END),'.00',''),
		O17 = ' ' + REPLACE((CASE WHEN ISNULL(C17,0) = ISNULL(D17,0) OR ISNULL(D17,0) = 0 AND NW.N_17 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D17,0)) END),'.00',''),
		O18 = ' ' + REPLACE((CASE WHEN ISNULL(C18,0) = ISNULL(D18,0) OR ISNULL(D18,0) = 0 AND NW.N_18 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D18,0)) END),'.00',''),
		O19 = ' ' + REPLACE((CASE WHEN ISNULL(C19,0) = ISNULL(D19,0) OR ISNULL(D19,0) = 0 AND NW.N_19 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D19,0)) END),'.00',''),
		O20 = ' ' + REPLACE((CASE WHEN ISNULL(C20,0) = ISNULL(D20,0) OR ISNULL(D20,0) = 0 AND NW.N_20 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D20,0)) END),'.00',''),

		O21 = ' ' + REPLACE((CASE WHEN ISNULL(C21,0) = ISNULL(D21,0) OR ISNULL(D21,0) = 0 AND NW.N_21 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D21,0)) END),'.00',''),
		O22 = ' ' + REPLACE((CASE WHEN ISNULL(C22,0) = ISNULL(D22,0) OR ISNULL(D22,0) = 0 AND NW.N_22 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D22,0)) END),'.00',''),
		O23 = ' ' + REPLACE((CASE WHEN ISNULL(C23,0) = ISNULL(D23,0) OR ISNULL(D23,0) = 0 AND NW.N_23 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D23,0)) END),'.00',''),
		O24 = ' ' + REPLACE((CASE WHEN ISNULL(C24,0) = ISNULL(D24,0) OR ISNULL(D24,0) = 0 AND NW.N_24 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D24,0)) END),'.00',''),
		O25 = ' ' + REPLACE((CASE WHEN ISNULL(C25,0) = ISNULL(D25,0) OR ISNULL(D25,0) = 0 AND NW.N_25 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D25,0)) END),'.00',''),
		O26 = ' ' + REPLACE((CASE WHEN ISNULL(C26,0) = ISNULL(D26,0) OR ISNULL(D26,0) = 0 AND NW.N_26 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D26,0)) END),'.00',''),
		O27 = ' ' + REPLACE((CASE WHEN ISNULL(C27,0) = ISNULL(D27,0) OR ISNULL(D27,0) = 0 AND NW.N_27 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D27,0)) END),'.00',''),
		O28 = ' ' + REPLACE((CASE WHEN ISNULL(C28,0) = ISNULL(D28,0) OR ISNULL(D28,0) = 0 AND NW.N_28 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D28,0)) END),'.00',''),
		O29 = ' ' + REPLACE((CASE WHEN ISNULL(C29,0) = ISNULL(D29,0) OR ISNULL(D29,0) = 0 AND NW.N_29 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D29,0)) END),'.00',''),
		O30 = ' ' + REPLACE((CASE WHEN ISNULL(C30,0) = ISNULL(D30,0) OR ISNULL(D30,0) = 0 AND NW.N_30 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D30,0)) END),'.00',''),
		O31 = ' ' + REPLACE((CASE WHEN ISNULL(C31,0) = ISNULL(D31,0) OR ISNULL(D31,0) = 0 AND NW.N_31 IS NOT NULL THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D31,0)) END),'.00','')
	
	FROM 
		#WORK1 W1
		LEFT JOIN 
		(
		SELECT 
			WP.link_empl, WP.link_sovm, link_day,
			d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18, d19, d20, d21, d22, d23, d24, d25, d26, d27, d28, d29, d30, d31 
		FROM 
			DBO.TABELS T 
			INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
			INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
			INNER JOIN DBO.TABELS_W W ON TE.LINK = W.LINK_UP AND ISNULL(W.LINK_SOVM,0) = WP.LINK_SOVM
		WHERE 
			T.LINK_DOC = @varKSnLINKDoc
		) W ON W.LINK_EMPL = W1.LINK_EMPL AND W.LINK_SOVM = W1.LINK_SOVM AND W.link_day = W1.DAY_TIP
		LEFT JOIN #NOWORK NW ON NW.LINK_EMPL = W1.LINK_EMPL AND NW.LINK_SOVM = W1.LINK_SOVM
			
	UNION ALL

	SELECT 
		WP.link_empl, WP.link_sovm, link_day,
		' ' + REPLACE(CASE WHEN ISNULL(D1,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D1,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D2,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D2,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D3,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D3,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D4,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D4,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D5,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D5,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D6,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D6,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D7,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D7,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D8,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D8,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D9,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D9,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D10,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D10,0)) END,'.00',''),
		
		' ' + REPLACE(CASE WHEN ISNULL(D11,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D11,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D12,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D12,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D13,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D13,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D14,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D14,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D15,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D15,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D16,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D16,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D17,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D17,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D18,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D18,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D19,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D19,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D20,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D20,0)) END,'.00',''),
		
		' ' + REPLACE(CASE WHEN ISNULL(D21,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D21,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D22,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D22,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D23,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D23,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D24,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D24,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D25,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D25,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D26,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D26,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D27,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D27,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D28,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D28,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D29,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D29,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D30,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D30,0)) END,'.00',''),
		' ' + REPLACE(CASE WHEN ISNULL(D31,0) = 0 THEN '' ELSE CONVERT(VARCHAR(10),ISNULL(D31,0)) END,'.00','') 			 
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN DBO.TABELS_W W ON TE.LINK = W.LINK_UP AND ISNULL(W.LINK_SOVM,0) = WP.LINK_SOVM
	WHERE
		T.LINK_DOC = @varKSnLINKDoc
		AND
		NOT EXISTS (SELECT * FROM #WORK1 W1 WHERE WP.LINK_EMPL = W1.LINK_EMPL AND WP.LINK_SOVM = W1.LINK_SOVM AND W.link_day = W1.DAY_TIP)					
	ORDER BY 
		1,2,3		


	-- Объединение явок и предпразничных и помещаем их отдельно
	CREATE TABLE #WORK3 (LINK_EMPL INT, LINK_SOVM INT, DAY_TIP INT, O_1 VARCHAR(10), O_10 VARCHAR(10), O_11 VARCHAR(10), O_12 VARCHAR(10), O_13 VARCHAR(10), O_14 VARCHAR(10), O_15 VARCHAR(10), O_16 VARCHAR(10), O_17 VARCHAR(10), O_18 VARCHAR(10), O_19 VARCHAR(10), O_2 VARCHAR(10), O_20 VARCHAR(10), O_21 VARCHAR(10), O_22 VARCHAR(10), O_23 VARCHAR(10), O_24 VARCHAR(10), O_25 VARCHAR(10), O_26 VARCHAR(10), O_27 VARCHAR(10), O_28 VARCHAR(10), O_29 VARCHAR(10), O_3 VARCHAR(10), O_30 VARCHAR(10), O_31 VARCHAR(10), O_4 VARCHAR(10), O_5 VARCHAR(10), O_6 VARCHAR(10), O_7 VARCHAR(10), O_8 VARCHAR(10), O_9  VARCHAR(10))	

	INSERT INTO #WORK3 (LINK_EMPL,LINK_SOVM,DAY_TIP,O_1,O_2,O_3,O_4,O_5,O_6,O_7,O_8,O_9,O_10,O_11,O_12,O_13,O_14,O_15,O_16,O_17,O_18,O_19,O_20,O_21,O_22,O_23,O_24,O_25,O_26,O_27,O_28,O_29,O_30,O_31)
	SELECT 
		LINK_EMPL,LINK_SOVM, MAX(DAY_TIP),
		MAX(O_1),MAX(O_2),MAX(O_3),MAX(O_4),MAX(O_5),MAX(O_6),MAX(O_7),MAX(O_8),MAX(O_9),MAX(O_10),MAX(O_11),MAX(O_12),MAX(O_13),MAX(O_14),MAX(O_15),
		MAX(O_16),MAX(O_17),MAX(O_18),MAX(O_19),MAX(O_20),MAX(O_21),MAX(O_22),MAX(O_23),MAX(O_24),MAX(O_25),MAX(O_26),MAX(O_27),MAX(O_28),MAX(O_29),MAX(O_30),MAX(O_31) 
	FROM 
		#WORK2 O
		INNER JOIN dbo.TYP_DAYS TD ON TD.LINK = O.DAY_TIP
	WHERE
		TD.WORK_D = 1 AND DOP_TAB = 1
	GROUP BY
		LINK_EMPL,LINK_SOVM
	ORDER BY 
		1,2,3


	-- Прочие виды часов отделяем для соединения с неявками (формирование второй строки)
	CREATE TABLE #WORK4 (LINK_EMPL INT, LINK_SOVM INT, DAY_TIP INT, O_1 VARCHAR(10), O_10 VARCHAR(10), O_11 VARCHAR(10), O_12 VARCHAR(10), O_13 VARCHAR(10), O_14 VARCHAR(10), O_15 VARCHAR(10), O_16 VARCHAR(10), O_17 VARCHAR(10), O_18 VARCHAR(10), O_19 VARCHAR(10), O_2 VARCHAR(10), O_20 VARCHAR(10), O_21 VARCHAR(10), O_22 VARCHAR(10), O_23 VARCHAR(10), O_24 VARCHAR(10), O_25 VARCHAR(10), O_26 VARCHAR(10), O_27 VARCHAR(10), O_28 VARCHAR(10), O_29 VARCHAR(10), O_3 VARCHAR(10), O_30 VARCHAR(10), O_31 VARCHAR(10), O_4 VARCHAR(10), O_5 VARCHAR(10), O_6 VARCHAR(10), O_7 VARCHAR(10), O_8 VARCHAR(10), O_9  VARCHAR(10))	
	
	INSERT INTO #WORK4 (LINK_EMPL,LINK_SOVM,DAY_TIP,O_1,O_2,O_3,O_4,O_5,O_6,O_7,O_8,O_9,O_10,O_11,O_12,O_13,O_14,O_15,O_16,O_17,O_18,O_19,O_20,O_21,O_22,O_23,O_24,O_25,O_26,O_27,O_28,O_29,O_30,O_31)
	SELECT LINK_EMPL,LINK_SOVM,DAY_TIP,O_1,O_2,O_3,O_4,O_5,O_6,O_7,O_8,O_9,O_10,O_11,O_12,O_13,O_14,O_15,O_16,O_17,O_18,O_19,O_20,O_21,O_22,O_23,O_24,O_25,O_26,O_27,O_28,O_29,O_30,O_31			
	FROM #WORK2
	WHERE DAY_TIP NOT IN (SELECT LINK FROM dbo.TYP_DAYS WHERE WORK_D = 1 AND DOP_TAB = 1)
	ORDER BY 
		1,2,3	


	----- ИТОГИ ОТРАБОТАННОГО ВРЕМЕНИ ПО ВИДАМ ЧАСОВ
	DECLARE @SYMB1 INT, @SYMB2 INT, @SYMB3 INT, @SYMB4 INT, @SYMB5 INT
	
	----		
	SET @SYMB1 = (SELECT TOP 1 LINK FROM dbo.TYP_DAYS WHERE TYP_YAVKA = 1 AND WORK_D = 1 AND DOP_TAB = 1)
	IF @SYMB1 IS NULL
		SET @SYMB1 = (SELECT DISTINCT TOP 1 DAY_TIP FROM #WORK3)
		
	SET @SYMB2 = (SELECT DISTINCT TOP 1 DAY_TIP FROM #WORK4 WHERE DAY_TIP <> @SYMB1 ORDER BY DAY_TIP )
	
	IF @SYMB2 IS NOT NULL
		SET @SYMB3 = (SELECT DISTINCT TOP 1 DAY_TIP FROM #WORK4 WHERE DAY_TIP <> @SYMB1 AND DAY_TIP <> @SYMB2 ORDER BY DAY_TIP )

	IF @SYMB3 IS NOT NULL
		SET @SYMB4 = (SELECT DISTINCT TOP 1 DAY_TIP FROM #WORK4 WHERE DAY_TIP <> @SYMB1 AND DAY_TIP <> @SYMB2 AND DAY_TIP <> @SYMB3 ORDER BY DAY_TIP )

	IF @SYMB4 IS NOT NULL
		SET @SYMB5 = (SELECT DISTINCT TOP 1 DAY_TIP FROM #WORK4 WHERE DAY_TIP <> @SYMB1 AND DAY_TIP <> @SYMB2 AND DAY_TIP <> @SYMB3 AND DAY_TIP <> @SYMB4 ORDER BY DAY_TIP )
		
	
	CREATE TABLE #ITOGI (link_empl INT, link_sovm INT, H_1 NUMERIC(10,2), D_1 INT, H_2 NUMERIC(10,2), H_3 NUMERIC(10,2), H_4 NUMERIC(10,2), H_5 NUMERIC(10,2) ) 	
	INSERT INTO #ITOGI (link_empl, link_sovm, H_1, D_1, H_2, H_3, H_4, H_5) 	
	SELECT 
		link_empl, link_sovm, H_1 = SUM(H_1), D_1 = SUM(D_1), H_2 = SUM(H_2), H_3 = SUM(H_3), H_4 = SUM(H_4), H_5 = SUM(H_5) 
	FROM
		(	
		SELECT 
			WP.link_empl, WP.link_sovm,
			H_1 = CASE WHEN link_day <> ISNULL(@SYMB2,0) AND link_day <> ISNULL(@SYMB3,0) AND link_day <> ISNULL(@SYMB4,0) AND link_day <> ISNULL(@SYMB5,0) THEN DBO.MINUTES_TO_NUM( DBO.NUM_TO_MINUTES(d1,@ISMINUTES) + DBO.NUM_TO_MINUTES(d2,@ISMINUTES) + DBO.NUM_TO_MINUTES(d3,@ISMINUTES) + DBO.NUM_TO_MINUTES(d4,@ISMINUTES) + DBO.NUM_TO_MINUTES(d5,@ISMINUTES) + DBO.NUM_TO_MINUTES(d6,@ISMINUTES) + DBO.NUM_TO_MINUTES(d7,@ISMINUTES) + DBO.NUM_TO_MINUTES(d8,@ISMINUTES) + DBO.NUM_TO_MINUTES(d9,@ISMINUTES) + DBO.NUM_TO_MINUTES(d10,@ISMINUTES) + DBO.NUM_TO_MINUTES(d11,@ISMINUTES) + DBO.NUM_TO_MINUTES(d12,@ISMINUTES) + DBO.NUM_TO_MINUTES(d13,@ISMINUTES) + DBO.NUM_TO_MINUTES(d14,@ISMINUTES) + DBO.NUM_TO_MINUTES(d15,@ISMINUTES) + DBO.NUM_TO_MINUTES(d16,@ISMINUTES) + DBO.NUM_TO_MINUTES(d17,@ISMINUTES) + DBO.NUM_TO_MINUTES(d18,@ISMINUTES) + DBO.NUM_TO_MINUTES(d19,@ISMINUTES) + DBO.NUM_TO_MINUTES(d20,@ISMINUTES) + DBO.NUM_TO_MINUTES(d21,@ISMINUTES) + DBO.NUM_TO_MINUTES(d22,@ISMINUTES) + DBO.NUM_TO_MINUTES(d23,@ISMINUTES) + DBO.NUM_TO_MINUTES(d24,@ISMINUTES) + DBO.NUM_TO_MINUTES(d25,@ISMINUTES) + DBO.NUM_TO_MINUTES(d26,@ISMINUTES) + DBO.NUM_TO_MINUTES(d27,@ISMINUTES) + DBO.NUM_TO_MINUTES(d28,@ISMINUTES) + DBO.NUM_TO_MINUTES(d29,@ISMINUTES) + DBO.NUM_TO_MINUTES(d30,@ISMINUTES) + DBO.NUM_TO_MINUTES(d31,@ISMINUTES) ,@ISMINUTES) ELSE 0 END,
			D_1 = CASE WHEN link_day <> ISNULL(@SYMB2,0) AND link_day <> ISNULL(@SYMB3,0) AND link_day <> ISNULL(@SYMB4,0) AND link_day <> ISNULL(@SYMB5,0) THEN (CASE WHEN d1 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d2 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d3 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d4 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d5 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d6 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d7 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d8 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d9 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d10 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d11 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d12 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d13 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d14 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d15 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d16 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d17 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d18 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d19 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d20 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d21 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d22 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d23 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d24 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d25 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d26 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d27 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d28 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d29 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d30 <> 0 THEN 1 ELSE 0 END) + (CASE WHEN d31 <> 0 THEN 1 ELSE 0 END)  ELSE 0 END,
			H_2 = CASE WHEN link_day = @SYMB2 THEN DBO.MINUTES_TO_NUM( DBO.NUM_TO_MINUTES(d1,@ISMINUTES) + DBO.NUM_TO_MINUTES(d2,@ISMINUTES) + DBO.NUM_TO_MINUTES(d3,@ISMINUTES) + DBO.NUM_TO_MINUTES(d4,@ISMINUTES) + DBO.NUM_TO_MINUTES(d5,@ISMINUTES) + DBO.NUM_TO_MINUTES(d6,@ISMINUTES) + DBO.NUM_TO_MINUTES(d7,@ISMINUTES) + DBO.NUM_TO_MINUTES(d8,@ISMINUTES) + DBO.NUM_TO_MINUTES(d9,@ISMINUTES) + DBO.NUM_TO_MINUTES(d10,@ISMINUTES) + DBO.NUM_TO_MINUTES(d11,@ISMINUTES) + DBO.NUM_TO_MINUTES(d12,@ISMINUTES) + DBO.NUM_TO_MINUTES(d13,@ISMINUTES) + DBO.NUM_TO_MINUTES(d14,@ISMINUTES) + DBO.NUM_TO_MINUTES(d15,@ISMINUTES) + DBO.NUM_TO_MINUTES(d16,@ISMINUTES) + DBO.NUM_TO_MINUTES(d17,@ISMINUTES) + DBO.NUM_TO_MINUTES(d18,@ISMINUTES) + DBO.NUM_TO_MINUTES(d19,@ISMINUTES) + DBO.NUM_TO_MINUTES(d20,@ISMINUTES) + DBO.NUM_TO_MINUTES(d21,@ISMINUTES) + DBO.NUM_TO_MINUTES(d22,@ISMINUTES) + DBO.NUM_TO_MINUTES(d23,@ISMINUTES) + DBO.NUM_TO_MINUTES(d24,@ISMINUTES) + DBO.NUM_TO_MINUTES(d25,@ISMINUTES) + DBO.NUM_TO_MINUTES(d26,@ISMINUTES) + DBO.NUM_TO_MINUTES(d27,@ISMINUTES) + DBO.NUM_TO_MINUTES(d28,@ISMINUTES) + DBO.NUM_TO_MINUTES(d29,@ISMINUTES) + DBO.NUM_TO_MINUTES(d30,@ISMINUTES) + DBO.NUM_TO_MINUTES(d31,@ISMINUTES) ,@ISMINUTES) ELSE 0 END,	
			H_3 = CASE WHEN link_day = @SYMB3 THEN DBO.MINUTES_TO_NUM( DBO.NUM_TO_MINUTES(d1,@ISMINUTES) + DBO.NUM_TO_MINUTES(d2,@ISMINUTES) + DBO.NUM_TO_MINUTES(d3,@ISMINUTES) + DBO.NUM_TO_MINUTES(d4,@ISMINUTES) + DBO.NUM_TO_MINUTES(d5,@ISMINUTES) + DBO.NUM_TO_MINUTES(d6,@ISMINUTES) + DBO.NUM_TO_MINUTES(d7,@ISMINUTES) + DBO.NUM_TO_MINUTES(d8,@ISMINUTES) + DBO.NUM_TO_MINUTES(d9,@ISMINUTES) + DBO.NUM_TO_MINUTES(d10,@ISMINUTES) + DBO.NUM_TO_MINUTES(d11,@ISMINUTES) + DBO.NUM_TO_MINUTES(d12,@ISMINUTES) + DBO.NUM_TO_MINUTES(d13,@ISMINUTES) + DBO.NUM_TO_MINUTES(d14,@ISMINUTES) + DBO.NUM_TO_MINUTES(d15,@ISMINUTES) + DBO.NUM_TO_MINUTES(d16,@ISMINUTES) + DBO.NUM_TO_MINUTES(d17,@ISMINUTES) + DBO.NUM_TO_MINUTES(d18,@ISMINUTES) + DBO.NUM_TO_MINUTES(d19,@ISMINUTES) + DBO.NUM_TO_MINUTES(d20,@ISMINUTES) + DBO.NUM_TO_MINUTES(d21,@ISMINUTES) + DBO.NUM_TO_MINUTES(d22,@ISMINUTES) + DBO.NUM_TO_MINUTES(d23,@ISMINUTES) + DBO.NUM_TO_MINUTES(d24,@ISMINUTES) + DBO.NUM_TO_MINUTES(d25,@ISMINUTES) + DBO.NUM_TO_MINUTES(d26,@ISMINUTES) + DBO.NUM_TO_MINUTES(d27,@ISMINUTES) + DBO.NUM_TO_MINUTES(d28,@ISMINUTES) + DBO.NUM_TO_MINUTES(d29,@ISMINUTES) + DBO.NUM_TO_MINUTES(d30,@ISMINUTES) + DBO.NUM_TO_MINUTES(d31,@ISMINUTES) ,@ISMINUTES) ELSE 0 END,
			H_4 = CASE WHEN link_day = @SYMB4 THEN DBO.MINUTES_TO_NUM( DBO.NUM_TO_MINUTES(d1,@ISMINUTES) + DBO.NUM_TO_MINUTES(d2,@ISMINUTES) + DBO.NUM_TO_MINUTES(d3,@ISMINUTES) + DBO.NUM_TO_MINUTES(d4,@ISMINUTES) + DBO.NUM_TO_MINUTES(d5,@ISMINUTES) + DBO.NUM_TO_MINUTES(d6,@ISMINUTES) + DBO.NUM_TO_MINUTES(d7,@ISMINUTES) + DBO.NUM_TO_MINUTES(d8,@ISMINUTES) + DBO.NUM_TO_MINUTES(d9,@ISMINUTES) + DBO.NUM_TO_MINUTES(d10,@ISMINUTES) + DBO.NUM_TO_MINUTES(d11,@ISMINUTES) + DBO.NUM_TO_MINUTES(d12,@ISMINUTES) + DBO.NUM_TO_MINUTES(d13,@ISMINUTES) + DBO.NUM_TO_MINUTES(d14,@ISMINUTES) + DBO.NUM_TO_MINUTES(d15,@ISMINUTES) + DBO.NUM_TO_MINUTES(d16,@ISMINUTES) + DBO.NUM_TO_MINUTES(d17,@ISMINUTES) + DBO.NUM_TO_MINUTES(d18,@ISMINUTES) + DBO.NUM_TO_MINUTES(d19,@ISMINUTES) + DBO.NUM_TO_MINUTES(d20,@ISMINUTES) + DBO.NUM_TO_MINUTES(d21,@ISMINUTES) + DBO.NUM_TO_MINUTES(d22,@ISMINUTES) + DBO.NUM_TO_MINUTES(d23,@ISMINUTES) + DBO.NUM_TO_MINUTES(d24,@ISMINUTES) + DBO.NUM_TO_MINUTES(d25,@ISMINUTES) + DBO.NUM_TO_MINUTES(d26,@ISMINUTES) + DBO.NUM_TO_MINUTES(d27,@ISMINUTES) + DBO.NUM_TO_MINUTES(d28,@ISMINUTES) + DBO.NUM_TO_MINUTES(d29,@ISMINUTES) + DBO.NUM_TO_MINUTES(d30,@ISMINUTES) + DBO.NUM_TO_MINUTES(d31,@ISMINUTES) ,@ISMINUTES) ELSE 0 END,
			H_5 = CASE WHEN link_day = @SYMB5 THEN DBO.MINUTES_TO_NUM( DBO.NUM_TO_MINUTES(d1,@ISMINUTES) + DBO.NUM_TO_MINUTES(d2,@ISMINUTES) + DBO.NUM_TO_MINUTES(d3,@ISMINUTES) + DBO.NUM_TO_MINUTES(d4,@ISMINUTES) + DBO.NUM_TO_MINUTES(d5,@ISMINUTES) + DBO.NUM_TO_MINUTES(d6,@ISMINUTES) + DBO.NUM_TO_MINUTES(d7,@ISMINUTES) + DBO.NUM_TO_MINUTES(d8,@ISMINUTES) + DBO.NUM_TO_MINUTES(d9,@ISMINUTES) + DBO.NUM_TO_MINUTES(d10,@ISMINUTES) + DBO.NUM_TO_MINUTES(d11,@ISMINUTES) + DBO.NUM_TO_MINUTES(d12,@ISMINUTES) + DBO.NUM_TO_MINUTES(d13,@ISMINUTES) + DBO.NUM_TO_MINUTES(d14,@ISMINUTES) + DBO.NUM_TO_MINUTES(d15,@ISMINUTES) + DBO.NUM_TO_MINUTES(d16,@ISMINUTES) + DBO.NUM_TO_MINUTES(d17,@ISMINUTES) + DBO.NUM_TO_MINUTES(d18,@ISMINUTES) + DBO.NUM_TO_MINUTES(d19,@ISMINUTES) + DBO.NUM_TO_MINUTES(d20,@ISMINUTES) + DBO.NUM_TO_MINUTES(d21,@ISMINUTES) + DBO.NUM_TO_MINUTES(d22,@ISMINUTES) + DBO.NUM_TO_MINUTES(d23,@ISMINUTES) + DBO.NUM_TO_MINUTES(d24,@ISMINUTES) + DBO.NUM_TO_MINUTES(d25,@ISMINUTES) + DBO.NUM_TO_MINUTES(d26,@ISMINUTES) + DBO.NUM_TO_MINUTES(d27,@ISMINUTES) + DBO.NUM_TO_MINUTES(d28,@ISMINUTES) + DBO.NUM_TO_MINUTES(d29,@ISMINUTES) + DBO.NUM_TO_MINUTES(d30,@ISMINUTES) + DBO.NUM_TO_MINUTES(d31,@ISMINUTES) ,@ISMINUTES) ELSE 0 END
		FROM 
			DBO.TABELS T 
			INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
			INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
			INNER JOIN DBO.TABELS_W W ON TE.LINK = W.LINK_UP AND ISNULL(W.LINK_SOVM,0) = WP.LINK_SOVM
		WHERE 
			T.LINK_DOC = @varKSnLINKDoc
		) T
	GROUP BY 
		link_empl, link_sovm
	ORDER BY
		link_empl, link_sovm	
		

	--Считаем, сколько всего часов отклонений 

	CREATE TABLE #NO_WORK_DAY (LINK_EMPL INT, LINK_SOVM INT, 
		C1 NUMERIC(5,2), C2 NUMERIC(5,2), C3 NUMERIC(5,2), C4 NUMERIC(5,2), C5 NUMERIC(5,2), C6 NUMERIC(5,2), C7 NUMERIC(5,2), C8 NUMERIC(5,2), C9  NUMERIC(5,2), C10 NUMERIC(5,2), C11 NUMERIC(5,2), C12 NUMERIC(5,2), C13 NUMERIC(5,2), C14 NUMERIC(5,2), C15 NUMERIC(5,2), C16 NUMERIC(5,2), C17 NUMERIC(5,2), C18 NUMERIC(5,2), C19 NUMERIC(5,2), C20 NUMERIC(5,2), C21 NUMERIC(5,2), C22 NUMERIC(5,2), C23 NUMERIC(5,2), C24 NUMERIC(5,2), C25 NUMERIC(5,2), C26 NUMERIC(5,2), C27 NUMERIC(5,2), C28 NUMERIC(5,2), C29 NUMERIC(5,2), C30 NUMERIC(5,2), C31 NUMERIC(5,2),
		D1 TINYINT, D2 TINYINT, D3 TINYINT, D4 TINYINT, D5 TINYINT, D6 TINYINT, D7 TINYINT, D8 TINYINT, D9  TINYINT, D10 TINYINT, D11 TINYINT, D12 TINYINT, D13 TINYINT, D14 TINYINT, D15 TINYINT, D16 TINYINT, D17 TINYINT, D18 TINYINT, D19 TINYINT, D20 TINYINT, D21 TINYINT, D22 TINYINT, D23 TINYINT, D24 TINYINT, D25 TINYINT, D26 TINYINT, D27 TINYINT, D28 TINYINT, D29 TINYINT, D30 TINYINT, D31 TINYINT)

	INSERT INTO #NO_WORK_DAY
	SELECT 
		W1.LINK_EMPL, W1.LINK_SOVM, --W1.DAY_TIP,
		--Часы неявок
		O1 = CASE WHEN @PERIOD BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD) AND ISNULL(W1.C1,0) > ISNULL(W.D1,0) THEN ISNULL(W1.C1,0) - ISNULL(W.D1,0) ELSE 0 END,
		O2 = CASE WHEN @PERIOD+1 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+1) AND ISNULL(W1.C2,0) > ISNULL(W.D2,0) THEN ISNULL(W1.C2,0) - ISNULL(W.D2,0) ELSE 0 END,
		O3 = CASE WHEN @PERIOD+2 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+2) AND ISNULL(W1.C3,0) > ISNULL(W.D3,0) THEN ISNULL(W1.C3,0) - ISNULL(W.D3,0) ELSE 0 END,
		O4 = CASE WHEN @PERIOD+3 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+3) AND ISNULL(W1.C4,0) > ISNULL(W.D4,0) THEN ISNULL(W1.C4,0) - ISNULL(W.D4,0) ELSE 0 END,
		O5 = CASE WHEN @PERIOD+4 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+4) AND ISNULL(W1.C5,0) > ISNULL(W.D5,0) THEN ISNULL(W1.C5,0) - ISNULL(W.D5,0) ELSE 0 END,
		O6 = CASE WHEN @PERIOD+5 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+5) AND ISNULL(W1.C6,0) > ISNULL(W.D6,0) THEN ISNULL(W1.C6,0) - ISNULL(W.D6,0) ELSE 0 END,
		O7 = CASE WHEN @PERIOD+6 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+6) AND ISNULL(W1.C7,0) > ISNULL(W.D7,0) THEN ISNULL(W1.C7,0) - ISNULL(W.D7,0) ELSE 0 END,
		O8 = CASE WHEN @PERIOD+7 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+7) AND ISNULL(W1.C8,0) > ISNULL(W.D8,0) THEN ISNULL(W1.C8,0) - ISNULL(W.D8,0) ELSE 0 END,
		O9 = CASE WHEN @PERIOD+8 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+8) AND ISNULL(W1.C9,0) > ISNULL(W.D9,0) THEN ISNULL(W1.C9,0) - ISNULL(W.D9,0) ELSE 0 END,
		O10 = CASE WHEN @PERIOD+9 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+9) AND ISNULL(W1.C10,0) > ISNULL(W.D10,0) THEN ISNULL(W1.C10,0) - ISNULL(W.D10,0) ELSE 0 END,

		O11 = CASE WHEN @PERIOD+10 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+10) AND ISNULL(W1.C11,0) > ISNULL(W.D11,0) THEN ISNULL(W1.C11,0) - ISNULL(W.D11,0) ELSE 0 END,
		O12 = CASE WHEN @PERIOD+11 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+11) AND ISNULL(W1.C12,0) > ISNULL(W.D12,0) THEN ISNULL(W1.C12,0) - ISNULL(W.D12,0) ELSE 0 END,
		O13 = CASE WHEN @PERIOD+12 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+12) AND ISNULL(W1.C13,0) > ISNULL(W.D13,0) THEN ISNULL(W1.C13,0) - ISNULL(W.D13,0) ELSE 0 END,
		O14 = CASE WHEN @PERIOD+13 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+13) AND ISNULL(W1.C14,0) > ISNULL(W.D14,0) THEN ISNULL(W1.C14,0) - ISNULL(W.D14,0) ELSE 0 END,
		O15 = CASE WHEN @PERIOD+14 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+14) AND ISNULL(W1.C15,0) > ISNULL(W.D15,0) THEN ISNULL(W1.C15,0) - ISNULL(W.D15,0) ELSE 0 END,
		O16 = CASE WHEN @PERIOD+15 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+15) AND ISNULL(W1.C16,0) > ISNULL(W.D16,0) THEN ISNULL(W1.C16,0) - ISNULL(W.D16,0) ELSE 0 END,
		O17 = CASE WHEN @PERIOD+16 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+16) AND ISNULL(W1.C17,0) > ISNULL(W.D17,0) THEN ISNULL(W1.C17,0) - ISNULL(W.D17,0) ELSE 0 END,
		O18 = CASE WHEN @PERIOD+17 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+17) AND ISNULL(W1.C18,0) > ISNULL(W.D18,0) THEN ISNULL(W1.C18,0) - ISNULL(W.D18,0) ELSE 0 END,
		O19 = CASE WHEN @PERIOD+18 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+18) AND ISNULL(W1.C19,0) > ISNULL(W.D19,0) THEN ISNULL(W1.C19,0) - ISNULL(W.D19,0) ELSE 0 END,
		O20 = CASE WHEN @PERIOD+19 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+19) AND ISNULL(W1.C20,0) > ISNULL(W.D20,0) THEN ISNULL(W1.C20,0) - ISNULL(W.D20,0) ELSE 0 END,

		O21 = CASE WHEN @PERIOD+20 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+20) AND ISNULL(W1.C21,0) > ISNULL(W.D21,0) THEN ISNULL(W1.C21,0) - ISNULL(W.D21,0) ELSE 0 END,
		O22 = CASE WHEN @PERIOD+21 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+21) AND ISNULL(W1.C22,0) > ISNULL(W.D22,0) THEN ISNULL(W1.C22,0) - ISNULL(W.D22,0) ELSE 0 END,
		O23 = CASE WHEN @PERIOD+22 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+22) AND ISNULL(W1.C23,0) > ISNULL(W.D23,0) THEN ISNULL(W1.C23,0) - ISNULL(W.D23,0) ELSE 0 END,
		O24 = CASE WHEN @PERIOD+23 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+23) AND ISNULL(W1.C24,0) > ISNULL(W.D24,0) THEN ISNULL(W1.C24,0) - ISNULL(W.D24,0) ELSE 0 END,
		O25 = CASE WHEN @PERIOD+24 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+24) AND ISNULL(W1.C25,0) > ISNULL(W.D25,0) THEN ISNULL(W1.C25,0) - ISNULL(W.D25,0) ELSE 0 END,
		O26 = CASE WHEN @PERIOD+25 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+25) AND ISNULL(W1.C26,0) > ISNULL(W.D26,0) THEN ISNULL(W1.C26,0) - ISNULL(W.D26,0) ELSE 0 END,
		O27 = CASE WHEN @PERIOD+26 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+26) AND ISNULL(W1.C27,0) > ISNULL(W.D27,0) THEN ISNULL(W1.C27,0) - ISNULL(W.D27,0) ELSE 0 END,
		O28 = CASE WHEN @PERIOD+27 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+27) AND ISNULL(W1.C28,0) > ISNULL(W.D28,0) THEN ISNULL(W1.C28,0) - ISNULL(W.D28,0) ELSE 0 END,
		O29 = CASE WHEN @PERIOD+28 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+28) AND ISNULL(W1.C29,0) > ISNULL(W.D29,0) THEN ISNULL(W1.C29,0) - ISNULL(W.D29,0) ELSE 0 END,
		O30 = CASE WHEN @PERIOD+29 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+29) AND ISNULL(W1.C30,0) > ISNULL(W.D30,0) THEN ISNULL(W1.C30,0) - ISNULL(W.D30,0) ELSE 0 END,
		O31 = CASE WHEN @PERIOD+30 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+30) AND ISNULL(W1.C31,0) > ISNULL(W.D31,0) THEN ISNULL(W1.C31,0) - ISNULL(W.D31,0) ELSE 0 END,

		--Дни неявок
		OD1 = CASE WHEN @PERIOD BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD) AND ISNULL(W1.C1,0) > 0 AND ISNULL(W.D1,0) = 0 THEN 1 ELSE 0 END,
		OD2 = CASE WHEN @PERIOD+1 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+1) AND ISNULL(W1.C2,0) > 0 AND ISNULL(W.D2,0) = 0 THEN 1 ELSE 0 END,
		OD3 = CASE WHEN @PERIOD+2 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+2) AND ISNULL(W1.C3,0) > 0 AND ISNULL(W.D3,0) = 0 THEN 1 ELSE 0 END,
		OD4 = CASE WHEN @PERIOD+3 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+3) AND ISNULL(W1.C4,0) > 0 AND ISNULL(W.D4,0) = 0 THEN 1 ELSE 0 END,
		OD5 = CASE WHEN @PERIOD+4 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+4) AND ISNULL(W1.C5,0) > 0 AND ISNULL(W.D5,0) = 0 THEN 1 ELSE 0 END,
		OD6 = CASE WHEN @PERIOD+5 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+5) AND ISNULL(W1.C6,0) > 0 AND ISNULL(W.D6,0) = 0 THEN 1 ELSE 0 END,
		OD7 = CASE WHEN @PERIOD+6 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+6) AND ISNULL(W1.C7,0) > 0 AND ISNULL(W.D7,0) = 0 THEN 1 ELSE 0 END,
		OD8 = CASE WHEN @PERIOD+7 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+7) AND ISNULL(W1.C8,0) > 0 AND ISNULL(W.D8,0) = 0 THEN 1 ELSE 0 END,
		OD9 = CASE WHEN @PERIOD+8 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+8) AND ISNULL(W1.C9,0) > 0 AND ISNULL(W.D9,0) = 0 THEN 1 ELSE 0 END,
		OD10 = CASE WHEN @PERIOD+9 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+9) AND ISNULL(W1.C10,0) > 0 AND ISNULL(W.D10,0) = 0 THEN 1 ELSE 0 END,

		OD11 = CASE WHEN @PERIOD+10 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+10) AND ISNULL(W1.C11,0) > 0 AND ISNULL(W.D11,0) = 0 THEN 1 ELSE 0 END,
		OD12 = CASE WHEN @PERIOD+11 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+11) AND ISNULL(W1.C12,0) > 0 AND ISNULL(W.D12,0) = 0 THEN 1 ELSE 0 END,
		OD13 = CASE WHEN @PERIOD+12 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+12) AND ISNULL(W1.C13,0) > 0 AND ISNULL(W.D13,0) = 0 THEN 1 ELSE 0 END,
		OD14 = CASE WHEN @PERIOD+13 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+13) AND ISNULL(W1.C14,0) > 0 AND ISNULL(W.D14,0) = 0 THEN 1 ELSE 0 END,
		OD15 = CASE WHEN @PERIOD+14 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+14) AND ISNULL(W1.C15,0) > 0 AND ISNULL(W.D15,0) = 0 THEN 1 ELSE 0 END,
		OD16 = CASE WHEN @PERIOD+15 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+15) AND ISNULL(W1.C16,0) > 0 AND ISNULL(W.D16,0) = 0 THEN 1 ELSE 0 END,
		OD17 = CASE WHEN @PERIOD+16 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+16) AND ISNULL(W1.C17,0) > 0 AND ISNULL(W.D17,0) = 0 THEN 1 ELSE 0 END,
		OD18 = CASE WHEN @PERIOD+17 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+17) AND ISNULL(W1.C18,0) > 0 AND ISNULL(W.D18,0) = 0 THEN 1 ELSE 0 END,
		OD19 = CASE WHEN @PERIOD+18 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+18) AND ISNULL(W1.C19,0) > 0 AND ISNULL(W.D19,0) = 0 THEN 1 ELSE 0 END,
		OD20 = CASE WHEN @PERIOD+19 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+19) AND ISNULL(W1.C20,0) > 0 AND ISNULL(W.D20,0) = 0 THEN 1 ELSE 0 END,

		OD21 = CASE WHEN @PERIOD+20 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+20) AND ISNULL(W1.C21,0) > 0 AND ISNULL(W.D21,0) = 0 THEN 1 ELSE 0 END,
		OD22 = CASE WHEN @PERIOD+21 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+21) AND ISNULL(W1.C22,0) > 0 AND ISNULL(W.D22,0) = 0 THEN 1 ELSE 0 END,
		OD23 = CASE WHEN @PERIOD+22 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+22) AND ISNULL(W1.C23,0) > 0 AND ISNULL(W.D23,0) = 0 THEN 1 ELSE 0 END,
		OD24 = CASE WHEN @PERIOD+23 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+23) AND ISNULL(W1.C24,0) > 0 AND ISNULL(W.D24,0) = 0 THEN 1 ELSE 0 END,
		OD25 = CASE WHEN @PERIOD+24 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+24) AND ISNULL(W1.C25,0) > 0 AND ISNULL(W.D25,0) = 0 THEN 1 ELSE 0 END,
		OD26 = CASE WHEN @PERIOD+25 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+25) AND ISNULL(W1.C26,0) > 0 AND ISNULL(W.D26,0) = 0 THEN 1 ELSE 0 END,
		OD27 = CASE WHEN @PERIOD+26 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+26) AND ISNULL(W1.C27,0) > 0 AND ISNULL(W.D27,0) = 0 THEN 1 ELSE 0 END,
		OD28 = CASE WHEN @PERIOD+27 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+27) AND ISNULL(W1.C28,0) > 0 AND ISNULL(W.D28,0) = 0 THEN 1 ELSE 0 END,
		OD29 = CASE WHEN @PERIOD+28 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+28) AND ISNULL(W1.C29,0) > 0 AND ISNULL(W.D29,0) = 0 THEN 1 ELSE 0 END,
		OD30 = CASE WHEN @PERIOD+29 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+29) AND ISNULL(W1.C30,0) > 0 AND ISNULL(W.D30,0) = 0 THEN 1 ELSE 0 END,
		OD31 = CASE WHEN @PERIOD+30 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+30) AND ISNULL(W1.C31,0) > 0 AND ISNULL(W.D31,0) = 0 THEN 1 ELSE 0 END		
		
	FROM 
		#WORK1 W1
		INNER JOIN dbo.SA_EMPLS_W WP ON WP.LINK_EMPL = W1.LINK_EMPL AND WP.LINK = W1.LINK_SOVM		
		LEFT JOIN 
		(
		SELECT 
			WP.link_empl, WP.link_sovm, link_day,
			d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18, d19, d20, d21, d22, d23, d24, d25, d26, d27, d28, d29, d30, d31 
		FROM 
			DBO.TABELS T 
			INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
			INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
			INNER JOIN DBO.TABELS_W W ON TE.LINK = W.LINK_UP AND ISNULL(W.LINK_SOVM,0) = WP.LINK_SOVM
		WHERE 
			T.LINK_DOC = @varKSnLINKDoc
		) W ON W.LINK_EMPL = W1.LINK_EMPL AND W.LINK_SOVM = W1.LINK_SOVM AND W.link_day = W1.DAY_TIP
		

	-----
	CREATE TABLE #NO_WORK_DAY1 (LINK_EMPL INT, LINK_SOVM INT, 
		C1 NUMERIC(5,2), C2 NUMERIC(5,2), C3 NUMERIC(5,2), C4 NUMERIC(5,2), C5 NUMERIC(5,2), C6 NUMERIC(5,2), C7 NUMERIC(5,2), C8 NUMERIC(5,2), C9  NUMERIC(5,2), C10 NUMERIC(5,2), C11 NUMERIC(5,2), C12 NUMERIC(5,2), C13 NUMERIC(5,2), C14 NUMERIC(5,2), C15 NUMERIC(5,2), C16 NUMERIC(5,2), C17 NUMERIC(5,2), C18 NUMERIC(5,2), C19 NUMERIC(5,2), C20 NUMERIC(5,2), C21 NUMERIC(5,2), C22 NUMERIC(5,2), C23 NUMERIC(5,2), C24 NUMERIC(5,2), C25 NUMERIC(5,2), C26 NUMERIC(5,2), C27 NUMERIC(5,2), C28 NUMERIC(5,2), C29 NUMERIC(5,2), C30 NUMERIC(5,2), C31 NUMERIC(5,2),
		OD INT)

	INSERT INTO #NO_WORK_DAY1
	SELECT 
		LINK_EMPL, LINK_SOVM,
		DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C1,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C2,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C3,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C4,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C5,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C6,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C7,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C8,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C9,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C10,@ISMINUTES)),@ISMINUTES),
		DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C11,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C12,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C13,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C14,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C15,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C16,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C17,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C18,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C19,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C20,@ISMINUTES)),@ISMINUTES),
		DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C21,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C22,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C23,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C24,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C25,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C26,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C27,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C28,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C29,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C30,@ISMINUTES)),@ISMINUTES), DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES(C31,@ISMINUTES)),@ISMINUTES),
		MAX(D1) + MAX(D2) + MAX(D3) + MAX(D4) + MAX(D5) + MAX(D6) + MAX(D7) + MAX(D8) + MAX(D9 ) + MAX(D10) + MAX(D11) + MAX(D12) + MAX(D13) + MAX(D14) + MAX(D15) + MAX(D16) + MAX(D17) + MAX(D18) + MAX(D19) + MAX(D20) + MAX(D21) + MAX(D22) + MAX(D23) + MAX(D24) + MAX(D25) + MAX(D26) + MAX(D27) + MAX(D28) + MAX(D29) + MAX(D30) + MAX(D31) 
	FROM 
		#NO_WORK_DAY
	GROUP BY
		LINK_EMPL,
		LINK_SOVM	


	--Убирем строки без отклонений
	DELETE FROM #WORK4 
	WHERE
		LTRIM(RTRIM(O_1)) = '' 
		AND LTRIM(RTRIM(O_2)) = '' 
		AND LTRIM(RTRIM(O_3)) = '' 
		AND LTRIM(RTRIM(O_4)) = '' 
		AND LTRIM(RTRIM(O_5)) = '' 
		AND LTRIM(RTRIM(O_6)) = '' 
		AND LTRIM(RTRIM(O_7)) = '' 
		AND LTRIM(RTRIM(O_8)) = '' 
		AND LTRIM(RTRIM(O_9)) = '' 
		AND LTRIM(RTRIM(O_10)) = '' 

		AND LTRIM(RTRIM(O_11)) = '' 
		AND LTRIM(RTRIM(O_12)) = '' 
		AND LTRIM(RTRIM(O_13)) = '' 
		AND LTRIM(RTRIM(O_14)) = '' 
		AND LTRIM(RTRIM(O_15)) = '' 
		AND LTRIM(RTRIM(O_16)) = '' 
		AND LTRIM(RTRIM(O_17)) = '' 
		AND LTRIM(RTRIM(O_18)) = '' 
		AND LTRIM(RTRIM(O_19)) = '' 
		AND LTRIM(RTRIM(O_20)) = '' 

		AND LTRIM(RTRIM(O_21)) = '' 
		AND LTRIM(RTRIM(O_22)) = '' 
		AND LTRIM(RTRIM(O_23)) = '' 
		AND LTRIM(RTRIM(O_24)) = '' 
		AND LTRIM(RTRIM(O_25)) = '' 
		AND LTRIM(RTRIM(O_26)) = '' 
		AND LTRIM(RTRIM(O_27)) = '' 
		AND LTRIM(RTRIM(O_28)) = '' 
		AND LTRIM(RTRIM(O_29)) = '' 
		AND LTRIM(RTRIM(O_30)) = '' 
		AND LTRIM(RTRIM(O_31)) = '' 
	
	--Объединение неявки и отклонения второго вида часов
	UPDATE N
		SET 
		 N_1 = ISNULL(N_1,'') + CASE WHEN LTRIM(RTRIM(W4.O_1)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_1)) ELSE '' END,
		 N_2 = ISNULL(N_2,'') + CASE WHEN LTRIM(RTRIM(W4.O_2)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_2)) ELSE '' END,
		 N_3 = ISNULL(N_3,'') + CASE WHEN LTRIM(RTRIM(W4.O_3)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_3)) ELSE '' END,
		 N_4 = ISNULL(N_4,'') + CASE WHEN LTRIM(RTRIM(W4.O_4)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_4)) ELSE '' END,
		 N_5 = ISNULL(N_5,'') + CASE WHEN LTRIM(RTRIM(W4.O_5)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_5)) ELSE '' END,
		 N_6 = ISNULL(N_6,'') + CASE WHEN LTRIM(RTRIM(W4.O_6)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_6)) ELSE '' END,
		 N_7 = ISNULL(N_7,'') + CASE WHEN LTRIM(RTRIM(W4.O_7)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_7)) ELSE '' END,
		 N_8 = ISNULL(N_8,'') + CASE WHEN LTRIM(RTRIM(W4.O_8)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_8)) ELSE '' END,
		 N_9 = ISNULL(N_9,'') + CASE WHEN LTRIM(RTRIM(W4.O_9)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_9)) ELSE '' END,
		 N_10 = ISNULL(N_10,'') + CASE WHEN LTRIM(RTRIM(W4.O_10)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_10)) ELSE '' END,

		 N_11 = ISNULL(N_11,'') + CASE WHEN LTRIM(RTRIM(W4.O_11)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_11)) ELSE '' END,
		 N_12 = ISNULL(N_12,'') + CASE WHEN LTRIM(RTRIM(W4.O_12)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_12)) ELSE '' END,
		 N_13 = ISNULL(N_13,'') + CASE WHEN LTRIM(RTRIM(W4.O_13)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_13)) ELSE '' END,
		 N_14 = ISNULL(N_14,'') + CASE WHEN LTRIM(RTRIM(W4.O_14)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_14)) ELSE '' END,
		 N_15 = ISNULL(N_15,'') + CASE WHEN LTRIM(RTRIM(W4.O_15)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_15)) ELSE '' END,
		 N_16 = ISNULL(N_16,'') + CASE WHEN LTRIM(RTRIM(W4.O_16)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_16)) ELSE '' END,
		 N_17 = ISNULL(N_17,'') + CASE WHEN LTRIM(RTRIM(W4.O_17)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_17)) ELSE '' END,
		 N_18 = ISNULL(N_18,'') + CASE WHEN LTRIM(RTRIM(W4.O_18)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_18)) ELSE '' END,
		 N_19 = ISNULL(N_19,'') + CASE WHEN LTRIM(RTRIM(W4.O_19)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_19)) ELSE '' END,
		 N_20 = ISNULL(N_20,'') + CASE WHEN LTRIM(RTRIM(W4.O_20)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_20)) ELSE '' END,

		 N_21 = ISNULL(N_21,'') + CASE WHEN LTRIM(RTRIM(W4.O_21)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_21)) ELSE '' END,
		 N_22 = ISNULL(N_22,'') + CASE WHEN LTRIM(RTRIM(W4.O_21)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_22)) ELSE '' END,
		 N_23 = ISNULL(N_23,'') + CASE WHEN LTRIM(RTRIM(W4.O_23)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_23)) ELSE '' END,
		 N_24 = ISNULL(N_24,'') + CASE WHEN LTRIM(RTRIM(W4.O_24)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_24)) ELSE '' END,
		 N_25 = ISNULL(N_25,'') + CASE WHEN LTRIM(RTRIM(W4.O_25)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_25)) ELSE '' END,
		 N_26 = ISNULL(N_26,'') + CASE WHEN LTRIM(RTRIM(W4.O_26)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_26)) ELSE '' END,
		 N_27 = ISNULL(N_27,'') + CASE WHEN LTRIM(RTRIM(W4.O_27)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_27)) ELSE '' END,
		 N_28 = ISNULL(N_28,'') + CASE WHEN LTRIM(RTRIM(W4.O_28)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_28)) ELSE '' END,
		 N_29 = ISNULL(N_29,'') + CASE WHEN LTRIM(RTRIM(W4.O_29)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_29)) ELSE '' END,
		 N_30 = ISNULL(N_30,'') + CASE WHEN LTRIM(RTRIM(W4.O_30)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_30)) ELSE '' END,
		 N_31 = ISNULL(N_31,'') + CASE WHEN LTRIM(RTRIM(W4.O_31)) <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_31)) ELSE '' END
	FROM 
		#NOWORK N
		INNER JOIN #WORK4 W4 ON N.LINK_EMPL = W4.LINK_EMPL AND N.LINK_SOVM = W4.LINK_SOVM
		INNER JOIN dbo.TYP_DAYS TD ON TD.LINK = W4.DAY_TIP
		INNER JOIN 
			(	
			SELECT LINK_EMPL, LINK_SOVM, DAY_TIP = MAX(DAY_TIP)
			FROM #WORK4 W4
			GROUP BY LINK_EMPL, LINK_SOVM
			) U ON U.LINK_EMPL = W4.LINK_EMPL AND U.LINK_SOVM = W4.LINK_SOVM AND U.DAY_TIP = W4.DAY_TIP

	---
	DELETE 
	FROM 
		#WORK4
	WHERE EXISTS
	(
		SELECT * 
		FROM	
		(	
		SELECT LINK_EMPL1 = LINK_EMPL, LINK_SOVM1 = LINK_SOVM, DAY_TIP1 = MAX(DAY_TIP)
		FROM #WORK4 W4
		GROUP BY LINK_EMPL, LINK_SOVM
		) U 
		WHERE U.LINK_EMPL1 = LINK_EMPL AND U.LINK_SOVM1 = LINK_SOVM AND U.DAY_TIP1 = DAY_TIP
	)	



	--ФОРМИРОВАНИЕ ДАННЫХ ДЛЯ ВЫВОДА В ОТЧЁТ
	
	CREATE TABLE #T_RES00 (
		ID VARCHAR(20),
		LINK_FACE INT, 
		LINK_EMPL INT,
		LINK_SOVM INT,
		FIO VARCHAR(254),
		NAME_EMPL VARCHAR(254),
		TN VARCHAR(10) ,
		SUBDIV_LINK INT, 
		CODE_SUB VARCHAR(10),
		SUBDIV VARCHAR(254) ,
		POST_LINK INT,
		CODE_POST VARCHAR(10),
		POST VARCHAR(254) ,
		O_1 VARCHAR(10), O_2 VARCHAR(10), O_3 VARCHAR(10), O_4 VARCHAR(10), O_5 VARCHAR(10), O_6 VARCHAR(10), O_7 VARCHAR(10), O_8 VARCHAR(10), O_9  VARCHAR(10), O_10 VARCHAR(10), O_11 VARCHAR(10), O_12 VARCHAR(10), O_13 VARCHAR(10), O_14 VARCHAR(10), O_15 VARCHAR(10), O_16 VARCHAR(10), O_17 VARCHAR(10), O_18 VARCHAR(10), O_19 VARCHAR(10), O_20 VARCHAR(10), O_21 VARCHAR(10), O_22 VARCHAR(10), O_23 VARCHAR(10), O_24 VARCHAR(10), O_25 VARCHAR(10), O_26 VARCHAR(10), O_27 VARCHAR(10), O_28 VARCHAR(10), O_29 VARCHAR(10), O_30 VARCHAR(10), O_31 VARCHAR(10),
		N_1 VARCHAR(10), N_2 VARCHAR(10), N_3 VARCHAR(10), N_4 VARCHAR(10), N_5 VARCHAR(10), N_6 VARCHAR(10), N_7 VARCHAR(10), N_8 VARCHAR(10), N_9  VARCHAR(10), N_10 VARCHAR(10), N_11 VARCHAR(10), N_12 VARCHAR(10), N_13 VARCHAR(10), N_14 VARCHAR(10), N_15 VARCHAR(10), N_16 VARCHAR(10), N_17 VARCHAR(10), N_18 VARCHAR(10), N_19 VARCHAR(10), N_20 VARCHAR(10), N_21 VARCHAR(10), N_22 VARCHAR(10), N_23 VARCHAR(10), N_24 VARCHAR(10), N_25 VARCHAR(10), N_26 VARCHAR(10), N_27 VARCHAR(10), N_28 VARCHAR(10), N_29 VARCHAR(10), N_30 VARCHAR(10), N_31 VARCHAR(10),
		CNT_DAY_N NUMERIC(5,2),
		SUM_HOUR_N NUMERIC(10,2),
		S_1 VARCHAR(4), H_1 NUMERIC(10,2), D_1 NUMERIC(10,2),
		S_2 VARCHAR(4), H_2 NUMERIC(10,2), 
		S_3 VARCHAR(4), H_3 NUMERIC(10,2), 
		S_4 VARCHAR(4), H_4 NUMERIC(10,2), 
		S_5 VARCHAR(4), H_5 NUMERIC(10,2)
	) 	

	INSERT INTO #T_RES00
	(
		ID, LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST, 
		O_1, O_2, O_3, O_4, O_5, O_6, O_7, O_8, O_9, O_10, O_11, O_12, O_13, O_14, O_15, O_16, O_17, O_18, O_19, O_20, O_21, O_22, O_23, O_24, O_25, O_26, O_27, O_28, O_29, O_30, O_31, 
		N_1, N_2, N_3, N_4, N_5, N_6, N_7, N_8, N_9, N_10, N_11, N_12, N_13, N_14, N_15, N_16, N_17, N_18, N_19, N_20, N_21, N_22, N_23, N_24, N_25, N_26, N_27, N_28, N_29, N_30, N_31,
		CNT_DAY_N, SUM_HOUR_N,
		S_1, H_1, D_1, S_2, H_2, S_3, H_3, S_4, H_4, S_5, H_5
	)

	SELECT
		ID = RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),T.LINK_EMPL),10) +RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),T.LINK_SOVM),10) ,
		[LINK_FACE] = P.LINK,
		T.LINK_EMPL,
		T.LINK_SOVM,
		[FIO]  = (case when coalesce(@nCheck3,0) = 1 then  coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),'Не заполнено'))),100), SPACE(100)) 
					else coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30), SPACE(100)) end),
		[NAME_EMPL] = LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30),
		[TN] 		= ISNULL(E.TAB, SPACE(10)),
		[SUBDIV_LINK] = WP.subdiv_head,
		[CODE_SUB] = ISNULL( WP.SUBDIV_CODE, SPACE(10) ),
		[SUBDIV] = ISNULL( WP.SUBDIV_NAME, SPACE(254) ),
		[POST_LINK] = WP.link_post,
		[CODE_POST] = ISNULL( WP.POST_CODE, SPACE(10) ),
		[POST] 		= ISNULL( WP.POST_NAME, SPACE(120) ),
		CASE WHEN @PERIOD BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD) THEN O_1 ELSE '-' END,
		CASE WHEN @PERIOD+1 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+1) THEN O_2 ELSE '-' END,
		CASE WHEN @PERIOD+2 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+2) THEN O_3 ELSE '-' END,
		CASE WHEN @PERIOD+3 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+3) THEN O_4 ELSE '-' END,
		CASE WHEN @PERIOD+4 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+4) THEN O_5 ELSE '-' END,
		CASE WHEN @PERIOD+5 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+5) THEN O_6 ELSE '-' END,
		CASE WHEN @PERIOD+6 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+6) THEN O_7 ELSE '-' END,
		CASE WHEN @PERIOD+7 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+7) THEN O_8 ELSE '-' END,
		CASE WHEN @PERIOD+8 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+8) THEN O_9 ELSE '-' END,
		CASE WHEN @PERIOD+9 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+9) THEN O_10 ELSE '-' END,

		CASE WHEN @PERIOD+10 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+10) THEN O_11 ELSE '-' END,
		CASE WHEN @PERIOD+11 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+11) THEN O_12 ELSE '-' END,
		CASE WHEN @PERIOD+12 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+12) THEN O_13 ELSE '-' END,
		CASE WHEN @PERIOD+13 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+13) THEN O_14 ELSE '-' END,
		CASE WHEN @PERIOD+14 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+14) THEN O_15 ELSE '-' END,
		CASE WHEN @PERIOD+15 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+15) THEN O_16 ELSE '-' END,
		CASE WHEN @PERIOD+16 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+16) THEN O_17 ELSE '-' END,
		CASE WHEN @PERIOD+17 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+17) THEN O_18 ELSE '-' END,
		CASE WHEN @PERIOD+18 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+18) THEN O_19 ELSE '-' END,
		CASE WHEN @PERIOD+19 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+19) THEN O_20 ELSE '-' END,

		CASE WHEN @PERIOD+20 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+20) THEN O_21 ELSE '-' END,
		CASE WHEN @PERIOD+21 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+21) THEN O_22 ELSE '-' END,
		CASE WHEN @PERIOD+22 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+22) THEN O_23 ELSE '-' END,
		CASE WHEN @PERIOD+23 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+23) THEN O_24 ELSE '-' END,
		CASE WHEN @PERIOD+24 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+24) THEN O_25 ELSE '-' END,
		CASE WHEN @PERIOD+25 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+25) THEN O_26 ELSE '-' END,
		CASE WHEN @PERIOD+26 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+26) THEN O_27 ELSE '-' END,
		CASE WHEN @PERIOD+27 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+27) THEN O_28 ELSE '-' END,
		CASE WHEN @PERIOD+28 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+28) THEN O_29 ELSE '-' END,
		CASE WHEN @PERIOD+29 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+29) THEN O_30 ELSE '-' END,
		CASE WHEN @PERIOD+30 BETWEEN WP.DATE_BEGIN AND ISNULL(WP.DATE_END,@PERIOD+30) THEN O_31 ELSE '-' END,
	
		N_1, N_2, N_3, N_4, N_5, N_6, N_7, N_8, N_9, N_10, N_11, N_12, N_13, N_14, N_15, N_16, N_17, N_18, N_19, N_20, N_21, N_22, N_23, N_24, N_25, N_26, N_27, N_28, N_29, N_30, N_31,

		CNT_DAY_N = NW.OD,
					
		SUM_HOUR_N = 
			DBO.MINUTES_TO_NUM(
			DBO.NUM_TO_MINUTES(NW.C1,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C2,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C3,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C4,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C5,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C6,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C7,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C8,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C9,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C10,@ISMINUTES)
		 + DBO.NUM_TO_MINUTES(NW.C11,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C12,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C13,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C14,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C15,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C16,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C17,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C18,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C19,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C20,@ISMINUTES)
		 + DBO.NUM_TO_MINUTES(NW.C21,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C22,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C23,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C24,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C25,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C26,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C27,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C28,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C29,@ISMINUTES) + DBO.NUM_TO_MINUTES(NW.C30,@ISMINUTES)
		 + DBO.NUM_TO_MINUTES(NW.C31,@ISMINUTES),@ISMINUTES),
		 
		 (SELECT SYMB FROM dbo.TYP_DAYS WHERE LINK = @SYMB1), I.H_1, I.D_1,
		 (SELECT SYMB FROM dbo.TYP_DAYS WHERE LINK = @SYMB2), I.H_2,
		 (SELECT SYMB FROM dbo.TYP_DAYS WHERE LINK = @SYMB3), I.H_3,
		 (SELECT SYMB FROM dbo.TYP_DAYS WHERE LINK = @SYMB4), I.H_4,
		 (SELECT SYMB FROM dbo.TYP_DAYS WHERE LINK = @SYMB5), I.H_5

	FROM 
		(

			--Основная строка в табеле
			SELECT 
				W3.LINK_EMPL, W3.LINK_SOVM, OSN = 1,
				O_1, O_2, O_3, O_4, O_5, O_6, O_7, O_8, O_9, O_10, O_11, O_12, O_13, O_14, O_15, O_16, O_17, O_18, O_19, O_20, O_21, O_22, O_23, O_24, O_25, O_26, O_27, O_28, O_29, O_30, O_31,
				N_1, N_2, N_3, N_4, N_5, N_6, N_7, N_8, N_9, N_10, N_11, N_12, N_13, N_14, N_15, N_16, N_17, N_18, N_19, N_20, N_21, N_22, N_23, N_24, N_25, N_26, N_27, N_28, N_29, N_30, N_31
			FROM 
				#WORK3 W3
				INNER JOIN #NOWORK NW ON W3.LINK_EMPL = NW.LINK_EMPL AND W3.LINK_SOVM = NW.LINK_SOVM
			
			UNION ALL
			
			--Дополнительные строки
			SELECT 
				W3.LINK_EMPL, W3.LINK_SOVM, OSN = 2,
				W3.O_1, W3.O_2, W3.O_3, W3.O_4, W3.O_5, W3.O_6, W3.O_7, W3.O_8, W3.O_9, W3.O_10, W3.O_11, W3.O_12, W3.O_13, W3.O_14, W3.O_15, W3.O_16, W3.O_17, W3.O_18, W3.O_19, W3.O_20, W3.O_21, W3.O_22, W3.O_23, W3.O_24, W3.O_25, W3.O_26, W3.O_27, W3.O_28, W3.O_29, W3.O_30, W3.O_31,
				CASE WHEN W4.O_1 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_1)) ELSE '' END,
				CASE WHEN W4.O_2 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_2)) ELSE '' END,
				CASE WHEN W4.O_3 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_3)) ELSE '' END,
				CASE WHEN W4.O_4 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_4)) ELSE '' END,
				CASE WHEN W4.O_5 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_5)) ELSE '' END,
				CASE WHEN W4.O_6 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_6)) ELSE '' END,
				CASE WHEN W4.O_7 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_7)) ELSE '' END,
				CASE WHEN W4.O_8 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_8)) ELSE '' END,
				CASE WHEN W4.O_9 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_9)) ELSE '' END,
				CASE WHEN W4.O_10 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_10)) ELSE '' END,

				CASE WHEN W4.O_11 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_11)) ELSE '' END,
				CASE WHEN W4.O_12 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_12)) ELSE '' END,
				CASE WHEN W4.O_13 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_13)) ELSE '' END,
				CASE WHEN W4.O_14 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_14)) ELSE '' END,
				CASE WHEN W4.O_15 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_15)) ELSE '' END,
				CASE WHEN W4.O_16 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_16)) ELSE '' END,
				CASE WHEN W4.O_17 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_17)) ELSE '' END,
				CASE WHEN W4.O_18 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_18)) ELSE '' END,
				CASE WHEN W4.O_19 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_19)) ELSE '' END,
				CASE WHEN W4.O_20 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_20)) ELSE '' END,

				CASE WHEN W4.O_21 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_21)) ELSE '' END,
				CASE WHEN W4.O_22 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_22)) ELSE '' END,
				CASE WHEN W4.O_23 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_23)) ELSE '' END,
				CASE WHEN W4.O_24 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_24)) ELSE '' END,
				CASE WHEN W4.O_25 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_25)) ELSE '' END,
				CASE WHEN W4.O_26 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_26)) ELSE '' END,
				CASE WHEN W4.O_27 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_27)) ELSE '' END,
				CASE WHEN W4.O_28 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_28)) ELSE '' END,
				CASE WHEN W4.O_29 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_29)) ELSE '' END,
				CASE WHEN W4.O_30 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_30)) ELSE '' END,
				CASE WHEN W4.O_31 <> '' THEN LTRIM(RTRIM(TD.SYMB)) + '/' + LTRIM(RTRIM(W4.O_31)) ELSE '' END
			FROM 
				#WORK3 W3
				INNER JOIN #WORK4 W4 ON W3.LINK_EMPL = W4.LINK_EMPL AND W3.LINK_SOVM = W4.LINK_SOVM
				INNER JOIN dbo.TYP_DAYS TD ON TD.LINK = W4.DAY_TIP
			WHERE
				LTRIM(RTRIM(W4.O_1)) <> '' 
				OR LTRIM(RTRIM(W4.O_2)) <> '' 
				OR LTRIM(RTRIM(W4.O_3)) <> '' 
				OR LTRIM(RTRIM(W4.O_4)) <> '' 
				OR LTRIM(RTRIM(W4.O_5)) <> '' 
				OR LTRIM(RTRIM(W4.O_6)) <> '' 
				OR LTRIM(RTRIM(W4.O_7)) <> '' 
				OR LTRIM(RTRIM(W4.O_8)) <> '' 
				OR LTRIM(RTRIM(W4.O_9)) <> '' 
				OR LTRIM(RTRIM(W4.O_10)) <> '' 

				OR LTRIM(RTRIM(W4.O_11)) <> '' 
				OR LTRIM(RTRIM(W4.O_12)) <> '' 
				OR LTRIM(RTRIM(W4.O_13)) <> '' 
				OR LTRIM(RTRIM(W4.O_14)) <> '' 
				OR LTRIM(RTRIM(W4.O_15)) <> '' 
				OR LTRIM(RTRIM(W4.O_16)) <> '' 
				OR LTRIM(RTRIM(W4.O_17)) <> '' 
				OR LTRIM(RTRIM(W4.O_18)) <> '' 
				OR LTRIM(RTRIM(W4.O_19)) <> '' 
				OR LTRIM(RTRIM(W4.O_20)) <> '' 

				OR LTRIM(RTRIM(W4.O_21)) <> '' 
				OR LTRIM(RTRIM(W4.O_22)) <> '' 
				OR LTRIM(RTRIM(W4.O_23)) <> '' 
				OR LTRIM(RTRIM(W4.O_24)) <> '' 
				OR LTRIM(RTRIM(W4.O_25)) <> '' 
				OR LTRIM(RTRIM(W4.O_26)) <> '' 
				OR LTRIM(RTRIM(W4.O_27)) <> '' 
				OR LTRIM(RTRIM(W4.O_28)) <> '' 
				OR LTRIM(RTRIM(W4.O_29)) <> '' 
				OR LTRIM(RTRIM(W4.O_30)) <> '' 
				OR LTRIM(RTRIM(W4.O_31)) <> '' 
					
		) T
		INNER JOIN DBO.EMPL E ON E.LINK = T.LINK_EMPL
		INNER JOIN DBO.PERSON P ON P.LINK = E.PERS_LINK
		INNER JOIN #NO_WORK_DAY1 NW ON NW.LINK_EMPL = T.LINK_EMPL AND NW.LINK_SOVM = T.LINK_SOVM
		LEFT JOIN dbo.SA_EMPLS_W WP ON WP.LINK_EMPL = T.LINK_EMPL AND WP.LINK = T.LINK_SOVM
		LEFT JOIN #ITOGI I ON I.LINK_EMPL = T.LINK_EMPL AND I.LINK_SOVM = T.LINK_SOVM AND T.OSN = 1
	ORDER BY 
		1	
 
	IF (SELECT COUNT(DISTINCT SUBDIV_LINK) FROM #T_RES00) <> 1 BEGIN
			SELECT @varKSSUBDIV = '', @varKSSUBDIV_CODE = ''
		END
		ELSE 
			BEGIN
				SELECT TOP 1 @varKSSUBDIV = SUBDIV, @varKSSUBDIV_CODE = CODE_SUB FROM  #T_RES00
			END

	DECLARE 
		@varKSCNT1 INT, @varKSCNT2 INT, @varKSCNT3 INT
	
	SELECT TOP 1 
		@varKSCNT1 = COUNT(DISTINCT LINK_FKR_D), 
		@varKSCNT2 = COUNT(DISTINCT LINK_FKR_T), 
		@varKSCNT3 = COUNT(DISTINCT LINK_FKR_E),
		@varKSDIV_CODE = MAX(CODE_FKR_D),
		@varKSDIV_NAME = MAX(NAME_FKR_D),
		@varKSTI_CODE = MAX(CODE_FKR_T),
		@varKSTI_NAME = MAX(NAME_FKR_T),
		@varKSEXP_CODE = MAX(CODE_FKR_E),
		@varKSEXP_NAME = MAX(NAME_FKR_E)
	FROM 
		DICTIONARY_PAYS_EMPL DPE
		INNER JOIN dbo.PAYS P ON DPE.LINK_PAYS = P.LINK
		INNER JOIN bi_diction_vkr VKR ON VKR.LINK = DPE.LINK_KBK
		INNER JOIN #T_RES00 R ON DPE.LINK_EMPL = R.LINK_EMPL
	where date_begin <= @varKSdDate2
		AND (DATE_END >= @varKSdDate1 OR DATE_END IS NULL) 


		declare @LINK_DEP int
		Set @LINK_DEP = Coalesce( (SELECT TOP 1 ZB_LINK FROM dbo.KS_OPTIONS_ZB), dbo.GetOwnDepLink())

		declare @nAVGCount numeric(18,2), @nMCount numeric(18,2)

		Select @nAVGCount = dbo.sa_ssch_empls(@varKSdDate1, @varKSdDate2, null, 0, 1, 0, DEFAULT)
		Select @nMCount = dbo.sa_sch_empls(@varKSdDate2, null, 0, 1, 0, DEFAULT)


	IF @varKSCNT1 <> 1
		SELECT @varKSDIV_CODE = '', @varKSDIV_NAME = ''
	IF @varKSCNT2 <> 1
		SELECT @varKSTI_CODE = '', @varKSTI_NAME = ''
	IF @varKSCNT3 <> 1
		SELECT @varKSEXP_CODE = '', @varKSEXP_NAME = ''

	SELECT *, @nAVGCount as AVGCount, @nMCount as MCount 
	FROM #T_RES00
	ORDER BY 
		LTRIM(RTRIM(CASE @varKSnOption1 
			WHEN 1 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 3 THEN POST
			WHEN 4 THEN FIO
			WHEN 5 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 6 THEN SUBDIV
			ELSE ''
		END)),

		LTRIM(RTRIM(CASE @varKSnCheck1 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN POST
			WHEN 5 THEN FIO
			WHEN 6 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN SUBDIV
			ELSE ''
		END)),
		
		LTRIM(RTRIM(CASE @nSort3 
			WHEN 2 THEN '' + REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN '' +POST
			WHEN 5 THEN '' +FIO
			WHEN 6 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN '' +SUBDIV
			ELSE ''
		END))

END



GO


GRANT EXECUTE ON dbo.[SA_PRINT_TABEL_148n] TO PUBLIC

GO


--Расширенные свойства--


GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_EXPORT_ZN]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[BB_EXPORT_ZN]
GO


/*
© Кейсистемс (Keysystems), 2005
*/

CREATE           
PROCEDURE BB_EXPORT_ZN
	@cBuffId	varchar(30) = '',
	@cObjCode	varchar(30) = ''

AS
  DECLARE @iDepLink	int, @cCodeOpt int, @cExp2 int, @iLongFio tinyint, @iPostRuk tinyint, @iPostGl tinyint

set @iDepLink = isnull(dbo.BK_GetDepZB(),dbo.GetOwnDepLink())
set @cCodeOpt = dbo.sa_get_option_by_code('DOC_REC_CARD_OPTIONS_KODBP')
set @iLongFio = dbo.sa_get_option_by_code('DOC_REC_CARD_FIO')
set @iPostRuk = dbo.sa_get_option_by_code('DOC_REC_CARD_POST_RUK')
set @iPostGl = dbo.sa_get_option_by_code('DOC_REC_CARD_POST_GL_BUH')



-- Таблица 2 (FROM)
SELECT BUDG_LEVEL  = case D.BUH_TYPE WHEN 1 then cast(replace(B.CODE_EL,'0','') as char(1)) else '6' end,
		KOD_UBP 	= case cast(replace(B.CODE_EL,'0','') as char(1)) when 1 then D.CODE_UBP else BUDG end,
		NAME_UBP	= D.FULL_NAME
from dbo.DEPARTMENTS D
left join dbo.KL_ADMIN_BS V WITH (NOLOCK) on V.LINK = D.VED_LINK
left join dbo.KL_BUDG_TYPE B WITH (NOLOCK) on V.Link_Budg = B.LINK
where D.LINK = @iDepLink


-- Таблица 3 (TO)
SELECT 	KOD_TOFK  = TOFK.CODE,
		NAME_TOFK = TOFK.FULL_NAME
from dbo.DEPARTMENTS D
inner join dbo.TREASURY TOFK on D.TOFK_LINK = TOFK.LINK
where D.LINK = @iDepLink



-- Таблица 4 (ZS)

	SELECT  LINK 		 = ZS.LINK,
			LINK_UP		 = ZS.LINK,
			GUID_FK		 = '',
			NOM_ZN		 = ZS.NUMBER,
			DATE_ZN		 = ZS.DATE,
			NAME_UBP 	 = ZS.DEP_FNAME, 
			KOD_UBP		 = case @cCodeOpt when 1 then ZS.DEP_UBP else '' end,
			NAME_TOFK	 = ZS.TOFK_NAME,
			KOD_TOFK	 = ZS.TOFK_CODE,
			LS_PAY		 = ZS.ACC_CODE,
			NOM_BO		 = ISNULL (ZS.NUM_BO, ''),
			FAIP_CODE	 = space(14),
			INN_UBP		 = ZS.DEP_INN,
			KPP			 = ZS.DEP_KPP,
			CARD_NUM	 = ZS.CARD_CODE, 
			NAME_V_SR	 = cast(ZS.VID_SR as char(1)),
			DOL_ISP		 = ZS.EMP_POST,
			ISP_F		 = ZS.EMP_F,
			ISP_I		 = ZS.EMP_I,
			ISP_O		 = ZS.EMP_O,
			DOL_RUK		 = case @iPostRuk when 1 then B.POST_NAME else '' end,
			NAME_RUK	 = B.SHORT_NAME,
			DOL_BUH		 = case @iPostGl when 1 then GB.POST_NAME else '' end,
			NAME_BUH 	 = GB.SHORT_NAME,
			SUMMA_ITOG	 = ZS.SUMMA,
			SUMMA_R2	 = (SELECT SUM(SUMMA) from dbo.RECEPTION_CArd_table_view ZT where ZT.LINK_UP = ZS.LINK),
			DATE_POD	 = ZS.DATE_POD

	FROM dbo.DOC_RECEPTION_CARD ZS
	left join dbo.GetOtvFaceData(NULL, 'Руководитель') B on ZS.DEP_LINK = B.LINK_DEP
	left join dbo.GetOtvFaceData(NULL, 'Главный бухгалтер') GB on ZS.DEP_LINK = GB.LINK_DEP
	where ZS.LINK in (select LINK from dbo.BufferGetTableByID(@cBuffId))

	-- Таблица 5 (ZSCH2)
	select  LINK 		 = ZT.LINK,
			LINK_UP		 = ZT.LINK_UP,
			POR_NUM 	 = ZT.record_no,
			TYPE_KBK	 = case ZT.KBK_TYPE when 1 then '10'
												when 2 then '20'
												when 4 then '31'
												when 8 then '32'
												else '' end,
			KBK			 = replace(rtrim(ZT.KBK_CODE) + ZT.EKR_CODE,'.',''),
			ADD_KLASS	 = ZT.D_CL_CODE,
			PURPOSE		 = ZT.REASON,
			SUMR_KBK	 = ZT.SUMMA,
			NOTE		 = ZT.TITLE

	from dbo.RECEPTION_CArd_table_view ZT 
	where ZT.LINK_UP in (select LINK from dbo.BufferGetTableByID(@cBuffId))









GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_EXPORT_RN]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[BB_EXPORT_RN]
GO


/*
© Кейсистемс (Keysystems), 2005
*/

CREATE           
PROCEDURE BB_EXPORT_RN
	@cBuffId	varchar(30) = '',
	@cObjCode	varchar(30) = ''

AS
  DECLARE @iDepLink	int, @cCodeOpt int, @cExp2 int, @iLongFio tinyint, @iPostRuk tinyint, @iPostGl tinyint

set @iDepLink = isnull(dbo.BK_GetDepZB(),dbo.GetOwnDepLink())
set @cCodeOpt = dbo.sa_get_option_by_code('DOC_REC_CARD_OPTIONS_KODBP')
set @iLongFio = dbo.sa_get_option_by_code('DOC_REC_CARD_FIO')
set @iPostRuk = dbo.sa_get_option_by_code('DOC_REC_CARD_POST_RUK')
set @iPostGl = dbo.sa_get_option_by_code('DOC_REC_CARD_POST_GL_BUH')



-- Таблица 2 (FROM)
SELECT BUDG_LEVEL  = case D.BUH_TYPE WHEN 1 then cast(replace(B.CODE_EL,'0','') as char(1)) else '6' end,
		KOD_UBP 	= case cast(replace(B.CODE_EL,'0','') as char(1)) when 1 then D.CODE_UBP else BUDG end,
		NAME_UBP	= D.FULL_NAME
from dbo.DEPARTMENTS D
left join dbo.KL_ADMIN_BS V WITH (NOLOCK) on V.LINK = D.VED_LINK
left join dbo.KL_BUDG_TYPE B WITH (NOLOCK) on V.Link_Budg = B.LINK
where D.LINK = @iDepLink


-- Таблица 3 (TO)
SELECT 	KOD_TOFK  = TOFK.CODE,
		NAME_TOFK = TOFK.FULL_NAME
from dbo.DEPARTMENTS D
inner join dbo.TREASURY TOFK on D.TOFK_LINK = TOFK.LINK
where D.LINK = @iDepLink



-- Таблица 4 (ZS)

	SELECT  LINK 		 = RN.LINK,
			LINK_UP		 = RN.LINK,
			GUID_FK		 = '',
			DATE_RN		 = RN.[DATE],
			NOM_RN		 = RN.NUMBER,
			LS_PAY		 = RN.ACC_CODE,
			VID_OPER     = cast(RN.VID as char(1)),
			KOD_UBP		 = case @cCodeOpt when 1 then RN.DEP_UBP else '' end,
			NAME_UBP 	 = RN.DEP_FNAME, 
			INN_UBP		 = RN.DEP_INN,
			KPP			 = RN.DEP_KPP,
			KOD_TOFK	 = RN.TOFK_CODE,
			NAME_TOFK	 = RN.TOFK_NAME,
			FAIP_CODE	 = space(14),
			CARD_NUM	 = RN.CARD_CODE, 
			DOL_RUK		 = case @iPostRuk when 1 then B.POST_NAME else '' end,
			NAME_RUK	 = B.SHORT_NAME,
			DOL_BUH		 = case @iPostGl when 1 then GB.POST_NAME else '' end,
			NAME_BUH 	 = GB.SHORT_NAME,
			DATE_POD	 = RN.DATE_PROV,
			SUMMA_ITOG	 = RN.SUMMA,
			SUMMA_R2	 = (SELECT SUM(SUMMA) from dbo.BB_DET_RETURN_table_view ZT where ZT.LINK_UP = RN.LINK)

	FROM dbo.BB_DET_RETURN RN
	left join dbo.GetOtvFaceData(NULL, 'Руководитель') B on RN.DEP_LINK = B.LINK_DEP
	left join dbo.GetOtvFaceData(NULL, 'Главный бухгалтер') GB on RN.DEP_LINK = GB.LINK_DEP
	where RN.LINK in (select LINK from dbo.BufferGetTableByID(@cBuffId))

	-- Таблица 5 (ZSCH2)
	select  LINK 		 = ZT.LINK,
			LINK_UP		 = ZT.LINK_UP,
			POR_NUM 	 = ZT.record_no,
			TYPE_KBK	 = case ZT.KBK_TYPE when 1 then '10'
												when 2 then '20'
												when 4 then '31'
												when 8 then '32'
												else '' end,
			KBK			 = replace(rtrim(ZT.KBK_CODE) + ZT.EKR_CODE,'.',''),
			NAME_V_SR	 = cast(ZT.VID_SR as char(1)),
			ADD_KLASS	 = ZT.D_CL_CODE,
			SUMMA	 = ZT.SUMMA,
			NOTE		 = ZT.TITLE

	from dbo.BB_DET_RETURN_table_view ZT 
	where ZT.LINK_UP in (select LINK from dbo.BufferGetTableByID(@cBuffId))









GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_JURN_INVOICE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_JURN_INVOICE]

GO
/*
© Кейсистемс (Keysystems), 2005
*/
CREATE  PROCEDURE dbo.BK_REPORT_JURN_INVOICE
	@varKSdDate_1 datetime,
	@varKSdDate_2 DATETIME,
	@varKSnOption1 int,	-- 1 - Полученные счета-фактуры
				-- 2 - Выданные счета-фактуры -- 
				-- 3 - Общий --
	@intSVOD_ZB	int	-- Сводный отчет (ЦБ) 
AS
BEGIN

	DECLARE
		@intDEP_LINK	INT,
		@strHD_Org_Name VARCHAR (254),
		@strHD_PUR_INN VARCHAR (20),
		@strHD_PUR_KPP VARCHAR (20),

		@DOC_LINK	INT,
		@NDS_TYPE	VARCHAR (4),
		@NDS_TYPE_VAL	VARCHAR (254),

		@CUR_DOC_LINK	INT,
		
		@QUARTER	INT,
		@YEAR	INT,

		@strSFIN_CODE CHAR (1),
		@cVal_SFIN char(1), @nOtborLinkSFIN int	-- Отбор источников финансирования --

	DECLARE @TAB1 TABLE (LINK_DOC INT,
			DEP1	INT,

			DOC_DATE1 DATETIME,
			DOC_NUM1 VARCHAR (50),

			DOC_DATE2 DATETIME,
			DOC_NUM2 VARCHAR (50),

			COR_DATE1 DATETIME,
			COR_NUM1 VARCHAR (50),

			COR_DATE2 DATETIME,
			COR_NUM2 VARCHAR (50),

			DATE_OPL DATETIME,

			SORT_NUM VARCHAR (50),
			SORT_DATE	DATETIME,

			IS_COR	TINYINT,
			ORDERS	TINYINT,

			BIL_DATE	DATETIME,
			BIL_CODE	VARCHAR (2))

	--- Сводный отчет (ЦБ) --- 
	SET @intSVOD_ZB = ISNULL (@intSVOD_ZB, 0)
	SET @intDEP_LINK = ISNULL (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())

	IF @intSVOD_ZB = 1
		SET @intDEP_LINK = dbo.GetOwnDepLink ()

	SELECT	@strHD_Org_Name = dbo.BK_GET_PRINT_DEP_NAME (LINK),
		@strHD_PUR_INN = INN,
		@strHD_PUR_KPP = KPP
	FROM dbo.DEPARTMENTS
	WHERE LINK = @intDEP_LINK

	SELECT @strHD_Org_Name = ISNULL (@strHD_Org_Name, ''),
		@strHD_PUR_INN = ISNULL (@strHD_PUR_INN, ''),
		@strHD_PUR_KPP = ISNULL (@strHD_PUR_KPP, '')

	IF @intSVOD_ZB = 1
		SET @strHD_Org_Name = RTRIM (@strHD_Org_Name) + '(ЦБ)'

	SET @QUARTER = MONTH (@varKSdDate_2) 

	SELECT
		@QUARTER = CASE
						WHEN @QUARTER BETWEEN 1 AND 3 THEN 1
						WHEN @QUARTER BETWEEN 4 AND 6 THEN 2
						WHEN @QUARTER BETWEEN 7 AND 9 THEN 3
						WHEN @QUARTER BETWEEN 10 AND 12 THEN 4
				END,
		@YEAR	=	YEAR (@varKSdDate_2)

	IF @varKSnOption1 = 1		-- Полученные счета-фактуры --
			OR @varKSnOption1 = 3
	BEGIN
		INSERT INTO @TAB1	-- Отбор всех полученных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.SEL_LINK,	-- ПРОДАВЕЦ --

			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			NULL,
			'',

			NULL,
			'',

			DOC.DATE_BASE,

			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			DOC.[DATE],

			0,
			1,

			BIL_DATE,
			BIL_CODE
		FROM dbo.DOCUMENTS_INVOICE_RECEIVED DOC
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)

		INSERT INTO @TAB1	-- Отбор всех кор. полученных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.SEL_LINK,	-- ПРОДАВЕЦ --

			DOC.OSN_DATE,
			DOC.OSN_NUM,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			DOC.DATE_BASE,

			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			DOC.[DATE],

			1,
			1,

			BIL_DATE,
			BIL_CODE
		FROM dbo.DOCUMENTS_INVOICE_COR_IN DOC
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)
	END

	IF @varKSnOption1 = 2		-- Выданные счета-фактуры --
			OR @varKSnOption1 = 3
	BEGIN
		INSERT INTO @TAB1	 -- Отбор всех выданных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.BUY_LINK,	-- ПОКУПАЕТЛЬ --

			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			NULL,
			'',

			NULL,
			'',

			DOC.DATE_BASE,

			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			DOC.[DATE],

			0,
			0,

			BIL_DATE,
			BIL_CODE
		FROM dbo.DOCUMENTS_INVOICE_ISSUED DOC
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)

		INSERT INTO @TAB1	-- Отбор всех кор. выданных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.BUY_LINK,	-- ПОКУПАЕТЛЬ --

			DOC.OSN_DATE,
			DOC.OSN_NUM,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			DOC.[DATE],
			DOC.NUMBER,

			DOC.COR_DATE, 
			DOC.COR_NUM,

			DOC.DATE_BASE,

			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			DOC.[DATE],

			1,
			0,

			BIL_DATE,
			BIL_CODE
		FROM dbo.DOCUMENTS_INVOICE_COR_OUT DOC
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND ((@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK)
				OR @intSVOD_ZB = 1)
	END
/*
	IF @varKSnOption1 = 2		-- Книга продаж (Выданные счета-фактуры) --
			OR @varKSnOption1 = 3
		INSERT INTO @TAB1	 -- Отбор всех выданных с/ф за период -- 
		SELECT DOC.LINK,
			DOC.BUY_LINK,	-- ПОКУПАЕТЛЬ --
			DOC.SUMMA,
			DOC.[DATE],
			DOC.NUMBER,
			DOC.DATE_BASE,
			RIGHT (REPLACE (SPACE (50), SPACE (1), '0') + LTRIM (RTRIM (DOC.NUMBER)), 50),
			2
		FROM dbo.DOCUMENTS_INVOICE_ISSUED DOC
		INNER JOIN dbo.DEPARTMENTS DEP ON ((DEP.ZB = 1 OR DEP.[TYPE] = 4)
						AND DEP.LINK = DOC.DEP_LINK)
		WHERE DOC.[DATE] BETWEEN @varKSdDate_1 AND @varKSdDate_2
			AND (@intSVOD_ZB = 0 AND DOC.DEP_LINK = @intDEP_LINK
				OR @intSVOD_ZB = 1)

*/

	-- Табличные части --
	DECLARE @TAB2 TABLE
		(DOC_LINK INT,
		NDS_TYPE VARCHAR (4),

		SUMMA NUMERIC (28,4),
		SUM_NDS NUMERIC (28,4),
		SUMMA_ALL NUMERIC (28,4),

		SUMMA_OLD NUMERIC (28,4),
		S_NDS_OLD NUMERIC (28,4),
		S_ALL_OLD NUMERIC (28,4),

		SUMMA_NEW NUMERIC (28,4),
		S_NDS_NEW NUMERIC (28,4),
		S_ALL_NEW NUMERIC (28,4),
		
		S_INC NUMERIC (28,4),
		S_DEC NUMERIC (28,4),

		S_NDS_INC NUMERIC (28,4),
		S_NDS_DEC NUMERIC (28,4),

		S_ALL_INC NUMERIC (28,4),
		S_ALL_DEC NUMERIC (28,4),

		IS_COR	TINYINT)

	-- Табличная часть с\ф --
	INSERT INTO @TAB2
	SELECT T1.LINK_DOC,
		ISNULL (T2.TNDS_CODE, ''),

		T2.SUMMA,
		T2.SUMMA_NDS,
		T2.SUMMA_ALL,
	
		T2.SUMMA,
		T2.SUMMA_NDS,
		T2.SUMMA_ALL,

		0, 0, 0,

		0, 0,
		0, 0,
		0, 0,
		0
	FROM @TAB1 T1
	INNER JOIN dbo.BK_DOC_TABLE_MZ_NDS_FN (DEFAULT) T2 ON (T2.LINK_UP = T1.LINK_DOC)
	WHERE T1.IS_COR = 0

	-- Табличная часть кор. с\ф --
	INSERT INTO @TAB2
	SELECT T1.LINK_DOC,
		ISNULL (T2.TNDS_CODE2, ''),

		0, 0, 0,		
		
		T2.SUMMA,
		T2.SUMMA_NDS,
		T2.SUMMA_ALL,

		T2.SUM_NEW,
		T2.S_NDS_NEW,
		T2.S_ALL_NEW,
		
		CASE
			WHEN T2.SUM_NEW > T2.SUMMA THEN T2.SUM_NEW - T2.SUMMA
			ELSE 0
		END,
		CASE
			WHEN T2.SUMMA > T2.SUM_NEW THEN T2.SUMMA - T2.SUM_NEW
			ELSE 0
		END,
		CASE
			WHEN T2.S_NDS_NEW > T2.SUMMA_NDS THEN T2.S_NDS_NEW - T2.SUMMA_NDS
			ELSE 0
		END,
		CASE
			WHEN T2.SUMMA_NDS > T2.S_NDS_NEW THEN T2.SUMMA_NDS - T2.S_NDS_NEW
			ELSE 0
		END,
		CASE
			WHEN T2.S_ALL_NEW > T2.SUMMA_ALL THEN T2.S_ALL_NEW - T2.SUMMA_ALL
			ELSE 0
		END,
		CASE
			WHEN T2.SUMMA_ALL > T2.S_ALL_NEW THEN T2.SUMMA_ALL - T2.S_ALL_NEW
			ELSE 0
		END,

		1
	FROM @TAB1 T1
	INNER JOIN dbo.BK_DOC_TAB_INVOICE_COR_FN (DEFAULT) T2 ON (T2.LINK_UP = T1.LINK_DOC)
	WHERE T1.IS_COR = 1

-- SELECT * FROM @TAB2
	
	-- Вычисляем суммы по документам и операции по НДС --
	DECLARE @TAB_SUM TABLE
		(DOC_LINK INT, 
		NDS_TYPE VARCHAR (100),
		SUMMA NUMERIC (28,4),
		SUM_NDS NUMERIC (28,4),
		SUMMA_ALL NUMERIC (28,4),

		S_INC NUMERIC (28,4),
		S_DEC NUMERIC (28,4),

		S_NDS_INC NUMERIC (28,4),
		S_NDS_DEC NUMERIC (28,4),

		S_ALL_INC NUMERIC (28,4),
		S_ALL_DEC NUMERIC (28,4)
		)

	-- Собираем виды операций по НДС --
	DECLARE #DATA_CURSOR CURSOR LOCAL STATIC	
	FOR
	SELECT DOC_LINK,
		NDS_TYPE
	FROM @TAB2
	GROUP BY DOC_LINK,
		NDS_TYPE
	ORDER BY DOC_LINK,
		NDS_TYPE

	OPEN #DATA_CURSOR
	FETCH FROM #DATA_CURSOR
		INTO @DOC_LINK, 
			@NDS_TYPE

	SET @CUR_DOC_LINK = 0

	WHILE @@FETCH_STATUS = 0
	BEGIN
		IF @DOC_LINK <> @CUR_DOC_LINK
		BEGIN
			INSERT INTO @TAB_SUM
			SELECT DOC_LINK,
				@NDS_TYPE_VAL,
				SUM (SUMMA),
				SUM (SUM_NDS),
				SUM (SUMMA_ALL),

				SUM (S_INC),
				SUM (S_DEC),
		
				SUM (S_NDS_INC),
				SUM (S_NDS_DEC),
		
				SUM (S_ALL_INC),
				SUM (S_ALL_DEC)

			FROM @TAB2 
			WHERE DOC_LINK = @CUR_DOC_LINK
			GROUP BY DOC_LINK

			SET @CUR_DOC_LINK = @DOC_LINK 
			SET @NDS_TYPE_VAL = ''
		END

		SET @NDS_TYPE_VAL = @NDS_TYPE_VAL
			+ CASE 
				WHEN @NDS_TYPE_VAL <> '' AND @NDS_TYPE <> '' THEN ', '
				ELSE ''
			END
			+ @NDS_TYPE

		FETCH FROM #DATA_CURSOR
			INTO @DOC_LINK, 
				@NDS_TYPE
	END

	CLOSE #DATA_CURSOR
	DEALLOCATE #DATA_CURSOR

	-- Запись последней итерации --
	INSERT INTO @TAB_SUM
	SELECT DOC_LINK,
		@NDS_TYPE_VAL,
		SUM (SUMMA),
		SUM (SUM_NDS),
		SUM (SUMMA_ALL),

		SUM (S_INC),
		SUM (S_DEC),

		SUM (S_NDS_INC),
		SUM (S_NDS_DEC),

		SUM (S_ALL_INC),
		SUM (S_ALL_DEC)
	FROM @TAB2 
	WHERE DOC_LINK = @CUR_DOC_LINK
	GROUP BY DOC_LINK

-- SELECT * FROM @TAB_SUM

	DECLARE @RESULT TABLE
		(DOC_LINK INT,
		DEP_NAME VARCHAR (254), DEP_INN VARCHAR (20), DEP_KPP VARCHAR (20),
		DEP_NAME1 VARCHAR (254), DEP_INN1 VARCHAR (20), DEP_KPP1 VARCHAR (20),
		
		BIL_DATE VARCHAR (10), 
		BIL_TYPE VARCHAR (20),
		
		NDS_TYPE VARCHAR (100),

		SORT_DATE DATETIME,

		DOC_DATE1 VARCHAR (10), DOC_NUM1 VARCHAR (50),
		DOC_DATE2 VARCHAR (10), DOC_NUM2 VARCHAR (50),

		COR_DATE1 VARCHAR (10), COR_NUM1 VARCHAR (50),
		COR_DATE2 VARCHAR (10), COR_NUM2 VARCHAR (50),

		DATE_OPL VARCHAR (10), SUM_TOTAL NUMERIC (28,4),
		SUMMA NUMERIC (28,4), SUM_NDS NUMERIC (28,4),

		S_INC NUMERIC (28,4),
		S_DEC NUMERIC (28,4),

		S_NDS_INC NUMERIC (28,4),
		S_NDS_DEC NUMERIC (28,4),

		S_ALL_INC NUMERIC (28,4),
		S_ALL_DEC NUMERIC (28,4),

		REP1 TINYINT, SORT_NUM VARCHAR (50),
		ORDERS TINYINT)

	INSERT INTO @RESULT
	SELECT T1.LINK_DOC,
		@strHD_Org_Name,
		@strHD_PUR_INN,
		@strHD_PUR_KPP,

		ISNULL (D1.NAME, ''),
		ISNULL (D1.INN, ''),
		ISNULL (D1.KPP, ''),

		CONVERT (VARCHAR (10), T1.BIL_DATE, 104),
		T1.BIL_CODE,
		
		ISNULL (TS.NDS_TYPE, ''),

		T1.SORT_DATE,

		CONVERT (VARCHAR (10), T1.DOC_DATE1, 104),
		T1.DOC_NUM1,
		CONVERT (VARCHAR (10), T1.DOC_DATE2, 104),
		T1.DOC_NUM2,

		CONVERT (VARCHAR (10), T1.COR_DATE1, 104),
		T1.COR_NUM1,
		CONVERT (VARCHAR (10), T1.COR_DATE2, 104),
		T1.COR_NUM2,


		ISNULL (CONVERT (VARCHAR (10), T1.DATE_OPL, 104), ''),

		ISNULL (TS.SUMMA_ALL, 0),
		ISNULL (TS.SUMMA, 0),
		ISNULL (TS.SUM_NDS, 0),

		ISNULL (TS.S_INC, 0),
		ISNULL (TS.S_DEC, 0),

		ISNULL (TS.S_NDS_INC, 0),
		ISNULL (TS.S_NDS_DEC, 0),

		ISNULL (TS.S_ALL_INC, 0),
		ISNULL (TS.S_ALL_DEC, 0),

		1,
		T1.SORT_NUM,
		T1.ORDERS
	FROM @TAB1 T1
	LEFT OUTER JOIN dbo.DEPARTMENTS D1 ON (D1.LINK = T1.DEP1)
	LEFT OUTER JOIN @TAB_SUM TS ON (TS.DOC_LINK = T1.LINK_DOC)

	SELECT
		*,
		D_QUART	=	@QUARTER,
		D_YEAR	= @YEAR,
		DOC_DATE = DOC_DATE1,
		DOC_NUM = DOC_NUM1
	FROM @RESULT
	ORDER BY ORDERS,
		SORT_DATE,
		SORT_NUM
END

GO


GRANT EXECUTE ON dbo.[BK_REPORT_JURN_INVOICE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_PRINT_TABEL_NEW]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_PRINT_TABEL_NEW]

GO

CREATE   PROCEDURE dbo.SA_PRINT_TABEL_NEW
	@varKSnLINKDoc INT,
	@varKSnOption1 INT= 1,
	@varKSnCheck1 INT = 0,
	@nSort3 int = 0 /*сортировка 3*/,
	@nCheck3 tinyint = 0 /*Фио полностью*/,
	@nCheck5 tinyint = 0 /* Пустой табель */,
	@varKSSUBDIV VARCHAR(254) OUTPUT, 
	@varKSSUBDIV_CODE VARCHAR(10) OUTPUT,
	@varKSDIV_CODE VARCHAR(10) OUTPUT, 
	@varKSDIV_NAME VARCHAR(254) OUTPUT,
	@varKSTI_CODE VARCHAR(10) OUTPUT, 
	@varKSTI_NAME VARCHAR(254) OUTPUT,
	@varKSEXP_CODE VARCHAR(10) OUTPUT, 
	@varKSEXP_NAME VARCHAR(254) OUTPUT

AS
BEGIN


	declare @varKSdDate1 DATETIME, @varKSdDate2 DATETIME
	SELECT @varKSdDate1 = PERIOD FROM TABELS WHERE LINK_DOC = @varKSnLINKDoc
	SELECT @varKSdDate1 = dbo.DateBeginOfMonth(@varKSdDate1)
	SELECT @varKSdDate2 = dbo.DateEndOfMonth(@varKSdDate1)

	CREATE TABLE #T_RES00 (
		ID VARCHAR(20),
		LINK_FACE INT, 
		LINK_EMPL INT,
		LINK_SOVM INT,
		FIO VARCHAR(254),
		NAME_EMPL VARCHAR(254),
		TN VARCHAR(10) ,
		SUBDIV_LINK INT, 
		CODE_SUB VARCHAR(10),
		SUBDIV VARCHAR(254) ,
		POST_LINK INT,
		CODE_POST VARCHAR(10),
		POST VARCHAR(254) ,
		LINK_DAY INT,
		SYMB VARCHAR(4),
		DAY_1 CHAR(2),	DAY_2 CHAR(2),	DAY_3 CHAR(2),	DAY_4 CHAR(2),	DAY_5 CHAR(2),
		DAY_6 CHAR(2),	DAY_7 CHAR(2),	DAY_8 CHAR(2),	DAY_9 CHAR(2),	DAY_10 CHAR(2),
		DAY_11 CHAR(2),	DAY_12 CHAR(2),	DAY_13 CHAR(2),	DAY_14 CHAR(2),	DAY_15 CHAR(2),
		DAY_16 CHAR(2),	DAY_17 CHAR(2),	DAY_18 CHAR(2),	DAY_19 CHAR(2),	DAY_20 CHAR(2),
		DAY_21 CHAR(2),	DAY_22 CHAR(2),	DAY_23 CHAR(2),	DAY_24 CHAR(2),	DAY_25 CHAR(2),
		DAY_26 CHAR(2),	DAY_27 CHAR(2),	DAY_28 CHAR(2),	DAY_29 CHAR(2),	DAY_30 CHAR(2),
		DAY_31 CHAR(2),
		
		H_1 NUMERIC(6,2),  H_2 NUMERIC(6,2),  H_3 NUMERIC(6,2),  H_4 NUMERIC(6,2),  H_5 NUMERIC(6,2),  H_6 NUMERIC(6,2),
		H_7 NUMERIC(6,2),  H_8 NUMERIC(6,2),  H_9 NUMERIC(6,2),  H_10 NUMERIC(6,2), H_11 NUMERIC(6,2), H_12 NUMERIC(6,2),
		H_13 NUMERIC(6,2), H_14 NUMERIC(6,2), H_15 NUMERIC(6,2), H_16 NUMERIC(6,2), H_17 NUMERIC(6,2), H_18 NUMERIC(6,2),
		H_19 NUMERIC(6,2), H_20 NUMERIC(6,2), H_21 NUMERIC(6,2), H_22 NUMERIC(6,2), H_23 NUMERIC(6,2), H_24 NUMERIC(6,2),
		H_25 NUMERIC(6,2), H_26 NUMERIC(6,2), H_27 NUMERIC(6,2), H_28 NUMERIC(6,2), H_29 NUMERIC(6,2), H_30 NUMERIC(6,2),
		H_31 NUMERIC(6,2),
		
		HALF_D INT, HALF_H NUMERIC(6,2), 	
		HALF2_D INT, HALF2_H NUMERIC(6,2), 	
		ALL_D INT, ALL_H NUMERIC(6,2), 		
		NONE_DAYS INT, NONE_HOURS NUMERIC(6,2)	,
		
		TYPE_1 INT, TYPE_1H NUMERIC(6,2), TYPE_2H INT, TYPE_2 INT, TYPE_3 INT, TYPE_4 INT, TYPE_5 INT, TYPE_6 INT, 
		TYPE_7 INT, TYPE_8 INT, TYPE_9 INT, TYPE_10 INT, TYPE_11 INT, TYPE_12 INT,

		TYPE_13 INT,	-- ОТРАБОТАНО В МЕСЯЦ СВЕРУХРОЧНЫХ ЧАСОВ
		TYPE_14 INT,	-- ОТРАБОТАНО В МЕСЯЦ НОЧНЫХ ЧАСОВ
		TYPE_15 INT,	-- ОТРАБОТАНО В МЕСЯЦ ЧАСОВ В ВЫХОДНЫЕ И ПРАЗДНИЧНЫЕ ДНИ
	) 

	---
	DECLARE @ISMINUTES TINYINT
	SET @ISMINUTES = DBO.SA_GET_OPTION_BY_CODE('TABEL_OPT10') --УЧЕТ ВРЕМЕНИ В ЧАСАХ И МИНУТАХ

	---
	declare @def_tdlink int, @def_tdname varchar(254), @def_tdsymb varchar(4)
	Select @def_tdlink = LINK, @def_tdname = [NAME], @def_tdsymb = SYMB from dbo.KD_TYP_DAYS where RTRIM(SYMB) = 'Я'

	select  LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY], 
		SUM([HOUR]) as [HOUR], 
		MAX(WORK_D) as WORK_D,
		MAX(TYP_YAV) AS TYP_YAV,
		(CASE when count(TYPE_DAY) = 1 then MAX(TYPE_DAY) else @def_tdlink end) as TYPE_DAY,
		(CASE when count(SYMB) = 1 then MAX(SYMB) else @def_tdsymb end) as SYMB,	
		(CASE when count(SYMB) = 1 then MAX(TYPE_DATY_NAME) else @def_tdname end) as TYPE_DATY_NAME
	into #tabel 
	from TABEL WHERE LINK_DOC = @varKSnLINKDoc
	group by LINK_DOC, NUMBER, DATE, LINK_EMPL, PERIOD, [DAY]
--	having count(SYMB) > 1
--AND TYPE_DAY not in (Select KOD from [dbo].[SA_TYPES_DOP_TAB])

	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_H1 = 
		CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END,

	DAYS_H2 = 
		CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
	+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
	+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END,

	HORS_H1 = SUM(W.D1) + SUM(W.D2) + SUM(W.D3) + SUM(W.D4) + SUM(W.D5) + SUM(W.D6) + SUM(W.D7) + SUM(W.D8) + SUM(W.D9) + SUM(W.D10) + SUM(W.D11) + SUM(W.D12) + SUM(W.D13) + SUM(W.D14) + SUM(W.D15),
	HORS_H2 = SUM(W.D16) + SUM(W.D17) + SUM(W.D18) + SUM(W.D19) + SUM(W.D20) + SUM(W.D21) + SUM(W.D22) + SUM(W.D23) + SUM(W.D24) + SUM(W.D25) + SUM(W.D26) + SUM(W.D27) + SUM(W.D28) + SUM(W.D29) + SUM(W.D30) + SUM(W.D31)
		
	INTO 
		#WORK_DAYS
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM

	--- Информация об отработанных днях
	SELECT W.LINK_UP1, W.LINK_SOVM,
	DAYS_Y7 = 
			CASE WHEN SUM(W.D1) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D2) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D3) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D4) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D5) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D6) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D7) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D8) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D9) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D10) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D11) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D12) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D13) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D14) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D15) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D16) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D17) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D18) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D19) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D20) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D21) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D22) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D23) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D24) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D25) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D26) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D27) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D28) > 0 THEN 1 ELSE 0 END
		+	CASE WHEN SUM(W.D29) > 0 THEN 1 ELSE 0 END +	CASE WHEN SUM(W.D30) > 0 THEN 1 ELSE 0 END 
		+	CASE WHEN SUM(W.D31) > 0 THEN 1 ELSE 0 END
	INTO 
		#WORK_DAYS1
	FROM 
		DBO.SA_TABELS_W W
	WHERE 
		LINK_UP = @varKSnLINKDoc
		AND
		TYP_YAVKA = 7
	GROUP BY 
		W.LINK_UP1, W.LINK_SOVM			

	--- Информация о неявках сотрудников
	SELECT 
		N.LINK_UP1,
		T.WORK_D,
		COUNT_DAYS = 
			CASE WHEN N.D1 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D2 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D3 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D4 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D5 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D6 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D7 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D8 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D9 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D10 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D11 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D12 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D13 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D14 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D15 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D16 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D17 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D18 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D19 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D20 = T.LINK THEN 1 ELSE 0 END

			+ CASE WHEN N.D21 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D22 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D23 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D24 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D25 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D26 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D27 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D28 = T.LINK THEN 1 ELSE 0 END
			+ CASE WHEN N.D29 = T.LINK THEN 1 ELSE 0 END + CASE WHEN N.D30 = T.LINK THEN 1 ELSE 0 END 
			+ CASE WHEN N.D31 = T.LINK THEN 1 ELSE 0 END 
	INTO 
		#NOTWORK_DAYS
	FROM
		DBO.SA_TABELS_N N, DBO.TYP_DAYS T
	WHERE
		LINK_UP = @varKSnLINKDoc

	---
	INSERT INTO #T_RES00
		(ID,LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST,
		LINK_DAY,
		SYMB,
		DAY_1,  DAY_2,  DAY_3,  DAY_4,  DAY_5,  DAY_6,  DAY_7,  DAY_8,  DAY_9,  DAY_10, 
		DAY_11, DAY_12, DAY_13, DAY_14, DAY_15, DAY_16, DAY_17, DAY_18, DAY_19, DAY_20, 
		DAY_21, DAY_22, DAY_23, DAY_24, DAY_25, DAY_26, DAY_27, DAY_28, DAY_29, DAY_30,
		DAY_31,
		H_1,  H_2, H_3,  H_4,  H_5,  H_6,  H_7,  H_8,  H_9,  H_10, 
		H_11, H_12, H_13, H_14, H_15, H_16, H_17, H_18, H_19, H_20, 
		H_21, H_22, H_23, H_24, H_25, H_26, H_27, H_28, H_29, H_30, 
		H_31,
		HALF_D, HALF_H,
		HALF2_D, HALF2_H,
		ALL_D, ALL_H,
		NONE_DAYS, NONE_HOURS,
		TYPE_1, TYPE_1H, TYPE_2, TYPE_2H, TYPE_3, TYPE_4, TYPE_5, TYPE_6, 
		TYPE_7, TYPE_8, TYPE_9, TYPE_10, TYPE_11, TYPE_12,

		TYPE_13,TYPE_14,TYPE_15

	)
	
	
	
	SELECT 
	
	ID,LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST,
	LINK_DAY = null,
	SYMB = '',
	DAY_1,  DAY_2,  DAY_3,  DAY_4,  DAY_5,  DAY_6,  DAY_7, DAY_8,  DAY_9, DAY_10, 
	DAY_11, DAY_12, DAY_13, DAY_14, DAY_15, DAY_16, DAY_17,DAY_18, DAY_19,DAY_20, 
	DAY_21, DAY_22, DAY_23, DAY_24, DAY_25, DAY_26, DAY_27,DAY_28, DAY_29,DAY_30,
	DAY_31,
	sum(H1),  sum(H2), sum(H3),  sum(H4),  sum(H5),  sum(H6),  sum(H7),  sum(H8),  sum(H9),  sum(H10), 
	sum(H11), sum(H12), sum(H13), sum(H14), sum(H15), sum(H16), sum(H17), sum(H18), sum(H19), sum(H20), 
	sum(H21), sum(H22), sum(H23), sum(H24), sum(H25), sum(H26), sum(H27), sum(H28), sum(H29), sum(H30), 
	sum(H31),
	HALF_D, sum(HALF_H),
	HALF_D2, sum(HALF_H2),
	ALL_D, ALL_H,
	NONE_DAYS, NONE_HOURS,
	TYPE_1, sum(TYPE_1H), sum(TYPE_2), sum(TYPE_2H), sum(TYPE_3), sum(TYPE_4), sum(TYPE_5), sum(TYPE_6), 
	sum(TYPE_7), sum(TYPE_8), sum(TYPE_9), sum(TYPE_10), sum(TYPE_11), sum(TYPE_12),
	sum(TYPE_13),sum(TYPE_14),sum(TYPE_15)

	
	
	
	
	from ( SELECT
		ID = RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_EMPL),10) +RIGHT( REPLACE(SPACE(20),SPACE(1),'0') + CONVERT(VARCHAR(20),WP.LINK_SOVM),10) ,
		[LINK_FACE] = P.LINK,
		WP.LINK_EMPL,
		WP.LINK_SOVM,
		[FIO]  = (case when coalesce(@nCheck3,0) = 1 then  coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(P.FM)) + ' ' + LTRIM(RTRIM(P.IM)) + ' ' + LTRIM(RTRIM(P.OT)),'Не заполнено'))),100), SPACE(100)) 
					else coalesce(LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30), SPACE(100)) end),
		[NAME_EMPL] = LEFT(LTRIM(RTRIM(COALESCE(LTRIM(RTRIM(FM)) + ' ' + LEFT(LTRIM(RTRIM(IM)),1) + '.' + LEFT(LTRIM(RTRIM(OT)),1) + '.', 'Не заполнено'))),30),
		[TN] 		= ISNULL(TE.TAB, SPACE(10)),
		[SUBDIV_LINK] = TE.SUBDIV_LINK,
		[CODE_SUB] = ISNULL( TE.SUBDIV_CODE, SPACE(10) ),
		[SUBDIV] = ISNULL( TE.SUBDIV_NAME, SPACE(254) ),
		[POST_LINK] = WP.POST_LINK,
		[CODE_POST] = ISNULL( WP.POST_CODE, SPACE(10) ),
		[POST] 		= ISNULL( WP.POST_NAME, SPACE(120) ),
		W.LINK_DAY,		
		W.SYMB,
		[DAY_1] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB1, SPACE(2) ) end,
		[DAY_2] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB2, SPACE(2) ) end,
		[DAY_3] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB3, SPACE(2) ) end,
		[DAY_4] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB4, SPACE(2) ) end,
		[DAY_5] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB5, SPACE(2) ) end,
		[DAY_6] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB6, SPACE(2) ) end,
		[DAY_7] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB7, SPACE(2) ) end,
		[DAY_8] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB8, SPACE(2) ) end,
		[DAY_9] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB9, SPACE(2) ) end,
		[DAY_10] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB10, SPACE(2) ) end,

		[DAY_11] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB11, SPACE(2) ) end,
		[DAY_12] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB12, SPACE(2) ) end,
		[DAY_13] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB13, SPACE(2) ) end,
		[DAY_14] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB14, SPACE(2) ) end,
		[DAY_15] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB15, SPACE(2) ) end,
		[DAY_16] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB16, SPACE(2) ) end,
		[DAY_17] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB17, SPACE(2) ) end,
		[DAY_18] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB18, SPACE(2) ) end,
		[DAY_19] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB19, SPACE(2) ) end,
		[DAY_20] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB20, SPACE(2) ) end,

		[DAY_21] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB21, SPACE(2) ) end,
		[DAY_22] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB22, SPACE(2) ) end,
		[DAY_23] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB23, SPACE(2) ) end,
		[DAY_24] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB24, SPACE(2) ) end,
		[DAY_25] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB25, SPACE(2) ) end,
		[DAY_26] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB26, SPACE(2) ) end,
		[DAY_27] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB27, SPACE(2) ) end,
		[DAY_28] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB28, SPACE(2) ) end,
		[DAY_29] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB29, SPACE(2) ) end,
		[DAY_30] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB30, SPACE(2) ) end,
		[DAY_31] =  case when @nCheck5 = 1 then '' else ISNULL( SYMB31, SPACE(2) ) end,

		[H1] = case when @nCheck5 = 1 then 0 else W.D1 end, 
		[H2] = case when @nCheck5 = 1 then 0 else W.D2 end,
		[H3] = case when @nCheck5 = 1 then 0 else W.D3 end,
		[H4] = case when @nCheck5 = 1 then 0 else W.D4 end, 
		[H5] = case when @nCheck5 = 1 then 0 else W.D5 end,
		[H6] = case when @nCheck5 = 1 then 0 else W.D6 end,
		[H7] = case when @nCheck5 = 1 then 0 else W.D7 end,  
		[H8] = case when @nCheck5 = 1 then 0 else W.D8 end, 
		[H9] = case when @nCheck5 = 1 then 0 else W.D9 end, 
		[H10] = case when @nCheck5 = 1 then 0 else W.D10 end,

		[H11] = case when @nCheck5 = 1 then 0 else W.D11 end,
		[H12] = case when @nCheck5 = 1 then 0 else W.D12 end, 
		[H13] = case when @nCheck5 = 1 then 0 else W.D13 end, 
		[H14] = case when @nCheck5 = 1 then 0 else W.D14 end, 
		[H15] = case when @nCheck5 = 1 then 0 else W.D15 end, 
		[H16] = case when @nCheck5 = 1 then 0 else W.D16 end, 
		[H17] = case when @nCheck5 = 1 then 0 else W.D17 end, 
		[H18] = case when @nCheck5 = 1 then 0 else W.D18 end, 
		[H19] = case when @nCheck5 = 1 then 0 else W.D19 end, 
		[H20] = case when @nCheck5 = 1 then 0 else W.D20 end, 

		[H21] = case when @nCheck5 = 1 then 0 else W.D21 end, 
		[H22] = case when @nCheck5 = 1 then 0 else W.D22 end, 
		[H23] = case when @nCheck5 = 1 then 0 else W.D23 end, 
		[H24] = case when @nCheck5 = 1 then 0 else W.D24 end, 
		[H25] = case when @nCheck5 = 1 then 0 else W.D25 end, 
		[H26] = case when @nCheck5 = 1 then 0 else W.D26 end, 
		[H27] = case when @nCheck5 = 1 then 0 else W.D27 end, 
		[H28] = case when @nCheck5 = 1 then 0 else W.D28 end, 
		[H29] = case when @nCheck5 = 1 then 0 else W.D29 end, 
		[H30] = case when @nCheck5 = 1 then 0 else W.D30 end, 
		[H31] = case when @nCheck5 = 1 then 0 else W.D31 end, 
--
		[HALF_D] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H1,0) end, 
		[HALF_H] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H1,0) end,

		[HALF_D2] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H2,0) end,
		[HALF_H2] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H2,0) end,

		[ALL_D] = case when @nCheck5 = 1 then 0 else isnull(WD.DAYS_H1,0) + isnull(WD.DAYS_H2,0) end,
		[ALL_H] = case when @nCheck5 = 1 then 0 else isnull(WD.HORS_H1,0) + isnull(WD.HORS_H2,0) end,

		[NONE_DAYS] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (4, 5, 6, 7, 8, 9, 10, 13)) end ) end,
		[NONE_HOURS] = case when @nCheck5 = 1 then 0 else 0 end,

		--Дни явок		
		[TYPE_1] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else COALESCE(WD.DAYS_H1,0) + COALESCE(WD.DAYS_H2,0) end) end,
		--Часы явок
		[TYPE_1H] =  case when @nCheck5 = 1 then 0 else 
			DBO.MINUTES_TO_NUM( 
			DBO.NUM_TO_MINUTES(W.D1,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D2,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D3,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D4,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D5,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D6,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D7,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D8,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D9,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D10,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D11,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D12,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D13,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D14,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D15,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D16,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D17,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D18,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D19,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D20,@ISMINUTES)

		+	DBO.NUM_TO_MINUTES(W.D21,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D22,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D23,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D24,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D25,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D26,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D27,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D28,@ISMINUTES)
		+	DBO.NUM_TO_MINUTES(W.D29,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D30,@ISMINUTES) +	DBO.NUM_TO_MINUTES(W.D31,@ISMINUTES)
		,@ISMINUTES) end,

		[TYPE_2] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 2) end,		-- командировка (дни)
		[TYPE_2H] = 0,	-- командировка (часы)
		[TYPE_3] = case when @nCheck5 = 1 then 0 else ISNULL((SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 3),0) + ISNULL(Y.DAYS_Y7,0) end,		-- повышение квалификации (дни)
		[TYPE_4] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 4) end,		-- очередной ежегодный отпуск НЕЯВКА (дни)
		[TYPE_5] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 5) end,		-- учебный отпуск НЕЯВКА (дни)
		[TYPE_6] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 6) end,		-- больничный НЕЯВКА (дни)
		[TYPE_7] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (7,13)) end, 	-- уход за ребенком НЕЯВКА (дни)
		[TYPE_8] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 8) end,		-- с разрешения администрации НЕЯВКА (дни)
		[TYPE_9] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 9) end,		-- прогул НЕЯВКА (дни)
		[TYPE_10] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 10) end,	-- невыясненные причины НЕЯВКА (дни)
		[TYPE_11] = case when @nCheck5 = 1 then 0 else (case when NOT (W.WORK_D = 1 AND W.TYP_YAVKA = 1) then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D IN (11,14)) end ) end,	-- выходные и праздничые НЕЯВКА (дни)
		[TYPE_12] = case when @nCheck5 = 1 then 0 else (SELECT SUM(COUNT_DAYS) FROM #NOTWORK_DAYS WHERE TE.LINK = LINK_UP1 AND WORK_D = 12) end,
		--
		[TYPE_13] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 4) end,	-- явка сверхурочно
		[TYPE_14] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 2) end, -- явка в ночное время
		[TYPE_15] = case when @nCheck5 = 1 then 0 else (SELECT COUNT(*)  FROM #TABEL WHERE LINK_EMPL = T.LINK_EMPL AND WORK_D = 1 and TYP_YAV = 3) end	-- явка в вызодные и праздничные
	FROM 
		DBO.TABELS T 
		INNER JOIN DBO.SA_TABELS_EMPLS TE ON T.LINK = TE.LINK
		INNER JOIN DBO.SA_TABELS_EMPLS_WP WP ON TE.LINK = WP.LINK_UP1
		INNER JOIN DBO.EMPL E ON E.LINK = TE.LINK_EMPL
		INNER JOIN DBO.PERSON P ON P.LINK = E.PERS_LINK
		LEFT JOIN DBO.SA_TABELS_N N ON TE.LINK = N.LINK_UP1
		LEFT JOIN DBO.SA_TABELS_W W ON TE.LINK = W.LINK_UP1 AND W.LINK_SOVM = WP.LINK_SOVM
		LEFT JOIN #WORK_DAYS WD ON TE.LINK = WD.LINK_UP1 AND WD.LINK_SOVM = WP.LINK_SOVM
		LEFT JOIN #WORK_DAYS1 Y ON TE.LINK = Y.LINK_UP1 AND WD.LINK_SOVM = Y.LINK_SOVM
	WHERE 
		T.LINK_DOC = @varKSnLINKDoc
	/*ORDER BY 
		1*/) a 
	GROUP BY  ID,LINK_FACE, LINK_EMPL, LINK_SOVM, FIO, NAME_EMPL, TN, SUBDIV_LINK, CODE_SUB, SUBDIV, POST_LINK, CODE_POST, POST,NONE_DAYS, NONE_HOURS,
	[DAY_1],[DAY_2],[DAY_3],[DAY_4],[DAY_5],[DAY_6],[DAY_7],[DAY_8],[DAY_9],[DAY_10],[DAY_11],[DAY_12],[DAY_13],[DAY_14],[DAY_15],[DAY_16],[DAY_17],[DAY_18],
	[DAY_19],[DAY_20],[DAY_21],[DAY_22],[DAY_23],[DAY_24],[DAY_25],[DAY_26],[DAY_27],[DAY_28],[DAY_29],[DAY_30],[DAY_31],ALL_D, ALL_H,HALF_D, HALF_D2,TYPE_1
	ORDER BY 
		1


IF (SELECT COUNT(DISTINCT SUBDIV_LINK) FROM #T_RES00) <> 1 BEGIN
		SELECT @varKSSUBDIV = '', @varKSSUBDIV_CODE = ''
	END
	ELSE 
		BEGIN
			SELECT TOP 1 @varKSSUBDIV = SUBDIV, @varKSSUBDIV_CODE = CODE_SUB FROM  #T_RES00
		END

	DECLARE 
		@varKSCNT1 INT, @varKSCNT2 INT, @varKSCNT3 INT
	
	SELECT TOP 1 
		@varKSCNT1 = COUNT(DISTINCT LINK_FKR_D), 
		@varKSCNT2 = COUNT(DISTINCT LINK_FKR_T), 
		@varKSCNT3 = COUNT(DISTINCT LINK_FKR_E),
		@varKSDIV_CODE = MAX(CODE_FKR_D),
		@varKSDIV_NAME = MAX(NAME_FKR_D),
		@varKSTI_CODE = MAX(CODE_FKR_T),
		@varKSTI_NAME = MAX(NAME_FKR_T),
		@varKSEXP_CODE = MAX(CODE_FKR_E),
		@varKSEXP_NAME = MAX(NAME_FKR_E)
	FROM DICTIONARY_PAYS_EMPL DPE
	INNER JOIN dbo.PAYS P ON DPE.LINK_PAYS = P.LINK
	INNER JOIN bi_diction_vkr VKR ON VKR.LINK = DPE.LINK_KBK
	INNER JOIN #T_RES00 R ON DPE.LINK_EMPL = R.LINK_EMPL
	where date_begin <= @varKSdDate2
		AND (DATE_END >= @varKSdDate1 OR DATE_END IS NULL) 


		declare @LINK_DEP int
		Set @LINK_DEP = Coalesce( (SELECT TOP 1 ZB_LINK FROM dbo.KS_OPTIONS_ZB), dbo.GetOwnDepLink())

		declare @nAVGCount numeric(18,2), @nMCount numeric(18,2)

		Select @nAVGCount = dbo.sa_ssch_empls(@varKSdDate1, @varKSdDate2, null, 0, 1, 0, DEFAULT)
		Select @nMCount = dbo.sa_sch_empls(@varKSdDate2, null, 0, 1, 0, DEFAULT)


	IF @varKSCNT1 <> 1
		SELECT @varKSDIV_CODE = '', @varKSDIV_NAME = ''
	IF @varKSCNT2 <> 1
		SELECT @varKSTI_CODE = '', @varKSTI_NAME = ''
	IF @varKSCNT3 <> 1
		SELECT @varKSEXP_CODE = '', @varKSEXP_NAME = ''

	SELECT *, @nAVGCount as AVGCount, @nMCount as MCount 
	FROM #T_RES00
	ORDER BY 
		LTRIM(RTRIM(CASE @varKSnOption1 
			WHEN 1 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 3 THEN POST
			WHEN 4 THEN FIO
			WHEN 5 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 6 THEN SUBDIV
			ELSE ''
		END)),

		LTRIM(RTRIM(CASE @varKSnCheck1 
			WHEN 2 THEN REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN POST
			WHEN 5 THEN FIO
			WHEN 6 THEN REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN SUBDIV
			ELSE ''
		END)),
		
		LTRIM(RTRIM(CASE @nSort3 
			WHEN 2 THEN '' + REPLICATE ('0',10 - len(ltrim(rtrim((TN))))) + ltrim(rtrim((TN))) 
			WHEN 3 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_POST))))) + ltrim(rtrim((CODE_POST)))
			WHEN 4 THEN '' +POST
			WHEN 5 THEN '' +FIO
			WHEN 6 THEN '' +REPLICATE ('0',10 - len(ltrim(rtrim((CODE_SUB))))) + ltrim(rtrim((CODE_SUB)))
			WHEN 7 THEN '' +SUBDIV
			ELSE ''
		END))

END












GO


GRANT EXECUTE ON dbo.[SA_PRINT_TABEL_NEW] TO PUBLIC

GO




GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[XU_ADMIN_BACKUP_FILELIST]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[XU_ADMIN_BACKUP_FILELIST]

GO

CREATE     PROCEDURE [dbo].XU_ADMIN_BACKUP_FILELIST
	@parFILENAME	varchar(254) = null
AS
	CREATE TABLE #filelist (LogicalName nvarchar(128), PhysicalName nvarchar(260), Type char(1), FileGroupName nvarchar(128),
			[Size] numeric(20,0), [MaxSize] numeric(20,0))
	
	IF @@microsoftversion / 0x01000000  >= 9
		ALTER table #filelist
		ADD 
		FileID bigint,
 		CreateLSN numeric(25,0),
		DropLSN numeric(25,0) NULL,
		UniqueID uniqueidentifier,
		ReadOnlyLSN numeric(25,0) NULL,
		ReadWriteLSN numeric(25,0) NULL,
		BackupSizeInBytes bigint,
		SourceBlockSize int,
		FileGroupID int,
		LogGroupGUID uniqueidentifier NULL,
		DifferentialBaseLSN numeric(25,0) NULL,
		DifferentialBaseGUID uniqueidentifier,
		IsReadOnly bit,
		IsPresent bit

	IF @@microsoftversion / 0x01000000  >= 10
		ALTER table #filelist
		ADD 
		TDEThumbprint varchar(16)

	IF @parFILENAME is null BEGIN
		SELECT TOP 1 checked=convert(bit, 0), * FROM #filelist
		RETURN 0
	END
	DECLARE @FExists int, @FisDir int
	CREATE TABLE #temp (FExists int, FisDir int, Parent int)
	INSERT INTO #temp
	EXECUTE master.dbo.xp_fileexist @parFILENAME
	IF @@ERROR<>0
		RETURN 7
	--есть ли вообще такой файл и не каталог ли это
	SELECT @FExists = FExists, @FisDir = FisDir FROM #temp
	IF @FExists=0 or @FisDir=1
		RETURN 131
	INSERT #filelist
	EXEC XU_ADMIN_RESTORE_FILELISTONLY @parFILENAME
	SELECT checked = convert(bit, 0), LogicalName, PhysicalName = convert(varchar(254), PhysicalName), Type, FileGroupName, [Size], [MaxSize] FROM #filelist
RETURN 0







GO


GRANT EXECUTE ON dbo.[XU_ADMIN_BACKUP_FILELIST] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BS_SetWorkMode]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BS_SetWorkMode]

GO
CREATE PROCEDURE dbo.BS_SetWorkMode
	(@WORK_MODE	VARCHAR (30),
	@WORK_STATUS	TINYINT	=	1
	)
AS
BEGIN
	SET @WORK_STATUS = ISNULL (@WORK_STATUS, 0)

	IF EXISTS (SELECT * FROM dbo.BS_WORKMODE WHERE WORK_MODE = @WORK_MODE)
		UPDATE dbo.BS_WORKMODE
		SET WORK_STATUS = @WORK_STATUS
		WHERE WORK_MODE = @WORK_MODE
	ELSE
		INSERT INTO dbo.BS_WORKMODE
		SELECT
			@WORK_MODE,
			@WORK_STATUS
END

GO

GRANT EXECUTE ON dbo.[BS_SetWorkMode] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SS_REP_CARD_NDFL]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SS_REP_CARD_NDFL]

GO

CREATE PROCEDURE dbo.SS_REP_CARD_NDFL
	@cYear varchar(4),
	@nMonth varchar (2) ,			
	@nFirstNum varchar (10) = '',
	@LINK_EMPL int = NULL,  
	@LINK_PERS int = NULL,
	@nCheck1 INT = 0 , 
	@nSum1 numeric(18,2) = NULL, /*Перечисленная сумма НДФЛ за январь*/
	@nSum2 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за февраль*/
	@nSum3 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за март*/
	@nSum4 numeric(18,2) = NULL, /*Перечисленная сумма НДФЛ за апрель*/
	@nSum5 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за май*/
	@nSum6 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за июнь*/
	@nSum7 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за июль*/
	@nSum8 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за август*/
	@nSum9 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за сентябрь*/
	@nSum10 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за октябрь*/
	@nSum11 numeric(18,2) = NULL,/*Перечисленная сумма НДФЛ за ноябрь*/
	@nSum12 numeric(18,2) = NULL/*Перечисленная сумма НДФЛ за декабрь*/
AS BEGIN

SET NOCOUNT ON

 
	Set @nMonth = (case when len(@nMonth)<2 then '0'+@nMonth  else @nMonth  end)

	DECLARE @varKSnYear INT
	SET @varKSnYear = CAST(@cYear AS INT)

	DECLARE @BEGIN_YEAR DATETIME
	SET @BEGIN_YEAR = dbo.ConvertDMY2Date(1,1,@varKSnYear)
	---------------------------------
	--определим последний день в месяце
	declare @eDay varchar (2)
	set @eDay = (select day(max(d.date1))  from dbo.days_month(@nMonth,@cYear)d)
/*	print @eDay*/

	
	DECLARE @PRES_DATE DATETIME,
			@PRESENT_DATE varchar (10) 			
	SET @PRES_DATE = dbo.ConvertDMY2Date(@eDay,@nMonth,@varKSnYear)
	SET @PRESENT_DATE = (@cYear + @nMonth + @eDay )

	declare @DEP_LINK int
	exec dbo.xd_whats_zb @DEP_LINK output

	SELECT * INTO #DICT_TYP_INCOMS FROM dbo.DICTIONARY_TYP_INCOMS
	SELECT * INTO #Salary_deductions FROM dbo.Salary_deductions(@PRESENT_DATE)	

	CREATE TABLE #PERSON (
		NOM_SPR varchar (10),
		SEX INT,
		INNFIZ VARCHAR(20),
		NUMB_SERT VARCHAR(20),
		STATUS VARCHAR(1),
		FIO VARCHAR(254),
		FM VARCHAR(254),
		IM VARCHAR(254),
		OT VARCHAR(254),
		NMD VARCHAR(50),
		KDVD VARCHAR(4),
		SERNOM VARCHAR(254), 
		BIRTH DATETIME,
		GRAZD VARCHAR(3),
		KSTR VARCHAR(3),
		LINK_ADR INT,
		IND_ADR VARCHAR(10),
		REGION VARCHAR(4),
		RAION VARCHAR(254),
		GOROD VARCHAR(254),
		NASEL VARCHAR(254),
		STREET VARCHAR(254),
		HOUSE VARCHAR(20),
		KORP VARCHAR(10),
		FLAT VARCHAR(10),

		KSTR_ino VARCHAR(3),
		Adr_ino VARCHAR(200),

		O_OKATO VARCHAR(14),
		O_OKTMO VARCHAR(11),
		O_KPP VARCHAR(9),		
		
	)	

	if isnull(@LINK_EMPL,0) = 0
		set @LINK_EMPL =  (SELECT TOP 1 LINK FROM dbo.SD_EMPL WHERE PERS_LINK = @LINK_PERS AND STATUS_EMPL IN (1,3) AND ISNULL(DATE_END,@BEGIN_YEAR) >= @BEGIN_YEAR AND DEP_LINK = @DEP_LINK )

	if isnull(@LINK_PERS,0)= 0
		set @LINK_PERS =  (SELECT TOP 1 PERS_LINK FROM dbo.EMPL WHERE LINK = @LINK_EMPL)


	declare @Status int
	Select @Status= [STATUS] from dbo.ITEM_MOVE where ACTIVE = 1 and EMPL_LINK = @LINK_EMPL	-->>NEW

	--Все сотрудники в данной организации с заданным @LINK_PERS
	CREATE TABLE #EMPLS (LINK INT, LINK_PERS INT)

	INSERT INTO #EMPLS(LINK, LINK_PERS)
	SELECT distinct LINK, @LINK_PERS FROM dbo.empl WHERE PERS_LINK = @LINK_PERS AND DEP_LINK = @DEP_LINK

	-----------------------------
	delete from dbo.SAL_DED_MONTH
	where 
	YEAR(DATE_DED) = @varKSnYear
	AND
	Month(DATE_DED) <= @nMonth
	AND
	LINK_EMPL IN (Select EM.LINK from #EMPLS EM)
	AND
	LINK IN 
	(
		select D.LINK 
		from dbo.SAL_DED_MONTH D inner join dbo.empl E on D.link_empl = E.link
		where YEAR(D.DATE_DED) = @varKSnYear AND Month(D.DATE_DED) <= @nMonth
		and not exists (Select * from dbo.CALCULATE_JURNAL JC where YEAR(JC.PERIOD_BEGIN) = @varKSnYear AND Month(JC.PERIOD_BEGIN) <= @nMonth AND JC.LINK_EMPL = E.LINK AND JC.LINK_VKR = D.LINK_VKR)
	)
	-----------------------------	

	EXEC dbo.BufferClear
	EXEC dbo.BufferPushTable '#EMPLS', 'REP2NDFL', 'LINK_PERS'

	/*Временная таблица*/
	Declare @isPrevPreiod tinyint
	--Суммы начислений включать в базу расчета в том месяце, в котором он был начислен.                   
	Set @isPrevPreiod = dbo.sa_get_option_by_code('NDFL_OPT6')

	create table #S_J_C_SHORT (LINK_FACE int,PERS_LINK int, link_empl int, link_pays int, link_vkr int, link_ekr int, typ_per tinyint, typ_oper tinyint, summa numeric(18,2), link_inc int, code_inc varchar(4), period_begin datetime, period_END datetime, date1 datetime, link_dep int)

	Insert into #S_J_C_SHORT (LINK_FACE, PERS_LINK, link_empl, link_pays, link_vkr, link_ekr, typ_per, typ_oper, summa, link_inc,code_inc, period_begin, period_end, date1, link_dep)
	Select 
		E.PERS_LINK, JC.PERS_LINK, JC.LINK_EMPL, P.LINK, link_vkr, ISNULL(JC.LINK_EKR,P.LINK_EKR), P.TYP_PER, P.OBJECT, summa, P.LINK_INC,
		CODE_INC = CONVERT(VARCHAR(5), (SELECT top 1 DA.VALUE FROM DICTION_APP DA WHERE DA.LINK_UP = P.LINK_INC AND 
							        da.OBJECT =(SELECT top 1 LINK FROM S_OBJECTS WHERE CODE = 'COLUMN_CODE_T_INC'))),
		period_begin = (case when @isPrevPreiod = 0 then JC.period_begin 
				else (Case 
						when JC.DATE_BEGIN < JC.period_begin and year(JC.DATE_BEGIN) = year(JC.period_begin) and d.code = 'DOCUMENTS_ADD_TABEL'
						then JC.DATE_BEGIN else JC.period_begin 
					end) 
				end),
		JC.period_END,		
		JC.DATE_BEGIN,
		JC.LINK_DEP
	from 
		dbo.CALCULATE_JURNAL JC 
		INNER JOIN dbo.NDFL_GroupTax() T ON JC.LINK_PAYS=T.LINK_PAYS
		LEFT JOIN dbo.EMPL E ON JC.LINK_EMPL = E.LINK
		LEFT JOIN dbo.PAYS P ON JC.LINK_PAYS = P.LINK
		LEFT JOIN (Select d.link, o.code from sdoc d inner join dbo.s_objects o on d.object = o.link) d on jc.LINK_DOC = d.link
	where
		(
				(@isPrevPreiod = 0 or ISNULL(d.code,'') <> 'DOCUMENTS_ADD_TABEL') and @nMonth >= month(JC.PERIOD_BEGIN) and @varKSnYear = year(JC.PERIOD_BEGIN)
				or 
				@isPrevPreiod = 1 and ISNULL(d.code,'') = 'DOCUMENTS_ADD_TABEL'
				and (@nMonth >= month(JC.DATE_BEGIN) or @nMonth >= month(JC.PERIOD_BEGIN) )
				and (@varKSnYear = year(JC.DATE_BEGIN) or @varKSnYear = year(JC.PERIOD_BEGIN) )

			)
		AND  
			(	-->>NEW
			E.PERS_LINK = @LINK_PERS
			or
			JC.PERS_LINK = @LINK_PERS
			)	
		AND JC.LINK_DEP = @DEP_LINK 
	union all --Удержания
	Select LINK_FACE, PERS_LINK, link_empl, link_pays, link_vkr, link_ekr, typ_per, typ_oper, summa, link_inc,
			CODE_INC = CONVERT(VARCHAR(5), (SELECT top 1 DA.VALUE FROM DICTION_APP DA WHERE DA.LINK_UP = sjc.LINK_INC AND 
							        da.OBJECT =(SELECT top 1 LINK FROM S_OBJECTS WHERE CODE = 'COLUMN_CODE_T_INC'))),
			 period_begin, period_end, date1, link_dep
	from dbo.S_J_C_SHORT SJC 
		LEFT JOIN #DICT_TYP_INCOMS DTI ON DTI.LINK = SJC.LINK_INC 
	where 
		SJC.LINK_DEP = @DEP_LINK
		and
		(
			SJC.LINK_FACE = @LINK_PERS
			or
			SJC.PERS_LINK = @LINK_PERS
		)
		and YEAR(SJC.PERIOD_BEGIN) = @varKSnYear
		and Month(SJC.PERIOD_BEGIN) <= @nMonth
		and TYP_OPER = 2

--select * from SDOC where link = SJC.link_doc
-----------------------------------------------------------
--Для обособленных подразделений
DECLARE @DATE DATETIME
SET @DATE = DBO.ConvertDMY2Date(1,@nMonth, @varKSnYear)
SET @DATE = DBO.DateEndOfMonth(@DATE)

CREATE TABLE #E_SUBDIV (EMPL_LINK INT, SUBDIV_LINK INT)
INSERT INTO #E_SUBDIV (EMPL_LINK, SUBDIV_LINK)
SELECT EMPL_LINK, SUBDIV_LINK
FROM DBO.SA_EMPLS_INFO(@DATE, DEFAULT)
WHERE [STATUS] = 1 OR [STATUS] = 3

CREATE TABLE #S_OBOSOB (SUBDIV_LINK INT, O_OKATO VARCHAR(14), O_OKTMO VARCHAR(11), O_KPP VARCHAR(9))
INSERT INTO #S_OBOSOB (SUBDIV_LINK, O_OKATO, O_OKTMO, O_KPP)
SELECT SUBDIV_LINK, O_OKATO,O_OKTMO, O_KPP 
FROM [dbo].SUBDIVISION(@DATE) 
WHERE OBOSOB = 1

CREATE TABLE #P_OBOSOB (PERS_LINK INT, O_OKATO VARCHAR(14), O_OKTMO VARCHAR(11), O_KPP VARCHAR(9))
INSERT INTO #P_OBOSOB(PERS_LINK, O_OKATO, O_OKTMO, O_KPP)
SELECT TOP 1 E.PERS_LINK, SO.O_OKATO,SO.O_OKTMO, SO.O_KPP 
FROM 
	#S_OBOSOB SO INNER JOIN #E_SUBDIV ES ON SO.SUBDIV_LINK = ES.SUBDIV_LINK
	INNER JOIN DBO.EMPL E ON E.LINK = ES.EMPL_LINK
WHERE
	E.PERS_LINK = @LINK_PERS

-----------------------------------------------------------
	INSERT INTO #PERSON (
		SEX,
		INNFIZ, --NALOG,
		NUMB_SERT,
		STATUS,
		FIO,
		FM, IM, OT,
		NMD,
		KDVD,
		SERNOM, 
		BIRTH,
		GRAZD,
		KSTR,
		LINK_ADR,
		IND_ADR,
		REGION,
		RAION,
		GOROD,
		NASEL,
		STREET,
		HOUSE,
		KORP,
		FLAT, 
		KSTR_ino,
		Adr_ino,
		O_OKATO,
		O_OKTMO,
		O_KPP
	)

	SELECT 	distinct 
		P.SEX, P.INN, /*P.IFNS,*/ P.INSUR_NUM, 
		CASE 
			WHEN P.RESIDENT  IS NULL THEN ''
			WHEN P.RESIDENT = 1 THEN '1'
			WHEN P.RESIDENT = 0 THEN '2'
			WHEN P.RESIDENT = 2 THEN '2'
		END,
		RTRIM(P.FM) + ',' + RTRIM(P.IM) + ',' + RTRIM(P.OT),
		RTRIM(P.FM), RTRIM(P.IM), RTRIM(P.OT),
		[NMD] = (SELECT TOP 1 NAME FROM FACE_DOCUMENT WHERE LINK = P.DOC_LINK),
		[KDVD] = (SELECT TOP 1 CODE FROM FACE_DOCUMENT WHERE LINK = P.DOC_LINK),
		P.DOC_NUM,
		P.BIRTHDATE,
		GRAZD= (SELECT TOP 1 CODE FROM CITIZENSHIP WHERE LINK = P.CITIZ_LINK),
		KSTR= (case when (SELECT TOP 1 CODE FROM CITIZENSHIP WHERE LINK = P.CITIZ_LINK) = '1' then '643' else '' END),
		ADR.LINK_ADDR,
		ADR.IND_ADR,
		ADR.REGION,
		ADR.RAION,
		ADR.GOROD,
		ADR.NASEL,
		ADR.STREET,
		ADR.HOUSE,
		ADR.KORP,
		ADR.FLAT,
		KSTR_ino = '',
		Adr_ino = '',
		isnull(PO.O_OKATO, '') ,
		isnull(PO.O_OKTMO, ''),
		isnull(PO.O_KPP, '')
	FROM 
		dbo.PERSON P
		LEFT OUTER JOIN dbo.NDFL_GET_ADDRESS() ADR ON P.LINK = ADR.LINK_FACE
		LEFT JOIN #P_OBOSOB PO ON 1=1
	WHERE
		P.LINK = @LINK_PERS		
		
	ORDER BY 
		RTRIM(P.FM) + ',' + RTRIM(P.IM) + ',' + RTRIM(P.OT)
	
			
	UPDATE #PERSON SET NOM_SPR = @nFirstNum 

	select distinct LINK_FACE, Y = year(PERIOD_BEGIN), M = month(PERIOD_BEGIN),  LINK_INC, LINK_VKR  
	into #spr_pays_kbk
	from 	#S_J_C_SHORT where TYP_OPER = 1


	---->>

	SELECT D.LINK_FACE, D.mes, SUM(D.SUMMA) as SUMMA, D.REF_DED 
	INTO #DED 
	FROM 
		dbo.SA_NDFL_MONTH_DED_ALL(@varKSnYear) D 
		inner join #spr_pays_kbk kbk on kbk.LINK_FACE = d.LINK_FACE and kbk.m = d.mes and kbk.link_inc = d.REF_INC and kbk.LINK_VKR = d.LINK_VKR
	where 
		kbk.y = @varKSnYear
		and kbk.m <= @nMonth
	GROUP BY 
		D.LINK_FACE, d.mes, d.REF_DED
		
	

	-- выборка заявленных вычетов по сотрудникам 
	---------------------------------
	CREATE  TABLE  #RES_VICHET (LINK INT, LINK_EMPL INT, LINK_PERS int, LINK_DED INT, CODE_DED VARCHAR(6), NAME_DED VARCHAR(254), SUMMA NUMERIC(10,2), PREDEL NUMERIC(28,2), TYPE NUMERIC(3,0), DATE1 DATETIME, DATE2 DATETIME,M_BEG INT, M_END INT, NUM_ROW int identity(1,1), FIO VARCHAR(60), BIRTHDAY DATETIME, AGE INT)
	INSERT INTO #RES_VICHET
	SELECT ed.LINK, 
		   ed.EMPL_LINK AS LINK_EMPL,
		   @LINK_PERS as  LINK_PERS,
		   ed.DED_LINK AS LINK_DED,
           sd.CODE AS CODE_DED,
           sd.NAME AS NAME_DED,
           sd.SUMMA AS SUMMA,
           /*(SELECT CODE
            FROM   dbo.DICTIONARY_TYP_DEDUCTION AS DTD
            WHERE  (LINK = ED.DED_LINK)) AS CODE_DED,
           (SELECT NAME
            FROM   dbo.DICTIONARY_TYP_DEDUCTION AS DTD
            WHERE  (LINK = ED.DED_LINK)) AS NAME_DED, 
           (SELECT SUMMA
            FROM   dbo.DICTIONARY_TYP_DEDUCTION AS DTD
            WHERE  (LINK = ED.DED_LINK)) AS SUMMA, 
            */sd.predel,
            sd.type,
            ed.DATE1, 
            ed.DATE2,
			0,
            0,
            '',
            '',
            0
	FROM dbo.EMPL_DED AS ED 
			INNER JOIN #EMPLS R  ON  ED.empl_link = R.LINK
			inner join  #Salary_deductions sd on sd.ref_pay = ed.ded_link and sd.type = '1'

	where 
		ed.date1 <= @PRES_DATE 
				AND (ed.date2 IS NULL OR YEAR(ed.date2) = '1900' OR year(ed.date2) >=@varKSnYear)
				and @nMonth >= month(ed.date1) 
				and @varKSnYear = year(ed.date1)
				
	update #RES_VICHET
		set M_BEG =  case when year(DATE1)< @cYear then 1
					      when year(DATE1)= @cYear then Month(DATE1) 
						  end,
			M_END = case when DATE2 is null then null
					      when DATE2 is not null and month(DATE2) <= @nMonth then Month(DATE2)
					      when DATE2 is not null and month(DATE2) > @nMonth then null
						  end 
	from #RES_VICHET


	if exists(select CODE_DED from #RES_VICHET where NAME_DED like ('%ребенка%'))
	begin

		create table #CHILDS (ROW_ID int identity(1,1),FIO varchar (60) , BIRTHDAY DATETIME, AGE INT )
		insert into #CHILDS  ( FIO, BIRTHDAY, AGE )
		SELECT 	
			distinct
			[FIO] = CONVERT(VARCHAR(60),RTRIM(FM) +' '+RTRIM(IM) + ' '+ RTRIM(OT)),
			[BIRTHDAY] = BIRTHDATE,
			[AGE] = DATEDIFF(year,BIRTHDATE,dbo.DateEndOfYear(dbo.SalaryCalcPeriod())) 
		FROM 
			dbo.KU_PERS_FAMILY  
		WHERE 
			PERS_LINK = @LINK_PERS
			AND
			FAMILY_NAME IN ('Сын','Дочь', 'Пасынок', 'Падчерица')
			and datediff(yy, BIRTHDATE, dbo.ConvertDMY2Date(1,1,@cYear)) <18

	
		create table #CHILDS_res (LINK INT, LINK_EMPL INT, LINK_PERS int, LINK_DED INT, CODE_DED VARCHAR(6), NAME_DED VARCHAR(254), SUMMA NUMERIC(10,2), PREDEL NUMERIC(28,2), TYPE NUMERIC(3,0), DATE1 DATETIME, DATE2 DATETIME,M_BEG INT, M_END INT, NUM_ROW int, N_ROW_C int identity(1,1), FIO VARCHAR(60), BIRTHDAY DATETIME, AGE INT)
		insert into #CHILDS_res 
		select  r.*
		from #RES_VICHET r where r.NAME_DED like ('%ребенка%')

		update #CHILDS_res
		Set	[FIO] = c.FIO,
			[BIRTHDAY] = c.BIRTHDAY,
			[AGE] = c.AGE
		FROM 
			#CHILDS_res v ,#CHILDS c 
		WHERE 
			v.N_ROW_C = c.ROW_ID

		update #RES_VICHET
		Set	[FIO] = v.FIO,
			[BIRTHDAY] = v.BIRTHDAY,
			[AGE] = v.AGE
		FROM 
			#RES_VICHET r , #CHILDS_res v 
		WHERE 
			r.link = v.link
			
		drop table #CHILDS_res
		drop table  #CHILDS
	end	
	else 
	begin
		


		insert into #RES_VICHET 
		select distinct	
		   0, 
		   0, 
		   0,
		   0,
           '',
           '', 
           0, 
           0,
           0,
           '',
           '',
           0, 
           0,
		   CONVERT(VARCHAR(60),RTRIM(F.FM) +' '+RTRIM(F.IM) + ' '+ RTRIM(F.OT)),
		   isnull(F.BIRTHDATE,''),
		   DATEDIFF(year,F.BIRTHDATE,dbo.DateEndOfYear(dbo.SalaryCalcPeriod()))
		FROM 
			dbo.KU_PERS_FAMILY F
		WHERE 
			F.PERS_LINK = @LINK_PERS
			AND
			F.FAMILY_NAME IN ('Сын','Дочь', 'Пасынок', 'Падчерица')
			--and datediff(yy, BIRTHDATE, dbo.ConvertDMY2Date(1,1,@cYear)) <18
	end 	


	--- если в таблице нет кода с вычетом 103, то добавляем пустую строку и код 103 - для вывода в excel
	if not exists(select * from #RES_VICHET where code_ded = '103')
	begin
		insert into #RES_VICHET 
		select distinct	
		   null, 
		   null, 
		   null,
		   null,
           '103',
           ' ', 
           null, 
           null,
           null,
           null,
           null,
           null, 
           null,
           null,
		   null,
		   null
	end
	
	if not exists(select * from #RES_VICHET where code_ded <> '103' and name_ded not like '%на налогоплательщика%')
		begin
		insert into #RES_VICHET 
		select distinct	
		   0, 
		   0, 
		   0,
		   0,
           ' ',
		   '', 
           0, 
           0,
           0,
           '',
           '',
           0, 
           0,
           null,
		   null,
		   null
	   
	end
	--- 

	--- выборка детей работников 
		CREATE  TABLE  #RES_CHILD_VICHET(PERS_LINK INT, FIO VARCHAR(60), BIRTHDAY DATETIME, AGE INT)
		INSERT INTO #RES_CHILD_VICHET
		SELECT F.PERS_LINK,
			[FIO] = CONVERT(VARCHAR(60),RTRIM(F.FM) +' '+RTRIM(F.IM) + ' '+ RTRIM(F.OT)),
			[BIRTHDAY] = F.BIRTHDATE,
			[AGE] = DATEDIFF(year,F.BIRTHDATE,dbo.DateEndOfYear(dbo.SalaryCalcPeriod()))
		FROM 
			dbo.KU_PERS_FAMILY F
		WHERE 
			F.PERS_LINK = @LINK_PERS
			AND
			F.FAMILY_NAME IN ('Сын','Дочь', 'Пасынок', 'Падчерица')
		

	DECLARE @varKSStatus VARCHAR(1)
	Set @varKSStatus = COALESCE((SELECT TOP 1 STATUS FROM #PERSON),1) /*резидент, не резидент*/	
	--- выборка имущественных вычетов	
	CREATE  TABLE  #RES_IM_VICHET (LINK INT, LINK_EMPL INT, LINK_DED INT, YEAR INT, MONTH1 TINYINT, CODE_DED VARCHAR(6), NAME_DED VARCHAR(254), F_NAME VARCHAR(254), 
		SUM_DED NUMERIC(10,2),NUM_REF VARCHAR(15), IFNS_CODE VARCHAR(20), PREDEL NUMERIC(28,2), TYPE NUMERIC(3,0), DATE_ref DATETIME)
	INSERT INTO #RES_IM_VICHET
	SELECT distinct TD.LINK, 
		   TD.LINK_PERSON AS LINK_EMPL, 
		   TD.LINK_DICTION AS LINK_DED,
		   TD.YEAR,
		   TD.MONTH1,
		   CODE_DED = SPR.CODE,
           NAME_DED = SPR.NAME,
           F_NAME = case when SPR.CODE = '311' or SPR.CODE = '313' then 'Прямые расходы на  новое строительство и (или) приобретение'
						 when SPR.CODE = '312' then 'Погашение процентов по кредитам'
						 when SPR.CODE = '318' then 'Погашение процентов по кредитам на рефинансирование ипотечных займов'
						 else  SPR.NAME end ,
            TD.SUM_DED,
            TD.NUM_REF,
            TD.IFNS_CODE, 
            PREDEL = ISNULL(sd.SUMMA,SPR.SUMMA),
            sd.type,
            TD.DATE_REF
	FROM dbo.TAX_DEDUCTIONS AS TD 
			INNER JOIN #EMPLS R  ON  TD.link_person = R.LINK_PERS
			INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = td.LINK_DICTION AND SPR.NUMBER = 4
			LEFT JOIN #Salary_deductions sd on sd.ref_pay = td.LINK_DICTION and sd.type = '4'
	where 
		YEAR(td.date_ref) = @cYear 
		AND
		TD.LINK_DEP = @DEP_LINK
	group by td.LINK, TD.LINK_PERSON, TD.LINK_DICTION, SPR.CODE, SPR.NAME,	TD.YEAR,TD.MONTH1,  TD.SUM_DED, TD.NUM_REF, TD.IFNS_CODE, sd.SUMMA,SPR.SUMMA, sd.type, TD.DATE_REF

	---------	 Необлагаемые доходы	
	CREATE  TABLE  #RES_NE_VICHET (CODE_DED VARCHAR(6), NAME_DED VARCHAR(254), PREDEL NUMERIC(10,2), CODE_INC varchar(5), NAME_INC VARCHAR(254),  
				SUMMA_M1 NUMERIC(10,2),SUMMA_M2 NUMERIC(10,2),SUMMA_M3 NUMERIC(10,2),SUMMA_M4 NUMERIC(10,2),
				SUMMA_M5 NUMERIC(10,2),SUMMA_M6 NUMERIC(10,2),SUMMA_M7 NUMERIC(10,2),SUMMA_M8 NUMERIC(10,2),
				SUMMA_M9 NUMERIC(10,2),SUMMA_M10 NUMERIC(10,2),SUMMA_M11 NUMERIC(10,2),SUMMA_M12 NUMERIC(10,2))

	INSERT INTO #RES_NE_VICHET
	SELECT DISTINCT
		   CODE_DED = isnull(SPR.CODE,' '),
           NAME_DED = SPR.NAME,
           PREDEL = ISNULL(sd.SUMMA,SPR.SUMMA),
           CODE_INC = DT.SNAME,
           NAME_INC = DT.NAME,
           SUMMA_M1 = 0,
           SUMMA_M2 = 0,
           SUMMA_M3 = 0,
           SUMMA_M4 = 0,
           SUMMA_M5 = 0,
           SUMMA_M6 = 0,
           SUMMA_M7 = 0,
           SUMMA_M8 = 0,
           SUMMA_M9 = 0,
           SUMMA_M10 = 0,
           SUMMA_M11 = 0,
           SUMMA_M12 = 0
	FROM
		dbo.SAL_DED_MONTH AS SDM
		INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
		INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
		inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
		LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
	where 
		YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth


	update #RES_NE_VICHET	
	set    
		   SUMMA_M1 = isnull((select sum(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 1 ),0) ,
           SUMMA_M2 = isnull((select SUM(SDM.SUMMA)
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 2 ),0),
           SUMMA_M3 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 3 ),0),           
           SUMMA_M4 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 4 ),0),           
           SUMMA_M5 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 5 ),0),           
           SUMMA_M6 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 6 ),0),          
           SUMMA_M7 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 7 ),0),           
          SUMMA_M8 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 8 ),0),           
           SUMMA_M9 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 9 ),0),           
           SUMMA_M10 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 10 ),0),           
           SUMMA_M11 = isnull((select SUM(SDM.SUMMA)
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 11 ),0),           
           SUMMA_M12 = isnull((select SUM(SDM.SUMMA) 
					   FROM
						dbo.SAL_DED_MONTH AS SDM
						INNER JOIN dbo.DICTIONARY_TYP_DEDUCTION SPR ON SPR.LINK = SDM.REF_DED
						INNER JOIN #EMPLS R  ON  SDM.link_empl = R.LINK
						inner join  #Salary_deductions sd on sd.ref_pay = sdm.ref_ded  and sd.type = '6'
						LEFT join  #DICT_TYP_INCOMS DT on dt.cod_ded = sd.code and dt.ref_deduct is not null
						where 
						YEAR(sdm.date_ded) = @cYear  and month(sdm.date_ded) <= @nMonth	 and MONTH(sdm.DATE_ded) = 12 ),0)

	FROM #RES_NE_VICHET		
	
------*************************


	--CREATE  TABLE  #RES_NonNDFL_VICHET (LINK_EMPL INT,LINK INT, link_vkr INT, link_ekr INT, TYP_PER varchar (8), object varchar (8), SUMMA NUMERIC(10,2), period_begin datetime , period_end datetime,DATE_BEGIN datetime , DATE_END datetime, CODE_DED VARCHAR(3), Ref_ded varchar (8), CODE_INC varchar(5), link_inc int, NAME_DED VARCHAR(254) ,PREDEL NUMERIC(10,2), TYPE_ded NUMERIC(3,0))
	--INSERT INTO #RES_NonNdfl_VICHET
	--Select 
	--	JC.LINK_EMPL, P.LINK, link_vkr, ISNULL(JC.LINK_EKR,P.LINK_EKR), P.TYP_PER, P.OBJECT, jc.summa, 
	--	period_begin =  JC.period_begin ,
	--	period_end = JC.period_end,
	--	JC.DATE_BEGIN,
	--	JC.DATE_END,
	--	dt.cod_ded, 
	--	dt.ref_deduct, 
	--	dt.sname  ,
	--	dt.link , 
	--	dt.name as name_ded,
	--	sd.summa as summa_neoblag,
	--	sd.type 
	
	--from 
	--	dbo.CALCULATE_JURNAL JC 
	--	INNER JOIN #EMPLS R  ON  JC.link_empl = R.LINK_PERS
	--	/*INNER JOIN dbo.EMPL E ON C.LINK_EMPL = E.LINK  /*and e.link = 17114*/*/
	--	INNER JOIN dbo.PAYS P ON   JC.LINK_PAYS = P.LINK 
	--	inner join DICTIONARY_TYP_INCOMS DT on dt.link = p.link_inc and dt.ref_deduct is not null
	--	LEFT JOIN (Select d.link, o.code from sdoc d inner join dbo.s_objects o on d.object = o.link) d on jc.LINK_DOC = d.link
	--	inner join  dbo.Salary_deductions(@cYear + @nMonth + @eDay ) sd on sd.ref_pay = dt.ref_deduct and sd.type = '6'
	--where
	--	P.OBJECT = 1
	--	AND P.LINK in (Select LINK_PAYS from  dbo.NDFL_GroupTax() )   /*  dbo.NDFL_GroupTax() */ 
	--	AND  month(JC.PERIOD_BEGIN) <=@nMonth and  year(JC.PERIOD_BEGIN) = @cYear
	--	/*AND (	@Status <> 1 AND JC.LINK_EMPL = @LINK_EMPL /*Если не основной сотрудник, то доход по своему табельному номеру*/
	--			or
	--	@Status = 1     and  R.PERS_LINK = 17024*/ /*Если основной сотрудник, то доход по всем табельным номерам
	--	)*/	
	--AND JC.LINK_DEP = @DEP_LINK 
	
	----------------------------------
	-- 5. Налоговые ставки 
	----------------------------------
	-- таблица 5.1 Статус налогоплательщика
	declare @varKSSumDed numeric(15,2), @varKSRange  numeric(15,2), @varKSResid int, @varKSStrCom varchar(1000)

	declare @FACE INT
	if @link_empl is null
		begin 
			set  @FACE = @link_PERS
		end 
	else
		begin 
			set	@FACE = @link_PERS	
		end

	CREATE  TABLE  #RES_EMP_STATUS (DATE_begin DATETIME,DATE_END DATETIME, NDFL_Range numeric (3), resident int, KSTR VARCHAR(3), month_d int,year_d varchar(4), link_inc int, link_dep int, sname varchar(4), name  varchar (254), flag int, perc_stav varchar(2) )
	INSERT INTO #RES_EMP_STATUS
	SELECT 
		   cast( (@cYear + '01' + '01') as datetime) ,
		   cast( (@cYear + @nMonth + @eDay) as datetime) ,
		   dbo.SalaryGetNDFLRange (isnull(@link_empl, @FACE),(@cYear + @nMonth + @eDay) ) as NDFL_Range ,
		   (case when dbo.GetEmplResident(isnull(@link_empl, @FACE)) = 0 then 2
				 when dbo.GetEmplResident(isnull(@link_empl, @FACE)) = 2 then 2
				 when dbo.GetEmplResident(isnull(@link_empl, @FACE)) = 1 then 1
				 else 3 end) as resident, 
		   (case when (SELECT TOP 1 CODE FROM CITIZENSHIP WHERE LINK = (select  top 1 CITIZ_LINK from person where link = @LINK_PERS)) = '1' then '643' else '' END) as KSTR,
		   null,
		   '',
		   null,
		   null,
		   '',
		   '', 
		   null,
		   ''
	--Таблица 5.2 Виды доходов (доходы не по ставке 13%)
	--по сотрудникам

	CREATE  TABLE  #vid_dohod_not13 (month_d int,year_d varchar(4), link_inc int, link_dep int, sname varchar(4), name  varchar (254), flag int, perc_stav varchar(2) )
	insert into #vid_dohod_not13	
	select DISTINCT
		   month(s.period_end),
		   year(s.period_end),
		   s.link_inc,
		   s.link_dep,
		   d.sname,
		   d.name,
		   d.flag,
		   perc_stav = case when d.flag = 1 then '0' 
							   when d.flag = 2 then '13'
							   when d.flag = 3 then '30'
							   else '35'
							   end
	from 
		#EMPLS E
		INNER JOIN #S_J_C_SHORT  S ON S.link_empl = E.LINK
		INNER JOIN #DICT_TYP_INCOMS D ON  S.LINK_INC = D.LINK  AND D.FLAG not in (2) 
	where YEAR(S.DATE1) = @cYear 
		 and	
		  Month(s.date1)<= @nMonth 
		 AND S.LINK_DEP = @DEP_LINK 
		 and S.link_inc is not null

	--по договорникам
	insert into #vid_dohod_not13	
	select DISTINCT
		   month(s.period_end),
		   year(s.period_end),
		   s.link_inc,
		   s.link_dep,
		   d.sname,
		   d.name,
		   d.flag,
		   perc_stav = case when d.flag = 1 then '0' 
							   when d.flag = 2 then '13'
							   when d.flag = 3 then '30'
							   else '35'
							   end
	from 
		#S_J_C_SHORT  S
		INNER JOIN #DICT_TYP_INCOMS D ON  S.LINK_INC = D.LINK  AND D.FLAG not in (2) 
	where YEAR(S.DATE1) = @cYear 
		 and	
		  Month(s.date1)<= @nMonth 
		  AND S.PERS_LINK = @LINK_PERS
		 AND S.LINK_DEP = @DEP_LINK 
		 and S.link_inc is not null
	-----------------------------------------------------
	
	DECLARE @varKSCNT INT

	SELECT @varKSCNT  = COUNT(*) FROM #PERSON

	SELECT TOP 1 
		LTRIM(RTRIM(STR(@varKSCNT))) AS DOCCOUNT, 
		ISNULL(IMNS, '') AS NALOG,
		ISNULL(dd.INN, '') AS INN,
		ISNULL(KPP, '') AS KPP,
		ISNULL(OKATO,'') AS OKATO,
		ISNULL(OKTMO, '')AS OKTMO,
		ISNULL(FULL_NAME, '') AS FULL_NAME,
		ISNULL((SELECT TOP 1 dbo.GetAddressByKladr(DD.REF_LINK_A)), '') AS ADDRES,
		ISNULL(DOTF.PHONE, '') AS PHONE,
		ISNULL(RTRIM(FM), '') + ' ' + ISNULL(RTRIM(IM), '') + ' ' + ISNULL(RTRIM(OT), '') AS GLBUH,
		ISNULL(RTRIM(FM), '') AS FM,
		ISNULL(RTRIM(IM), '') AS IM, 
		ISNULL(RTRIM(OT), '') AS OT,
		ISNULL(RTRIM(DOTF.NAME), '') AS Dolzh
	INTO #DEP
	FROM DICTIONARY_DEPARTMENT DD 
	LEFT OUTER JOIN DICTIONARY_OTV_FACE DOTF ON 
		(DOTF.DEP_LINK = DD.LINK
		AND DOTF.NAME = 'Главный бухгалтер')
	LEFT OUTER JOIN KU_EMPL_PLACING EP ON DOTF.FACE_LINK = EP.LINK
	WHERE DD.link = @DEP_LINK


	DECLARE @varKScInn VARCHAR(254), @varKScKPP VARCHAR(254), @varKSFULL_NAME varchar(254), 
		@varKSNALOG VARCHAR(254), @varKSOKATO VARCHAR(254), @varKSOKTMO VARCHAR(254), @varKSPHONE VARCHAR(254), 
		@varKSGLBUH VARCHAR(254), 
		@varKSRESULT BIT

	SELECT 
		@varKScInn = INN, @varKScKPP = KPP,
		@varKSFULL_NAME = FULL_NAME, 
		@varKSNALOG = NALOG, @varKSOKATO = Replace(OKATO,' ','') ,  @varKSOKTMO = Replace(OKTMO,' ',''), 
		@varKSPHONE = PHONE, 
		@varKSGLBUH  = GLBUH
	FROM #DEP
	------------------------------------
	--- 6.  Сведения о вычетах, предоставленных по предыдущему мету работы 
	------------------------------------
	
		---Сумма доходов, облагаемых по ставке 13%
	SELECT  * 
	INTO #Prev_dohod
	FROM SD_EMPL_PREV_DOHOD 
	WHERE LINK_EMPL =  @LINK_EMPL ORDER BY COD_TYP_INCOMS 


	--- Сумма доходов не облагаемых по ставке 13%
	SELECT  SD.LINK_EMPL,
			SD.REF_TYP_INCOMS ,
			SD.COD_TYP_INCOMS AS COD_INC,
			SD.NAME_TYP_INCOMS AS NAME_INC,
			(CASE WHEN SD.SUMMA_TYP_INCOMS > DT.SUMMA_DED THEN DT.SUMMA_DED 
				  WHEN SD.SUMMA_TYP_INCOMS <= DT.SUMMA_DED THEN SD.SUMMA_TYP_INCOMS END )AS SUMM_INC,
			@cYear as PER_YEAR	  				 
	INTO #Prev_dohod_NO
	FROM SD_EMPL_PREV_DOHOD sd
	inner join dbo.#DICT_TYP_INCOMS DT ON DT.LINK = SD.REF_TYP_INCOMS AND DT.NUMBER_DED = 6
	WHERE LINK_EMPL =  @LINK_EMPL ORDER BY COD_TYP_INCOMS

	declare @SUM_doh13  numeric(10,2),
			@sum_doh_no13 numeric(10,2)
		
	set @SUM_doh13 = isnull((select sum(SUMMA_TYP_INCOMS) from #Prev_dohod),0) 
	set @sum_doh_no13 = isnull((select sum(SUMM_INC) from #Prev_dohod_NO),0) 

	
	
	CREATE  TABLE  #DEP_Prev (link_dep int,NALOG varchar(10), INN varchar(12), KPP varchar(9), OKATO varchar(14), OKTMO varchar(11), FULL_NAME  varchar (254), ADDRES  varchar (254), SUMMA_13 NUMERIC(10,2))
	insert into #DEP_Prev
	SELECT 
		null AS link_dep,
		' ' AS NALOG,
		' ' AS INN,
		' ' AS KPP,
		' ' AS OKATO, 
		' ' AS OKTMO, 
		/*
		ISNULL(dd.link,null) AS link_dep,
		ISNULL(dd.IMNS, ' ') AS NALOG,
		ISNULL(dd.INN, ' ') AS INN,
		ISNULL(dd.KPP, ' ') AS KPP,
		ISNULL(dd.OKATO, ' ')AS OKATO,
		*/
		ISNULL(A.DEP, ' ') AS FULL_NAME,
		ISNULL(A.place, ' ') AS ADDRES,
		ISNULL((@SUM_doh13 - @sum_doh_no13),0) AS SUMMA_13
	FROM /*DICTIONARY_DEPARTMENT DD 
	inner join */KU_EMPL_OLDWORK A /*on  (dd.full_name = a.dep or dd.name = a.dep)*/
	inner join KJ_EMPL_OLDWORK_GROUP b  on a.EMPL_LINK = b.EMPL_LINK 
									and b.EMPL_LINK =  @LINK_EMPL
									and b.link > -1 
									and  year(b.date_end) = @cYear 
									and month(b.date_end) <=  @nMonth 
									and b.date_end = (select max(date_end) 
													  from KJ_EMPL_OLDWORK_GROUP   
													  WHERE EMPL_LINK = @LINK_EMPL 
															and  year(date_end) = @cYear  
															and month(date_end) <= @nMonth 
													  ) 

	where a.date_end = (select max(date_end)  from KJ_EMPL_OLDWORK_GROUP   
											  WHERE EMPL_LINK = @LINK_EMPL 
											and  year(date_end) = @cYear  
													and month(date_end) <= @nMonth 
													 ) 
	---- налоговые вычеты с предыдущего места работы по типам

	SELECT  dd.link_empl,dd.link_ded,dd.code_ded,dd.name_ded,dd.summa_ded as summ_ded, sd.type,  @cYear as PER_YEAR
	INTO #Prev_ded
	FROM SD_EMPL_PREV_DED dd
	inner join #Salary_deductions sd on sd.code = dd.code_ded  
	WHERE dd.LINK_EMPL =  @LINK_EMPL ORDER BY dd.CODE_DED
	
	------------------------------------------------
	-- 7. Доходы облагаемые по ставке 13%

	select 
		SJC.link_empl, 
		SJC.pers_link, 
		   d.name  , 
		   D.sname, 
		   SJC.period_begin, 
		   SJC.period_end, 
		   sum(SJC.summa) as summa , 
		   SJC.link_inc
		   
	into #Dohod_13	   		
	from   #S_J_C_SHORT SJC 
			--inner join pays  p on  p.link = SJC.link_pays and  p.link_inc is not null 
			inner join #DICT_TYP_INCOMS d on d.link = SJC.link_inc 
	WHERE
		(
			SJC.LINK_FACE = @FACE
			or
			SJC.PERS_LINK = @FACE
		)
		AND YEAR(CASE WHEN SJC.TYP_PER = 1 THEN SJC.PERIOD_BEGIN WHEN SJC.TYP_PER = 2 THEN SJC.DATE1 END) = @cYear
		AND MONTH(CASE WHEN SJC.TYP_PER = 1 THEN SJC.PERIOD_BEGIN WHEN SJC.TYP_PER = 2 THEN SJC.DATE1 END) <= @nMonth
		AND SJC.CODE_INC IS NOT NULL
		AND SJC.CODE_INC <> '0000'
		AND SJC.link_dep  = @DEP_LINK  
	group by SJC.pers_link, SJC.link_empl, D.sname ,d.name  , SJC.period_begin, SJC.period_end, SJC.link_inc

	create TABLE #Dohod_13_1 (link_empl int, name varchar(256),  sname varchar(4) ,link_inc int,  p_b1 datetime, p_e1 datetime, s1 numeric (10,2),  
						 p_b2 datetime, p_e2 datetime, s2 numeric (10,2),p_b3 datetime, p_e3 datetime, s3 numeric (10,2), 
						 p_b4 datetime, p_e4 datetime, s4 numeric (10,2),p_b5 datetime, p_e5 datetime, s5 numeric (10,2), 
						 p_b6 datetime, p_e6 datetime, s6 numeric (10,2),p_b7 datetime, p_e7 datetime, s7 numeric (10,2), 
						 p_b8 datetime, p_e8 datetime, s8 numeric (10,2),p_b9 datetime, p_e9 datetime, s9 numeric (10,2),
						 p_b10 datetime, p_e10 datetime, s10 numeric (10,2),p_b11 datetime, p_e11 datetime, s11 numeric (10,2),
						 p_b12 datetime, p_e12 datetime, s12 numeric (10,2))
	INSERT INTO #Dohod_13_1
	SELECT distinct
		D.link_empl ,
		D.name , 
		D.sname , 
 		D.link_inc,
		[p_b1] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '01' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e1] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '01' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s1] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '01' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b2] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '02' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e2] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '02' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s2] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '02' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b3] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '03' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e3] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '03' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s3] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '03' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b4] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '04' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e4] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '04' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s4] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '04' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b5] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '05' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e5] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '05' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s5] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '05' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b6] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '06' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e6] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '06' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s6] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '06' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b7] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '07' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e7] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '07' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s7] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '07' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b8] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '08' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e8] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '08' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s8] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '08' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b9] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '09' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e9] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '09' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s9] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '09' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b10] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '10' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e10] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '10' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s10] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '10' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b11] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '11' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e11] =(SELECT top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '11' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s11] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '11' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)),
		[p_b12] =(SELECT top 1 period_begin FROM #Dohod_13 WHERE month(period_begin) = '12' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[p_e12] =(SELECT  top 1 period_end FROM #Dohod_13 WHERE month(period_end) = '12' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0)), 
		[s12] = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '12' AND LINK_INC = D.LINK_INC and ISNULL(link_empl,0) = ISNULL(d.link_empl,0))
	FROM #Dohod_13 D
	GROUP BY D.link_empl ,D.name , D.sname ,D.link_inc

	--- всего за месяц 
	CREATE  TABLE #Dohod_13_i (MODE int, S_JAN NUMERIC(10,2), S_FEB NUMERIC(10,2), S_MART NUMERIC(10,2), S_APR NUMERIC(10,2), S_MAY NUMERIC(10,2), S_JUN NUMERIC(10,2),S_JUL NUMERIC(10,2),S_AUG NUMERIC(10,2), S_SEN NUMERIC(10,2),S_OKT NUMERIC(10,2), S_NOV NUMERIC(10,2), S_DEC NUMERIC(10,2))
	INSERT INTO #Dohod_13_i
	SELECT
		MODE = 1,
		S_JAN = 0 , 
		S_FEB = 0 , 
		S_MART = 0, 
		S_APR = 0, 
		S_MAY = 0, 
		S_JUN = 0,
		S_JUL = 0,
		S_AUG = 0, 
		S_SEN = 0,
		S_OKT = 0, 
		S_NOV = 0, 
		S_DEC = 0
		 
	UPDATE #Dohod_13_i
	SET	S_JAN = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '01' ),
		S_FEB = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '02' ),
		S_MART= (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '03' ),
		S_APR = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '04' ), 
		S_MAY = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '05' ),
		S_JUN = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '06' ),
		S_JUL = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '07' ),
		S_AUG = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '08' ),
		S_SEN = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '09' ),
		S_OKT = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '10' ),
		S_NOV = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '11' ),
		S_DEC = (SELECT isnull(sum(summa),0) FROM #Dohod_13 WHERE month(period_end) = '12' ) 
	FROM #Dohod_13_i where MODE = 1	
	
	--- всего с нарастающим итогом с начала года за месяц
	INSERT INTO  #Dohod_13_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 2,
		S_JAN = isnull(S_JAN,0),
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0),
		S_MART= isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) ,
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0),
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #Dohod_13_i 
		 where MODE = 1	

	------------------------------------------------
	--8. Необлагаемые суммы доходов
	
	Select distinct 
			code_ded, 
			code_inc, 
			name_ded, 
			predel,
			SUMMA_M1,
            SUMMA_M2,          
            SUMMA_M3,         
            SUMMA_M4,        
            SUMMA_M5,          
            SUMMA_M6,          
            SUMMA_M7,        
            SUMMA_M8,      
            SUMMA_M9,         
            SUMMA_M10,         
            SUMMA_M11,          
            SUMMA_M12
				 
	into #Dohod_13_predel
	from #RES_NE_VICHET R

	--- всего за месяц 

	CREATE  TABLE #Dohod_13_predel_i (MODE int null, S_JAN NUMERIC(10,2) , S_FEB NUMERIC(10,2), S_MART NUMERIC(10,2), S_APR NUMERIC(10,2), S_MAY NUMERIC(10,2), S_JUN NUMERIC(10,2),S_JUL NUMERIC(10,2),S_AUG NUMERIC(10,2), S_SEN NUMERIC(10,2),S_OKT NUMERIC(10,2), S_NOV NUMERIC(10,2), S_DEC NUMERIC(10,2))
	
	INSERT INTO #Dohod_13_predel_i
	
	SELECT
		MODE = 1,
		S_JAN = 0, 
		S_FEB = 0, 
		S_MART = 0, 
		S_APR = 0, 
		S_MAY = 0, 
		S_JUN = 0,
		S_JUL = 0,
		S_AUG = 0, 
		S_SEN = 0,
		S_OKT = 0, 
		S_NOV = 0, 
		S_DEC = 0
	 
	UPDATE #Dohod_13_predel_i
	SET MODE = 1,
		S_JAN = (SELECT isnull(SUMMA_M1,0) FROM #Dohod_13_predel),
		S_FEB = (SELECT isnull(SUMMA_M2,0) FROM #Dohod_13_predel),
		S_MART =(SELECT isnull(SUMMA_M3,0) FROM #Dohod_13_predel),
		S_APR = (SELECT isnull(SUMMA_M4,0) FROM #Dohod_13_predel),	
		S_MAY = (SELECT isnull(SUMMA_M5,0) FROM #Dohod_13_predel),
		S_JUN = (SELECT isnull(SUMMA_M6,0) FROM #Dohod_13_predel),	
		S_JUL = (SELECT isnull(SUMMA_M7,0) FROM #Dohod_13_predel),
		S_AUG = (SELECT isnull(SUMMA_M8,0) FROM #Dohod_13_predel),	
		S_SEN = (SELECT isnull(SUMMA_M9,0) FROM #Dohod_13_predel),
		S_OKT = (SELECT isnull(SUMMA_M10,0) FROM #Dohod_13_predel),	
		S_NOV = (SELECT isnull(SUMMA_M11,0) FROM #Dohod_13_predel),
		S_DEC = (SELECT isnull(SUMMA_M12,0) FROM #Dohod_13_predel) 
	FROM #Dohod_13_predel_i	 where mode = 1 
	
	--- всего с нарастающим итогом с начала года за месяц
	INSERT INTO #Dohod_13_predel_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 2,
	    S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0), 
		S_MART =isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0),
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0), 
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #Dohod_13_predel_i where mode = 1 
		
	------------------------------------------------
	--- 9. Сумма облагаемых доходов
	------------------------------------------------
	
	--- всего за месяц 

	CREATE  TABLE #Obl_Dohod_i (MODE INT , S_JAN NUMERIC(10,2), S_FEB NUMERIC(10,2), S_MART NUMERIC(10,2), S_APR NUMERIC(10,2), S_MAY NUMERIC(10,2), S_JUN NUMERIC(10,2),S_JUL NUMERIC(10,2),S_AUG NUMERIC(10,2), S_SEN NUMERIC(10,2),S_OKT NUMERIC(10,2), S_NOV NUMERIC(10,2), S_DEC NUMERIC(10,2))
	
	INSERT INTO #Obl_Dohod_i
	SELECT  mode = 1 ,S_JAN = 0 ,S_FEB = 0 ,S_MART = 0,	S_APR = 0,S_MAY = 0,S_JUN = 0,S_JUL = 0,S_AUG = 0,S_SEN = 0,S_OKT = 0,S_NOV = 0,S_DEC = 0
	
	UPDATE #Obl_Dohod_i
	SET S_JAN = (SELECT isnull(d.S_JAN,0) - isnull(dp.S_JAN,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_FEB = (SELECT isnull(d.S_FEB,0) - isnull(dp.S_FEB,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_MART =(SELECT isnull(d.S_MART,0) - isnull(dp.S_MART,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_APR = (SELECT isnull(d.S_APR,0) - isnull(dp.S_APR,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),	
		S_MAY = (SELECT isnull(d.S_MAY,0) - isnull(dp.S_MAY,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_JUN = (SELECT isnull(d.S_JUN,0) - isnull(dp.S_JUN,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),	
		S_JUL = (SELECT isnull(d.S_JUL,0) - isnull(dp.S_JUL,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_AUG = (SELECT isnull(d.S_AUG,0) - isnull(dp.S_AUG,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),	
		S_SEN = (SELECT isnull(d.S_SEN,0) - isnull(dp.S_SEN,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_OKT = (SELECT isnull(d.S_OKT,0) - isnull(dp.S_OKT,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),	
		S_NOV = (SELECT isnull(d.S_NOV,0) - isnull(dp.S_NOV,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1),
		S_DEC = (SELECT isnull(d.S_DEC,0) - isnull(dp.S_DEC,0) FROM #Dohod_13_i d, #Dohod_13_predel_i dp where d.mode = 1 and dp.mode = 1) 
	FROM #Obl_Dohod_i where mode = 1 
	
	--- всего с нарастающим итогом с начала года за месяц
	INSERT INTO #Obl_Dohod_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 2,
		S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0), 
		S_MART =isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0), 
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0), 
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #Obl_Dohod_i where mode = 1 
	
	-----------------------------------------------
	--- 10. Вычеты фактически предоставленные , стандартные, имущестевнные, проффессиональные
	-----------------------------------------------
	CREATE  TABLE #DED_FACT( /* LINK_VKR int, NAME_VKR varchar(20) ,*/ LINK_EMPL int , name_ded varchar(254) , code_ded varchar(6),ref_ded int,
							type tinyint,type_ded tinyint, type_name varchar(100),NUM1 int,summa_1 NUMERIC(10,2), countd1 int,NUM2 int, summa_2 NUMERIC(10,2), countd2 int,
							NUM3 int,summa_3 NUMERIC(10,2), countd3 int,NUM4 int, summa_4 NUMERIC(10,2), countd4 int,NUM5 int, summa_5 NUMERIC(10,2), countd5 int,
							NUM6 int,summa_6 NUMERIC(10,2), countd6 int,NUM7 int, summa_7 NUMERIC(10,2), countd7 int,NUM8 int, summa_8 NUMERIC(10,2), countd8 int,
							NUM9 int,summa_9 NUMERIC(10,2), countd9 int,NUM10 int, summa_10 NUMERIC(10,2), countd10 int,NUM11 int, summa_11 NUMERIC(10,2), countd11 int,
							NUM12 int,summa_12 NUMERIC(10,2), countd12 int)
	INSERT INTO #DED_FACT

	SELECT 	
	--LINK_VKR,
	--[NAME_VKR]= FIN.CODE,
	LINK_EMPL, 
	[name_ded] = T.[name],
	[code_ded] =T.[CODE],
	[ref_ded] = REF_DED,
	[type] = type,
	[type_ded] = t.number,
	[type_name] =(case when type=1 and t.number <> 4 and t.code not in (101,102,106,107,108,109,110,111,112,113)  then 'стандартный налоговый вычет'
					   when type=1 and t.number <> 4 and t.code in (101,102,106,107,108,109,110,111,112,113)  then 'Стандартный налоговый вычет на обеспечение ребенка'
					   when type=1 and  t.number = 10 then 'Социальный налоговый вычет в части расходов по уплате взносов на ДПС (НГПС)' 
					   when type=1 and t.number = 4  then 'Имущественный налоговый вычет'
						 else 'освобождаемые от налогообложения' 
					end),
	[NUM1] = 1,
	[summa_1] = 0,
	countd1 = 0,
	[num2] = 2,
	[summa_2] = 0,
	[countd2] = 0  ,
	[num3] = 3,
	[summa_3] = 0 ,
	[countd3] = 0 ,
	[num4] = 4,
	[summa_4] = 0 ,
	[countd4] = 0 ,	
	[num5]= 5,
	[summa_5] = 0 ,
	[countd5] = 0 ,
	[num6]= 6,
	[summa_6] = 0 ,
	[countd6] = 0 ,
	[num7]= 7,
	[summa_7]  = 0,
	[countd7] = 0 ,
	[num8]= 8,
	[summa_8]  = 0,
	[countd8]  = 0,		
	[num9]= 9,
	[summa_9] = 0 ,
	[countd9] = 0 ,
	[num10]= 10,
	[summa_10] = 0 ,
	[countd10] = 0 ,
	[num11]= 11,
	[summa_11] = 0 ,
	[countd11] = 0 ,
	[num12]= 12,
	[summa_12] = 0 ,
	[countd12] = 0 
	from 
		sal_ded_month D inner join months m on m.num =  month(DATE_DED)
		left join dbo.SAL_SFIN FIN ON FIN.LINK = D.LINK_VKR
		left join DICTIONARY_TYP_DEDUCTION  T on T.link = D.REF_DED
	where  
		month(DATE_DED)<=@nMonth and YEAR(DATE_DED)=@cYear and link_empl = @LINK_EMPL and (TYPE=1 /*or TYPE=2*/)

	group by /*m.num,*/ LINK_EMPL, REF_DED, T.[code],T.[name],  type , /*LINK_VKR, FIN.CODE ,*/ t.number
	order by 1,3
	
	update #DED_FACT
	set 	[summa_1] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= d.NUM1 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = d.ref_ded   and s1.link_empl = d.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd1 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= d.NUM1  and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = d.ref_ded   and s1.link_empl = d.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d

	update #DED_FACT 
	set 	[summa_2] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM2  and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = d.ref_ded   and s1.link_empl = d.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd2 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM2  and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = d.ref_ded   and s1.link_empl = d.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d

	update #DED_FACT
	set 	[summa_3] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM3 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd3 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM3 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d


	update #DED_FACT
	set 	[summa_4] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM4 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd4 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM4 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d

	update #DED_FACT
	set 	[summa_5] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM5 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd5 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM5 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d

	update #DED_FACT
	set 	[summa_6] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM6 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd6 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM6 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
			
	update #DED_FACT
	set 	[summa_7] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM7 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd7 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM7 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
	
	update #DED_FACT
	set 	[summa_8] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM8 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd8 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM8 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
		
	update #DED_FACT
	set 	[summa_9] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM9 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd9 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM9 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
		
	update #DED_FACT
	set 	[summa_10] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM10 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd10 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM10 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
		
	update #DED_FACT
	set 	[summa_11] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM11 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd11 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM11 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d
		
	update #DED_FACT
	set 	[summa_12] = isnull((select sum(s1.summa) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM12 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2)),0),
			countd12 = (select count(s1.ref_ded) from sal_ded_month s1 
				where  month(s1.DATE_DED)= D.NUM12 and YEAR(s1.DATE_DED)=@cYear and s1.ref_ded = D.ref_ded   and s1.link_empl = D.link_empl and (s1.TYPE=1 or s1.TYPE=2))
	from #DED_FACT d

	--- всего за месяц 

	CREATE  TABLE #NDFL_13_i ( MODE int, S_JAN NUMERIC(18,2), d1 datetime, num1 varchar(10), S_FEB NUMERIC(18,2), d2 datetime, num2 varchar(10), S_MART NUMERIC(18,2), d3 datetime, num3 varchar(10), S_APR NUMERIC(18,2), d4 datetime, num4 varchar(10), 
							   S_MAY NUMERIC(18,2), d5 datetime, num5 varchar(10), S_JUN NUMERIC(18,2),d6 datetime, num6 varchar(10),S_JUL NUMERIC(18,2), d7 datetime, num7 varchar(10),S_AUG NUMERIC(18,2), d8 datetime, num8 varchar(10), 
							   S_SEN NUMERIC(18,2), d9 datetime, num9 varchar(10), S_OKT NUMERIC(18,2),d10 datetime, num10 varchar(10), S_NOV NUMERIC(18,2), d11 datetime, num11 varchar(10), S_DEC NUMERIC(18,2), d12 datetime, num12 varchar(10))
	
	INSERT INTO #NDFL_13_i
	
	SELECT 
		MODE = 1,
		S_JAN = 0 , 
		null,
		null,
		S_FEB = 0 , 
		null,
		null,
		S_MART = 0, 
		null,
		null,
		S_APR = 0, 
		null,
		null,
		S_MAY = 0, 
		null,
		null,
		S_JUN = 0,
		null,
		null,
		S_JUL = 0,
		null,
		null,
		S_AUG = 0, 
		null,
		null,
		S_SEN = 0,
		null,
		null,
		S_OKT = 0, 
		null,
		null,
		S_NOV = 0, 
		null,
		null,
		S_DEC = 0,
		null,
		null
		
	UPDATE #NDFL_13_i
	SET S_JAN = (SELECT sum(isnull(summa_1,0)) FROM #DED_FACT ),
		S_FEB = (SELECT sum(isnull(summa_2,0)) FROM #DED_FACT ),
		S_MART =(SELECT sum(isnull(summa_3,0)) FROM #DED_FACT ),
		S_APR = (SELECT sum(isnull(summa_4,0)) FROM #DED_FACT ),	
		S_MAY = (SELECT sum(isnull(summa_5,0)) FROM #DED_FACT ),
		S_JUN = (SELECT sum(isnull(summa_6,0)) FROM #DED_FACT ),	
		S_JUL = (SELECT sum(isnull(summa_7,0)) FROM #DED_FACT ),
		S_AUG = (SELECT sum(isnull(summa_8,0)) FROM #DED_FACT ),	
		S_SEN = (SELECT sum(isnull(summa_9,0)) FROM #DED_FACT ),
		S_OKT = (SELECT sum(isnull(summa_10,0)) FROM #DED_FACT ),	
		S_NOV = (SELECT sum(isnull(summa_11,0)) FROM #DED_FACT ),
		S_DEC = (SELECT sum(isnull(summa_12,0)) FROM #DED_FACT ) 
	FROM #NDFL_13_i where mode = 1

	--- всего с нарастающим итогом с начала года за месяц
	INSERT INTO #NDFL_13_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	SELECT 
		MODE = 2,
		S_JAN = isnull(S_JAN,0), 
		null,
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0), 
		null,
		S_MART =isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0),
		null,
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		null,
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		null,
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		null,
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		null,
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) ,
		null,
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) , 
		null,
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		null,
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0), 
		null,
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0),
		null 
	FROM #NDFL_13_i where mode = 1
	---------------------------------------------
	---- 11. Облагаемая база ставка 13% 
	---------------------------------------------
	--- всего за месяц 

	INSERT INTO #NDFL_13_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	
	SELECT
		MODE = 3,
		S_JAN = 0 ,
		null,
		S_FEB = 0 ,
		null,
		S_MART = 0,
		null,
		S_APR = 0, 
		null,
		S_MAY = 0,
		null,
		S_JUN = 0,
		null,
		S_JUL = 0,
		null,
		S_AUG = 0,
		null, 
		S_SEN = 0,
		null,
		S_OKT = 0,
		null, 
		S_NOV = 0,
		null, 
		S_DEC = 0,
		null
	 
	UPDATE #NDFL_13_i
	SET S_JAN = (SELECT isnull(O.S_JAN,0) - isnull(D.S_JAN,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_FEB = (SELECT isnull(O.S_FEB,0) - isnull(D.S_FEB,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_MART =(SELECT isnull(O.S_MART,0) - isnull(D.S_MART,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_APR = (SELECT isnull(O.S_APR,0) - isnull(D.S_APR,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),	
		S_MAY = (SELECT isnull(O.S_MAY,0) - isnull(D.S_MAY,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_JUN = (SELECT isnull(O.S_JUN,0) - isnull(D.S_JUN,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),	
		S_JUL = (SELECT isnull(O.S_JUL,0) - isnull(D.S_JUL,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_AUG = (SELECT isnull(O.S_AUG,0) - isnull(D.S_AUG,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),	
		S_SEN = (SELECT isnull(O.S_SEN,0) - isnull(D.S_SEN,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_OKT = (SELECT isnull(O.S_OKT,0) - isnull(D.S_OKT,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),	
		S_NOV = (SELECT isnull(O.S_NOV,0) - isnull(D.S_NOV,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1),
		S_DEC = (SELECT isnull(O.S_DEC,0) - isnull(D.S_DEC,0) FROM #Obl_Dohod_i O, #NDFL_13_i d where d.mode = 1 and o.mode = 1) 
	FROM #NDFL_13_i where mode = 3

	--- всего с нарастающим итогом с начала года за месяц

	
	INSERT INTO #NDFL_13_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	SELECT 
		MODE = 4,
		S_JAN = 0 ,
		null, 
		S_FEB = 0 ,
		null, 
		S_MART = 0,
		null, 
		S_APR = 0, 
		null,
		S_MAY = 0,
		null, 
		S_JUN = 0,
		null,
		S_JUL = 0,
		null,
		S_AUG = 0,
		null, 
		S_SEN = 0,
		null,
		S_OKT = 0,
		null, 
		S_NOV = 0,
		null, 
		S_DEC = 0,
		null
		
	UPDATE #NDFL_13_i
	set   
		S_JAN = (SELECT isnull(o.S_JAN,0) - isnull(D.S_JAN,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2), 
		S_FEB = (SELECT isnull(o.S_FEB,0) - isnull(D.S_FEB,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2), 
		S_MART =(SELECT isnull(o.S_MART,0) - isnull(D.S_MART,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_APR = (SELECT isnull(o.S_APR,0) - isnull(D.S_APR,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_MAY = (SELECT isnull(o.S_MAY,0) - isnull(D.S_MAY,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_JUN = (SELECT isnull(o.S_JUN,0) - isnull(D.S_JUN,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_JUL = (SELECT isnull(o.S_JUL,0) - isnull(D.S_JUL,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_AUG = (SELECT isnull(o.S_AUG,0) - isnull(D.S_AUG,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_SEN = (SELECT isnull(o.S_SEN,0) - isnull(D.S_SEN,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2), 
		S_OKT = (SELECT isnull(o.S_OKT,0) - isnull(D.S_OKT,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2),
		S_NOV = (SELECT isnull(o.S_NOV,0) - isnull(D.S_NOV,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2), 
		S_DEC = (SELECT isnull(o.S_DEC,0) - isnull(D.S_DEC,0) FROM #NDFL_13_i D, #Obl_Dohod_i O where d.mode = 2 and o.mode=2)
	FROM #NDFL_13_i where mode = 4
	
	------------------------------------------------
	--- 12. НДФЛ по ставке 13%
	------------------------------------------------ 
	--сумма начисленного налого С НАЧАЛА ГОДА
	INSERT INTO #NDFL_13_i  (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	SELECT
		MODE = 5,
		S_JAN = 0 ,
		null, 
		S_FEB = 0 , 
		null, 
		S_MART = 0, 
		null, 
		S_APR = 0, 
		null,
		S_MAY = 0, 
		null, 
		S_JUN = 0,
		null,
		S_JUL = 0,
		null,
		S_AUG = 0, 
		null,
		S_SEN = 0,
		null,
		S_OKT = 0, 
		null,
		S_NOV = 0, 
		null,
		S_DEC = 0,
		null

	DECLARE @varKSCOEFF NUMERIC(20,2)
	SELECT @varKSCOEFF = CASE WHEN @varKSStatus = 1 THEN 0.13 ELSE 0.30 END

 
	UPDATE #NDFL_13_i 
	SET S_JAN = round((SELECT isnull(S_JAN,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0), 
		S_FEB = round((SELECT isnull(S_FEB,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0), 
		S_MART =round((SELECT isnull(S_MART,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_APR = round((SELECT isnull(S_APR,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_MAY = round((SELECT isnull(S_MAY,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_JUN = round((SELECT isnull(S_JUN,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_JUL = round((SELECT isnull(S_JUL,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_AUG = round((SELECT isnull(S_AUG,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_SEN = round((SELECT isnull(S_SEN,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0), 
		S_OKT = round((SELECT isnull(S_OKT,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0),
		S_NOV = round((SELECT isnull(S_NOV,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0), 
		S_DEC = round((SELECT isnull(S_DEC,0)* @varKSCOEFF FROM #NDFL_13_i where mode = 4 ),0)
	FROM #NDFL_13_i where mode =5
	

	
	
	--сумма начисленного налога за месяц 
	INSERT INTO #NDFL_13_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	SELECT
		MODE = 6,
		S_JAN = case ((SELECT SUM(C.SUMMA) FROM (select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '1'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '1') AS C ) 
						  - (round(isnull(S_JAN,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_JAN,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_JAN,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_JAN,0)* @varKSCOEFF,0) end,
		d1 = case when isnull(S_JAN,0) <>0 then (select max(d.date1) from dbo.days_month(1,@cYear)d) else null end,
		
		
		S_FEB =  case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '2'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '2') AS C ) 
						  - (round(isnull(S_FEB,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_FEB,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_FEB,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_FEB,0)* @varKSCOEFF,0) end, 
		d2 = case when isnull(S_FEB,0) <>0 then (select max(d.date1) from dbo.days_month(2,@cYear)d) else null end,
		S_MART = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '3'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '3') AS C ) 
						  - (round(isnull(S_MART,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_MART,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_MART,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_MART,0)* @varKSCOEFF,0) end, 
		d3 = case when isnull(S_MART,0) <>0 then (select max(d.date1) from dbo.days_month(3,@cYear)d) else null end,
		S_APR = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '4'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '4') AS C ) 
						  - (round(isnull(S_APR,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_APR,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_APR,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_APR,0)* @varKSCOEFF,0) end,
		d4 = case when isnull(S_APR,0) <>0 then (select max(d.date1) from dbo.days_month(4,@cYear)d) else null end,
		S_MAY = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '5'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '5') AS C ) 
						  - (round(isnull(S_MAY,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_MAY,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_MAY,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_MAY,0)* @varKSCOEFF,0) end,
		d5 = case when isnull(S_MAY,0) <>0 then (select max(d.date1) from dbo.days_month(5,@cYear)d) else null end,
		S_JUN = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '6'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '6') AS C ) 
						  - (round(isnull(S_JUN,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_JUN,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_JUN,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_JUN,0)* @varKSCOEFF,0) end,
		d6 = case when isnull(S_JUN,0) <>0 then (select max(d.date1) from dbo.days_month(6,@cYear)d) else null end,
		S_JUL = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '7'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '7') AS C ) 
						  - (round(isnull(S_JUL,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_JUL,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_JUL,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_JUL,0)* @varKSCOEFF,0) end,
		d7 = case when isnull(S_JUL,0) <>0 then (select max(d.date1) from dbo.days_month(7,@cYear)d) else null end,
		S_AUG = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '8'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '8') AS C ) 
						  - (round(isnull(S_AUG,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_AUG,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_AUG,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_AUG,0)* @varKSCOEFF,0) end,
		d8 = case when isnull(S_AUG,0) <>0 then (select max(d.date1) from dbo.days_month(8,@cYear)d) else null end,
		S_SEN = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '9'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '9') AS C ) 
						  - (round(isnull(S_SEN,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_SEN,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_SEN,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_SEN,0)* @varKSCOEFF,0) end, 
		d9 = case when isnull(S_SEN,0) <>0 then (select max(d.date1) from dbo.days_month(9,@cYear)d) else null end,
		S_OKT = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '10'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '10') AS C ) 
						  - (round(isnull(S_OKT,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_OKT,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_OKT,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_OKT,0)* @varKSCOEFF,0) end, 
		d10 = case when isnull(S_OKT,0) <>0 then (select max(d.date1) from dbo.days_month(10,@cYear)d) else null end,
		S_NOV = case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '11'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '11') AS C ) 
						  - (round(isnull(S_NOV,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_NOV,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_NOV,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_NOV,0)* @varKSCOEFF,0) end, 
		d11 = case when isnull(S_NOV,0) <>0 then (select max(d.date1) from dbo.days_month(11,@cYear)d) else null end,
		S_DEC =	case ((SELECT SUM(C.SUMMA) FROM(select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  E.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '12'	
					     union all
					     select sum(summa) as summa from #S_J_C_SHORT sjc 
							INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
							where  SJC.PERS_LINK = @LINK_PERS AND SJC.LINK_DEP = @DEP_LINK   and year(sjc.date1) = @varKSnYear and month(sjc.date1) = '12') AS C ) 
						  - (round(isnull(S_DEC,0)* @varKSCOEFF,0))
						)		
				    when 1	
					then (round(isnull(S_DEC,0)* @varKSCOEFF,0)+1)	
					when -1 
					then (round(isnull(S_DEC,0)* @varKSCOEFF,0)-1)	
					else round(isnull(S_DEC,0)* @varKSCOEFF,0) end, 
		d12 = case when isnull(S_DEC,0) <>0 then (select max(d.date1) from dbo.days_month(12,@cYear)d) else null end
	FROM #NDFL_13_i  where mode = 3

	
	--сумма удержанного налого С НАЧАЛА ГОДА
	CREATE TABLE #MONTHES ([MONTH] INT, SUMMA NUMERIC(18,2), CODE_DED VARCHAR(10) )
	INSERT INTO #MONTHES
	SELECT MONTH(DATE1), CAST( (SUM(CAST(round(SUMMA,0) as int) )) AS NUMERIC(8,0) ), ''
	FROM #S_J_C_SHORT SJC 
	INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
	INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
	WHERE 
 		YEAR(DATE1) = @varKSnYear
 		and 
		MONTH(DATE1)<= @nMonth
		AND 
		SJC.LINK_DEP = @DEP_LINK 
		AND 
		E.PERS_LINK = @LINK_PERS 
	GROUP BY MONTH(DATE1)
	UNION ALL
	SELECT MONTH(DATE1), CAST( (SUM(CAST(round(SUMMA,0) as int) )) AS NUMERIC(8,0) ), ''
	FROM #S_J_C_SHORT SJC 
	INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 4)
	WHERE 
 		YEAR(DATE1) = @varKSnYear 
 		and
 		MONTH(DATE1)<= @nMonth 
 		AND 
		SJC.LINK_DEP = @DEP_LINK 
		AND
		SJC.PERS_LINK = @LINK_PERS 
	GROUP BY MONTH(DATE1)	

	--сумма удержанного налога за месяц 
	INSERT INTO #NDFL_13_i (MODE,  S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6,S_JUL, D7,S_AUG, D8, S_SEN, D9,S_OKT, D10, S_NOV, D11, S_DEC, D12)
	select 
		MODE = 8,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null,
		0,
		null
	update	#NDFL_13_i	
	set 
		S_JAN = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 1 ),0),0), 
		S_FEB = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 2 ),0),0), 
		S_MART =round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 3 ),0),0),
		S_APR = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 4 ),0),0),
		S_MAY = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 5 ),0),0),
		S_JUN = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 6 ),0),0),
		S_JUL = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 7 ),0),0),
		S_AUG = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 8 ),0),0),
		S_SEN = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 9 ),0),0), 
		S_OKT = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 10 ),0),0),
		S_NOV = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 11 ),0),0), 
		S_DEC = round(isnull((SELECT SUM(summa) FROM #MONTHES where [month]= 12 ),0),0)
	FROM #NDFL_13_i where mode = 8
	
	update	#NDFL_13_i	
	set 
		d1 = case when isnull(S_JAN,0) <>0 then (select max(d.date1)  from dbo.days_month(1,@cYear)d) else null end,
		d2 = case when isnull(S_FEB,0) <>0 then (select max(d.date1)  from dbo.days_month(2,@cYear)d) else null end,
		d3 = case when isnull(S_MART,0) <>0 then (select max(d.date1)  from dbo.days_month(3,@cYear)d) else null end,
		d4 = case when isnull(S_APR,0) <>0 then (select max(d.date1)  from dbo.days_month(4,@cYear)d) else null end,
		d5 = case when isnull(S_MAY,0) <>0 then (select max(d.date1)  from dbo.days_month(5,@cYear)d) else null end,
		d6 = case when isnull(S_JUN,0) <>0 then (select max(d.date1)  from dbo.days_month(6,@cYear)d) else null end,
		d7 = case when isnull(S_JUL,0) <>0 then (select max(d.date1)  from dbo.days_month(7,@cYear)d) else null end,
		d8 = case when isnull(S_AUG,0) <>0 then (select max(d.date1)  from dbo.days_month(8,@cYear)d) else null end,
		d9 = case when isnull(S_SEN,0) <>0 then (select max(d.date1)  from dbo.days_month(9,@cYear)d) else null end,
		d10 = case when isnull(S_OKT,0) <>0 then (select max(d.date1)  from dbo.days_month(10,@cYear)d) else null end,
		d11 = case when isnull(S_NOV,0) <>0 then (select max(d.date1)  from dbo.days_month(11,@cYear)d) else null end,
		d12 = case when isnull(S_DEC,0) <>0 then (select max(d.date1)  from dbo.days_month(12,@cYear)d) else null end
	FROM #NDFL_13_i where mode = 8	
	
 	
	INSERT INTO #NDFL_13_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 7,
		S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0), 
		S_MART =isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0),
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0), 
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #NDFL_13_i where mode = 8
 	
	-- перечисления	НДФЛ по ставке 13%
	INSERT INTO #NDFL_13_i (MODE,  S_JAN, D1,NUM1, S_FEB, D2,NUM2, S_MART, D3,NUM3, S_APR, D4,NUM4, S_MAY, D5,NUM5, S_JUN, D6,NUM6,S_JUL, D7,NUM7,S_AUG, D8,NUM8, S_SEN, D9,NUM9,S_OKT, D10,NUM10, S_NOV, D11,NUM11, S_DEC, D12,NUM12)
	select 
		MODE = 10,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null,
		0,
		null,
		null



	DECLARE @SUMMA_PLAT_ALL NUMERIC(18,2)
	DECLARE @SUMMA_NACH_ALL NUMERIC(18,2)


	update	#NDFL_13_i	
	set 
		d1 = (select max(d.date1)  from dbo.days_month(1,@cYear)d),
		d2 = (select max(d.date1)  from dbo.days_month(2,@cYear)d),
		d3 = (select max(d.date1)  from dbo.days_month(3,@cYear)d),
		d4 = (select max(d.date1)  from dbo.days_month(4,@cYear)d),
		d5 = (select max(d.date1)  from dbo.days_month(5,@cYear)d),
		d6 = (select max(d.date1)  from dbo.days_month(6,@cYear)d),
		d7 = (select max(d.date1)  from dbo.days_month(7,@cYear)d),
		d8 = (select max(d.date1)  from dbo.days_month(8,@cYear)d),
		d9 = (select max(d.date1)  from dbo.days_month(9,@cYear)d),
		d10 =(select max(d.date1)  from dbo.days_month(10,@cYear)d),
		d11 =(select max(d.date1)  from dbo.days_month(11,@cYear)d),
		d12 =(select max(d.date1)  from dbo.days_month(12,@cYear)d)
	FROM #NDFL_13_i where mode = 10	




	declare @db datetime ,
		@de datetime, 
		@SUMMA_PLAT_ALL1 NUMERIC(18,2),
		@SUMMA_NACH_ALL1 NUMERIC(18,2),
		@SUMMA_PLAT_ALL2 NUMERIC(18,2),
		@SUMMA_NACH_ALL2 NUMERIC(18,2),
		@SUMMA_PLAT_ALL3 NUMERIC(18,2),
		@SUMMA_NACH_ALL3 NUMERIC(18,2),
		@SUMMA_PLAT_ALL4 NUMERIC(18,2),
		@SUMMA_NACH_ALL4 NUMERIC(18,2),
		@SUMMA_PLAT_ALL5 NUMERIC(18,2),
		@SUMMA_NACH_ALL5 NUMERIC(18,2),
		@SUMMA_PLAT_ALL6 NUMERIC(18,2),
		@SUMMA_NACH_ALL6 NUMERIC(18,2),
		@SUMMA_PLAT_ALL7 NUMERIC(18,2),
		@SUMMA_NACH_ALL7 NUMERIC(18,2),
		@SUMMA_PLAT_ALL8 NUMERIC(18,2),
		@SUMMA_NACH_ALL8 NUMERIC(18,2),
		@SUMMA_PLAT_ALL9 NUMERIC(18,2),
		@SUMMA_NACH_ALL9 NUMERIC(18,2),
		@SUMMA_PLAT_ALL10 NUMERIC(18,2),
		@SUMMA_NACH_ALL10 NUMERIC(18,2),
		@SUMMA_PLAT_ALL11 NUMERIC(18,2),
		@SUMMA_NACH_ALL11 NUMERIC(18,2),
		@SUMMA_PLAT_ALL12 NUMERIC(18,2),
		@SUMMA_NACH_ALL12 NUMERIC(18,2)				
		
	set @db = @BEGIN_YEAR
	set @de = (select top 1  d1  FROM #NDFL_13_i where mode = 10)

	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL1 =  @nSum1
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL1 OUT
			SET @SUMMA_PLAT_ALL1 = ISNULL(@SUMMA_PLAT_ALL1,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL1 OUT

	set @de = (select top 1 d2  FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL2 =  @nSum2
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL2 OUT
			SET @SUMMA_PLAT_ALL2 = ISNULL(@SUMMA_PLAT_ALL2,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL2 OUT

	set @de = (select top 1 d3  FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL3 =  @nSum3
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL3 OUT
			SET @SUMMA_PLAT_ALL3 = ISNULL(@SUMMA_PLAT_ALL3,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL3 OUT

	set @de = (select top 1 d4 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL4 =  @nSum4
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL4 OUT
			SET @SUMMA_PLAT_ALL4 = ISNULL(@SUMMA_PLAT_ALL4,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL4 OUT

	set @de = (select top 1 d5 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL5 =  @nSum5
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL5 OUT
			SET @SUMMA_PLAT_ALL5 = ISNULL(@SUMMA_PLAT_ALL5,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL5 OUT

	set @de = (select top 1 d6 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL6 =  @nSum6
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL6 OUT
			SET @SUMMA_PLAT_ALL6 = ISNULL(@SUMMA_PLAT_ALL6,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL6 OUT

	set @de = (select top 1 d7 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL7 =  @nSum7
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL7 OUT
			SET @SUMMA_PLAT_ALL7 = ISNULL(@SUMMA_PLAT_ALL7,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL7 OUT

	set @de = (select top 1 d8 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL8 =  @nSum8
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL8 OUT
			SET @SUMMA_PLAT_ALL8 = ISNULL(@SUMMA_PLAT_ALL8,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL8 OUT

	set @de = (select top 1 d9 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL9 =  @nSum9
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL9 OUT
			SET @SUMMA_PLAT_ALL9 = ISNULL(@SUMMA_PLAT_ALL9,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL9 OUT

	set @de = (select top 1 d10 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL10 =  @nSum10
		END
	ELSE
		BEGIN 
				EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL10 OUT
				SET @SUMMA_PLAT_ALL10 = ISNULL(@SUMMA_PLAT_ALL10,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL10 OUT

	set @de = (select top 1 d11 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL11 =  @nSum11
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL11 OUT
			SET @SUMMA_PLAT_ALL11 = ISNULL(@SUMMA_PLAT_ALL11,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL11 OUT

	set @de = (select top 1 d12 FROM #NDFL_13_i where mode = 10)
	IF @nCHECK1 = 0
		BEGIN
			SET @SUMMA_PLAT_ALL12 =  @nSum12
		END
	ELSE
		BEGIN 
			EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL12 OUT
			SET @SUMMA_PLAT_ALL12 = ISNULL(@SUMMA_PLAT_ALL12,0)
		END 
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL12 OUT


	
IF @nCHECK1 != 0
begin	
	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'

	INSERT INTO BUFFER (link, id)
	select link, 'DT' from s_accounts where cSinth = '303' and cAnalit = '01'

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '304' and cAnalit = '05'

	INSERT INTO BUFFER (link, id)
	select link, 'KT' from s_accounts where cSinth = '201' and (cAnalit = '11' or cAnalit = '21' or cAnalit = '27')


		SELECT max(g.number) as number, max(g.date) as [date] ,CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')) as PERIOD /*, SUM(P.SUMMA)*/
				into #GPROV_PP
				from 
					dbo.AProvByBufferConditionsShortDate('19900101', '20991231','DT', 'KT') P
					inner join dbo.DOCUMENTS_PAY_ADD PA on P.link = PA.link
					inner join dbo.g_prov G on G.link = PA.link
				WHERE
					P.DEP_LINK = @DEP_LINK
					AND
					G.DEP = @DEP_LINK
					AND
					CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,2,'.')) BETWEEN MONTH(@BEGIN_YEAR) AND MONTH(@PRES_DATE)
					AND
					CONVERT(INT,DBO.SA_GET_WORD_NUM(PERIOD,3,'.')) = YEAR(@BEGIN_YEAR)					
						
		group by PERIOD


	update	#NDFL_13_i	
	set 
		d1 = (select [date] from #GPROV_PP where PERIOD = 1),
		NUM1 = (select number from #GPROV_PP where PERIOD = 1),
		d2 = (select [date] from #GPROV_PP where PERIOD = 2),
		NUM2 = (select number from #GPROV_PP where PERIOD = 2),
		d3 = (select [date] from #GPROV_PP where PERIOD = 3),
		NUM3 = (select number from #GPROV_PP where PERIOD = 3),
		d4 = (select [date] from #GPROV_PP where PERIOD = 4),
		NUM4 = (select number from #GPROV_PP where PERIOD = 4),
		d5 = (select [date] from #GPROV_PP where PERIOD = 5),
		NUM5 = (select number from #GPROV_PP where PERIOD = 5),
		d6 = (select [date] from #GPROV_PP where PERIOD = 6),
		NUM6 = (select number from #GPROV_PP where PERIOD = 6),
		d7 = (select [date] from #GPROV_PP where PERIOD = 7),
		NUM7 = (select number from #GPROV_PP where PERIOD = 7),
		d8 = (select [date] from #GPROV_PP where PERIOD = 8),
		NUM8 = (select number from #GPROV_PP where PERIOD = 8),
		d9 = (select [date] from #GPROV_PP where PERIOD = 9),
		NUM9 = (select number from #GPROV_PP where PERIOD = 9),
		d10 =(select [date] from #GPROV_PP where PERIOD = 10),
		NUM10 = (select number from #GPROV_PP where PERIOD = 10),
		d11 =(select [date] from #GPROV_PP where PERIOD = 11),
		NUM11 = (select number from #GPROV_PP where PERIOD = 11),
		d12 =(select [date] from #GPROV_PP where PERIOD = 12),
		NUM12 = (select number from #GPROV_PP where PERIOD = 12)
	FROM #NDFL_13_i where mode = 10			
						
	exec dbo.BufferClear 'DT'
	exec dbo.BufferClear 'KT'	
end	

	--- расчет перечисленных сумм расчитывается в зависимости от удержанных сум, 
	---  если получившаяся перечисленная сумма больше начисленной , то перечисленную сумму обрезаем до начисленной
	UPDATE #NDFL_13_i
	 SET
		 S_JAN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL1 * (CASE WHEN @SUMMA_NACH_ALL1 > 0 THEN ((select top 1 S_JAN from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL1) ELSE 0 END), 0)),													
		 S_FEB = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL2 * (CASE WHEN @SUMMA_NACH_ALL2 > 0 THEN ((select top 1 S_FEB from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL2) ELSE 0 END), 0)),
		 S_MART= CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL3 * (CASE WHEN @SUMMA_NACH_ALL3 > 0 THEN ((select top 1 S_MART from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL3) ELSE 0 END), 0)), 
		 S_APR = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL4 * (CASE WHEN @SUMMA_NACH_ALL4 > 0 THEN ((select top 1 S_APR from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL4) ELSE 0 END), 0)),
		 S_MAY = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL5 * (CASE WHEN @SUMMA_NACH_ALL5 > 0 THEN ((select top 1 S_MAY from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL5) ELSE 0 END), 0)),
		 S_JUN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL6 * (CASE WHEN @SUMMA_NACH_ALL6 > 0 THEN ((select top 1 S_JUN from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL6) ELSE 0 END), 0)),
		 S_JUL = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL7 * (CASE WHEN @SUMMA_NACH_ALL7 > 0 THEN ((select top 1 S_JUL from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL7) ELSE 0 END), 0)),
		 S_AUG = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL8 * (CASE WHEN @SUMMA_NACH_ALL8 > 0 THEN ((select top 1 S_AUG from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL8) ELSE 0 END), 0)),
		 S_SEN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL9 * (CASE WHEN @SUMMA_NACH_ALL9 > 0 THEN ((select top 1 S_SEN from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL9) ELSE 0 END), 0)),
		 S_OKT = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL10 * (CASE WHEN @SUMMA_NACH_ALL10 > 0 THEN ((select top 1 S_OKT from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL10) ELSE 0 END), 0)),
		 S_NOV = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL11 * (CASE WHEN @SUMMA_NACH_ALL11 > 0 THEN ((select top 1 S_NOV from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL11) ELSE 0 END), 0)),
		 S_DEC = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL12 * (CASE WHEN @SUMMA_NACH_ALL12 > 0 THEN ((select top 1 S_DEC from #NDFL_13_i where mode = 7)/ @SUMMA_NACH_ALL12) ELSE 0 END), 0))
	from #NDFL_13_i where mode = 10

			
	UPDATE #NDFL_13_i
	 SET S_JAN = CASE WHEN S_JAN > ISNULL((select top 1 S_JAN from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_JAN from #NDFL_13_i where mode = 5),0))
					  ELSE S_JAN END,													
		
		 S_FEB = CASE WHEN S_FEB > ISNULL((select top 1 S_FEB from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_FEB from #NDFL_13_i where mode = 5),0))
					  ELSE S_FEB END,
		
		 S_MART= CASE WHEN S_MART > ISNULL((select S_MART from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select S_MART from #NDFL_13_i where mode = 5),0))
					  ELSE S_MART END, 
		
		 S_APR = CASE WHEN S_APR > ISNULL((select top 1 S_APR from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_APR from #NDFL_13_i where mode = 5),0))
					  ELSE S_APR END,
		
		 S_MAY = CASE WHEN S_MAY > ISNULL((select top 1 S_MAY from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_MAY from #NDFL_13_i where mode = 5),0))
					  ELSE S_MAY END,
		
		 S_JUN = CASE WHEN S_JUN > ISNULL((select top 1 S_JUN from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_JUN from #NDFL_13_i where mode = 5),0))
					  ELSE S_JUN END,
		
		 S_JUL = CASE WHEN S_JUL> ISNULL((select top 1 S_JUL from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_JUL from #NDFL_13_i where mode = 5),0))
					  ELSE S_JUL END,
		
		 S_AUG = CASE WHEN S_AUG > ISNULL((select top 1 S_AUG from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_AUG from #NDFL_13_i where mode = 5),0))
					  ELSE S_AUG END,
		
		 S_SEN = CASE WHEN S_SEN > ISNULL((select top 1 S_SEN from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_SEN from #NDFL_13_i where mode = 5),0))
					  ELSE S_SEN END,
		
		 S_OKT = CASE WHEN S_OKT > ISNULL((select top 1 S_OKT from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_OKT from #NDFL_13_i where mode = 5),0))
					  ELSE S_OKT END,
		
		 S_NOV = CASE WHEN S_NOV > ISNULL((select top 1 S_NOV from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_NOV from #NDFL_13_i where mode = 5),0))
					  ELSE S_NOV END,
		
		 S_DEC = CASE WHEN S_DEC > ISNULL((select top 1 S_DEC from #NDFL_13_i where mode = 5),0)
					  THEN (ISNULL((select top 1 S_DEC from #NDFL_13_i where mode = 5),0))
					  ELSE S_DEC END
	from #NDFL_13_i where mode = 10		



	update	#NDFL_13_i	
	set 
		d1 = case when isnull(S_JAN,0) <> 0 then d1 else null end,
		d2 = case when isnull(S_FEB,0) <> 0 then d2 else null end,
		d3 = case when isnull(S_MART,0) <> 0 then d3 else null end,
		d4 = case when isnull(S_APR,0) <> 0 then d4 else null end,
		d5 = case when isnull(S_MAY,0) <> 0 then d5 else null end,
		d6 = case when isnull(S_JUN,0) <> 0 then d6 else null end,
		d7 = case when isnull(S_JUL,0) <> 0 then d7 else null end,
		d8 = case when isnull(S_AUG,0) <> 0 then d8 else null end,
		d9 = case when isnull(S_SEN,0) <> 0 then d9 else null end,
		d10 = case when isnull(S_OKT,0) <> 0 then d10 else null end,
		d11 = case when isnull(S_NOV,0) <> 0 then d11 else null end,
		d12 = case when isnull(S_DEC,0) <> 0 then d12 else null end
	FROM #NDFL_13_i where mode = 10	


--	--Перечисленная сумма по всем за период
----	EXEC dbo.SA_NDFL_PLAT @BEGIN_YEAR, @DATE, @DEP_LINK, @SUMMA_PLAT_ALL OUT
--	EXEC dbo.SA_NDFL_PLAT @BEGIN_YEAR, @DATE, @DEP_LINK, @SUMMA_PLAT_ALL OUT
--	--Начисленная сумма по всем за период
--	EXEC dbo.SA_NDFL_NACHISL @BEGIN_YEAR, @DATE, @DEP_LINK, @SUMMA_NACH_ALL OUT
--	--select @BEGIN_YEAR, @DATE, @DEP_LINK,	@SUMMA_PLAT_ALL, @SUMMA_NACH_ALL
--	--Перечисленная за сотрудника	
--	--UPDATE #RES0 SET NALOG13S = CONVERT(NUMERIC(18,0), ISNULL( @SUMMA_PLAT_ALL * CASE WHEN @SUMMA_NACH_ALL > 0 THEN (NALOGU13	/ @SUMMA_NACH_ALL) ELSE 0 END, 0))
	INSERT INTO #NDFL_13_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 9,
		S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_FEB,0) - isnull(S_JAN,0) , 
		S_MART =isnull(S_MART,0) - isnull(S_FEB,0) ,
		S_APR = isnull(S_APR,0) - isnull(S_MART,0),
		S_MAY = isnull(S_MAY,0) - isnull(S_APR,0),
		S_JUN = isnull(S_JUN,0) - isnull(S_MAY,0),
		S_JUL = isnull(S_JUL,0) - isnull(S_JUN,0),
		S_AUG = isnull(S_AUG,0) - isnull(S_JUL,0),
		S_SEN = isnull(S_SEN,0) - isnull(S_AUG,0), 
		S_OKT = isnull(S_OKT,0) - isnull(S_SEN,0),
		S_NOV = isnull(S_NOV,0) - isnull(S_OKT,0), 
		S_DEC = isnull(S_DEC,0) - isnull(S_NOV,0)
	FROM #NDFL_13_i where mode = 10	
	
	update	#NDFL_13_i	
	set 
		d1 = case when isnull(S_JAN,0) <> 0 then (select d1 from #NDFL_13_i where mode = 10) else null end,
		num1 = case when isnull(S_FEB,0) <> 0 then (select num1 from #NDFL_13_i where mode = 10) else null end,
		d2 = case when isnull(S_FEB,0) <> 0 then (select d2 from #NDFL_13_i where mode = 10) else null end,
		num2 = case when isnull(S_FEB,0) <> 0 then (select num2 from #NDFL_13_i where mode = 10) else null end,
		d3 = case when isnull(S_MART,0) <> 0 then (select d3 from #NDFL_13_i where mode = 10) else null end,
		num3 = case when isnull(S_FEB,0) <> 0 then (select num3 from #NDFL_13_i where mode = 10) else null end,
		d4 = case when isnull(S_APR,0) <> 0 then (select d4 from #NDFL_13_i where mode = 10)  else null end,
		num4 = case when isnull(S_FEB,0) <> 0 then (select num4 from #NDFL_13_i where mode = 10) else null end,
		d5 = case when isnull(S_MAY,0) <> 0 then (select d5 from #NDFL_13_i where mode = 10) else null end,
		num5 = case when isnull(S_FEB,0) <> 0 then (select num5 from #NDFL_13_i where mode = 10) else null end,
		d6 = case when isnull(S_JUN,0) <> 0 then (select d6 from #NDFL_13_i where mode = 10) else null end,
		num6 = case when isnull(S_FEB,0) <> 0 then (select num6 from #NDFL_13_i where mode = 10) else null end,
		d7 = case when isnull(S_JUL,0) <> 0 then (select d7 from #NDFL_13_i where mode = 10) else null end,
		num7 = case when isnull(S_FEB,0) <> 0 then (select num7 from #NDFL_13_i where mode = 10) else null end,
		d8 = case when isnull(S_AUG,0) <> 0 then (select d8 from #NDFL_13_i where mode = 10) else null end,
		num8 = case when isnull(S_FEB,0) <> 0 then (select num8 from #NDFL_13_i where mode = 10) else null end,
		d9 = case when isnull(S_SEN,0) <> 0 then (select d9 from #NDFL_13_i where mode = 10) else null end,
		num9 = case when isnull(S_FEB,0) <> 0 then (select num9 from #NDFL_13_i where mode = 10) else null end,
		d10 = case when isnull(S_OKT,0) <> 0 then (select d10 from #NDFL_13_i where mode = 10) else null end,
		num10 = case when isnull(S_FEB,0) <> 0 then (select num10 from #NDFL_13_i where mode = 10) else null end,
		d11 = case when isnull(S_NOV,0) <> 0 then (select d11 from #NDFL_13_i where mode = 10) else null end,
		num11 = case when isnull(S_FEB,0) <> 0 then (select num11 from #NDFL_13_i where mode = 10) else null end,
		d12 = case when isnull(S_DEC,0) <> 0 then (select d12 from #NDFL_13_i where mode = 10) else null end,
		num12 = case when isnull(S_FEB,0) <> 0 then (select num12 from #NDFL_13_i where mode = 10) else null end
	FROM #NDFL_13_i where mode = 9		
	
	
	------------------------------------------------
	--- 15.Доходы , облагаемая база  - ставка 35%
	-------------------------------------------------
	/*	CREATE  TABLE  #vid_dohod_not13 (LINK_empl INT, LINK_face INT, month_d int,year_d varchar(4), link_inc int, link_dep int, sname varchar(4), name  varchar (254), flag int, percent_stav varchar(2) )
	insert into #vid_dohod_not13	
	select s.link_empl, 
		   s.link_face,
		   s.month_end,
		   s.year_end,
		   s.link_inc,
		   s.link_dep,
		   d.sname,
		   d.name,
		   d.flag,
		   percent_stav = case when d.flag = 1 then '0' 
							   when d.flag = 2 then '13'
							   when d.flag = 3 then '30'
							   else '35'
							   end
	from S_J_C_SHORT  S
		INNER JOIN DICTIONARY_TYP_INCOMS D ON  S.LINK_INC = D.LINK  AND D.FLAG not in (2) 
	where YEAR(S.DATE1) = @cYear 
		 AND S.LINK_DEP = @DEP_LINK 
		 AND S.link_empl = @LINK_EMPL 
		 and S.link_inc is not null
	group by s.link_empl, s.link_face , s.month_end, s.year_end,s.link_inc,s.link_dep, d.sname, d.name, d.flag
	*/

	select j.link_empl,  
		   d.name  , 
		   d.sname , 
		   j.period_begin, 
		   j.period_end, 
		   sum(j.summa) as summa , 
		   p.link_inc

	into #Dohod_35  	
	from   CALCULATE_JURNAL j
		INNER JOIN #EMPLS R  ON  J.link_empl = R.LINK
		inner join pays  p on  p.link = j.link_pays and  p.link_inc is not null 
		inner join #DICT_TYP_INCOMS d on d.link = p.link_inc  and  D.FLAG = 4  	
	where 
 		P.OBJECT = 1
		AND P.LINK in (Select LINK_PAYS from  dbo.NDFL_GroupTax() )   /*  dbo.NDFL_GroupTax() */ 
		AND  month(J.PERIOD_BEGIN) <=@nMonth and  year(J.PERIOD_BEGIN) = @cYear
		/*AND (	@Status <> 1 AND J.LINK_EMPL = @LINK_EMPL /*Если не основной сотрудник, то доход по своему табельному номеру*/
				or
		@Status = 1     and  R.LINK_FACE = @LINK_PERS /*Если основной сотрудник, то доход по всем табельным номерам*/
		)*/
		AND J.LINK_DEP = @DEP_LINK 
	group by j.link_empl, d.sname ,d.name  , j.period_begin, j.period_end, p.link_inc  

	--- Суммы доходов сгруппированнные по коду дохода по месяцам
	CREATE  TABLE #Dohod_35_m( LINK_EMPL int, name varchar(254), sname varchar(3),link_inc int, NUM1 int,summa_1 NUMERIC(10,2), d1 datetime,NUM2 int, summa_2 NUMERIC(10,2), d2 datetime,
							NUM3 int,summa_3 NUMERIC(10,2), d3 datetime,NUM4 int, summa_4 NUMERIC(10,2), d4 datetime,NUM5 int, summa_5 NUMERIC(10,2), d5 datetime,
							NUM6 int,summa_6 NUMERIC(10,2), d6 datetime,NUM7 int, summa_7 NUMERIC(10,2), d7 datetime,NUM8 int, summa_8 NUMERIC(10,2), d8 datetime,
							NUM9 int,summa_9 NUMERIC(10,2), d9 datetime,NUM10 int, summa_10 NUMERIC(10,2), d10 datetime,NUM11 int, summa_11 NUMERIC(10,2), d11 datetime,
							NUM12 int,summa_12 NUMERIC(10,2), d12 datetime)
	INSERT INTO #Dohod_35_m	

	select  d.link_empl,  
		    d.name  , 
		    d.sname , 
		    d.link_inc,
		    [NUM1] = 1,
			[summa_1] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '01' AND LINK_INC = D.LINK_INC),
			[d1] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '01' AND LINK_INC = D.LINK_INC),
			[num2] = 2,
			[summa_2] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '02' AND LINK_INC = D.LINK_INC),
			[d2] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '02' AND LINK_INC = D.LINK_INC),  
			[num3] = 3,
			[summa_3] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '03' AND LINK_INC = D.LINK_INC) ,
			[d3] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '03' AND LINK_INC = D.LINK_INC), 
			[num4] = 4,
			[summa_4] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '04' AND LINK_INC = D.LINK_INC) ,
			[d4] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '04' AND LINK_INC = D.LINK_INC),	
			[num5]= 5,
			[summa_5] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '05' AND LINK_INC = D.LINK_INC) ,
			[d5] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '05' AND LINK_INC = D.LINK_INC),
			[num6]= 6,
			[summa_6] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '06' AND LINK_INC = D.LINK_INC) ,
			[d6] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '06' AND LINK_INC = D.LINK_INC),
			[num7]= 7,
			[summa_7]  = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '07' AND LINK_INC = D.LINK_INC),
			[d7] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '07' AND LINK_INC = D.LINK_INC),
			[num8]= 8,
			[summa_8] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '08' AND LINK_INC = D.LINK_INC),
			[d8]  = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '08' AND LINK_INC = D.LINK_INC),		
			[num9]= 9,
			[summa_9] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '09' AND LINK_INC = D.LINK_INC) ,
			[d9] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '09' AND LINK_INC = D.LINK_INC), 
			[num10]= 10,
			[summa_10] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '10' AND LINK_INC = D.LINK_INC) ,
			[d10] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '10' AND LINK_INC = D.LINK_INC),
			[num11]= 11,
			[summa_11] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '11' AND LINK_INC = D.LINK_INC) ,
			[d11] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '11' AND LINK_INC = D.LINK_INC),
			[num12]= 12,
			[summa_12] = (SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '12' AND LINK_INC = D.LINK_INC) ,
			[d12] = (SELECT period_end FROM #Dohod_35 WHERE month(period_end) = '12' AND LINK_INC = D.LINK_INC)  

	from #Dohod_35 d 
	group by d.link_empl, d.sname ,d.name,  d.link_inc	
	

	--- всего за месяц 
	CREATE  TABLE #Dohod_35_i (MODE INT, S_JAN NUMERIC(10,2), d1 datetime, S_FEB NUMERIC(10,2), d2 datetime,  S_MART NUMERIC(10,2), d3 datetime,  S_APR NUMERIC(10,2), d4 datetime,
							  S_MAY NUMERIC(10,2), d5 datetime,  S_JUN NUMERIC(10,2), d6 datetime, S_JUL NUMERIC(10,2), d7 datetime, S_AUG NUMERIC(10,2), d8 datetime,
							  S_SEN NUMERIC(10,2), d9 datetime, S_OKT NUMERIC(10,2), d10 datetime,  S_NOV NUMERIC(10,2), d11 datetime, S_DEC NUMERIC(10,2), d12 datetime)
	INSERT INTO #Dohod_35_i
	SELECT
		MODE = 1,
		S_JAN = 0 ,
		null, 
		S_FEB = 0 , 
		null,
		S_MART = 0, 
		null,
		S_APR = 0, 
		null,
		S_MAY = 0, 
		null,
		S_JUN = 0,
		null,
		S_JUL = 0,
		null,
		S_AUG = 0, 
		null,
		S_SEN = 0,
		null,
		S_OKT = 0, 
		null,
		S_NOV = 0, 
		null,
		S_DEC = 0,
		null
		 
	UPDATE #Dohod_35_i
	SET	S_JAN = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '01' ),0),
		D1 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '01'), 
		S_FEB = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '02' ),0),
		D2 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '02'), 
		S_MART= round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '03' ),0),
		D3 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '03'), 
		S_APR = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '04' ),0), 
		D4 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '04'), 
		S_MAY = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '05' ),0),
		D5 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '05'), 
		S_JUN = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '06' ),0),
		D6 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '06'), 
		S_JUL = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '07' ),0),
		D7 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '07'), 
		S_AUG = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '08' ),0),
		D8 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '08'), 
		S_SEN = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '09' ),0),
		D9 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '09'), 
		S_OKT = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '10' ),0),
		D10 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '10'), 
		S_NOV = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '11' ),0),
		D11 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '11'), 
		S_DEC = round((SELECT isnull(sum(summa),0) FROM #Dohod_35 WHERE month(period_end) = '12' ),0), 
		D12 = (SELECT isnull(period_end,null) FROM #Dohod_35 WHERE month(period_end) = '12') 
	FROM #Dohod_35_i where mode = 1	
	
	--- всего с нарастающим итогом с начала года 
	INSERT INTO #Dohod_35_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 2,
		S_JAN = isnull(S_JAN,0),
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0),
		S_MART= isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0),
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0),
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #Dohod_35_i where mode = 1
		

	------------------------------------------------
	--- 16. НДФЛ по ставке 35%
	------------------------------------------------
	--сумма начисленного налога С НАЧАЛА ГОДА
	INSERT INTO #Dohod_35_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 3,
		S_JAN = round(isnull(S_JAN,0)*0.35,0),
		S_FEB = round(isnull(S_FEB,0)*0.35,0), 
		S_MART = round(isnull(S_MART,0)*0.35,0),
		S_APR = round(isnull(S_APR,0)*0.35,0),
		S_MAY = round(isnull(S_MAY,0)*0.35,0),
		S_JUN = round(isnull(S_JUN,0)*0.35,0),
		S_JUL = round(isnull(S_JUL,0)*0.35,0),
		S_AUG = round(isnull(S_AUG,0)*0.35,0),
		S_SEN = round(isnull(S_SEN,0)*0.35,0), 
		S_OKT = round(isnull(S_OKT,0)*0.35,0),
		S_NOV = round(isnull(S_NOV,0)*0.35,0), 
		S_DEC = round(isnull(S_DEC,0)*0.35,0)
	FROM #Dohod_35_i where mode = 2
	


	--сумма начисленного налога за месяц 
	INSERT INTO #Dohod_35_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6,S_JUL, D7,S_AUG, D8, S_SEN, D9,S_OKT, D10, S_NOV, D11, S_DEC, D12)
	SELECT
		MODE = 4,
		S_JAN = round(isnull(S_JAN,0)*0.35,0),
		D1,  
		S_FEB = round(isnull(S_FEB,0)*0.35,0), 
		D2,
		S_MART =round(isnull(S_MART,0)*0.35,0),
		D3,
		S_APR = round(isnull(S_APR,0)*0.35,0),
		D4,
		S_MAY = round(isnull(S_MAY,0)*0.35,0),
		D5,
		S_JUN = round(isnull(S_JUN,0)*0.35,0),
		D6,
		S_JUL = round(isnull(S_JUL,0)*0.35,0),
		D7,
		S_AUG = round(isnull(S_AUG,0)*0.35,0),
		D8,
		S_SEN = round(isnull(S_SEN,0)*0.35,0), 
		D9,
		S_OKT = round(isnull(S_OKT,0)*0.35,0),
		D10,
		S_NOV = round(isnull(S_NOV,0)*0.35,0), 
		D11,
		S_DEC = round(isnull(S_DEC,0)*0.35,0),
		D12
	FROM #Dohod_35_i  where mode = 1
	
	--сумма удержанного налого С НАЧАЛА ГОДА
	delete from #MONTHES
	
	--CREATE TABLE #MONTHES ([MONTH] INT, SUMMA NUMERIC(18,2), CODE_DED VARCHAR(10) )
	INSERT INTO #MONTHES
	SELECT MONTH(DATE1), CAST( (SUM(CAST(round(SUMMA,0) as int) )) AS NUMERIC(8,0) ), ''
	FROM #S_J_C_SHORT SJC 
	INNER JOIN EMPL E ON (E.LINK = SJC.LINK_EMPL)
	INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 5)
	WHERE 
 		YEAR(DATE1) = @varKSnYear 
 		and
 		MONTH(DATE1)<= @nMonth
		AND 
		SJC.LINK_DEP = @DEP_LINK 
		AND 
		E.PERS_LINK = @LINK_PERS 
	GROUP BY MONTH(DATE1)
	UNION ALL
	SELECT MONTH(DATE1), CAST( (SUM(CAST(round(SUMMA,0) as int) )) AS NUMERIC(8,0) ), ''
	FROM #S_J_C_SHORT SJC INNER JOIN PAYS P ON (SJC.LINK_PAYS = P.LINK AND P.OBJECT = 2 AND P.WAY_CALC  = 5)
	WHERE 
 		YEAR(DATE1) = @varKSnYear 
		and 
		MONTH(DATE1)<= @nMonth
		AND 
		SJC.LINK_DEP = @DEP_LINK 
		AND
		SJC.PERS_LINK = @LINK_PERS 
	GROUP BY MONTH(DATE1)		
		
	--сумма удержанного налога за месяц 
	INSERT INTO #Dohod_35_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	select 5, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL
	
	UPDATE 	#Dohod_35_i
	Set
		MODE = 5,
		S_JAN = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 1 ),0),0), 
		D1 = case when isnull(S_JAN,0) <>0 then (select max(d.date1)  from dbo.days_month(1,@cYear)d) else null end,
		S_FEB = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 2 ),0),0), 
		D2 = case when isnull(S_FEB,0) <>0 then (select max(d.date1)  from dbo.days_month(2,@cYear)d) else null end,
		S_MART =isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 3 ),0),0),
		D3 = case when isnull(S_MART,0) <>0 then (select max(d.date1)  from dbo.days_month(3,@cYear)d) else null end,
		S_APR = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 4 ),0),0),
		D4 = case when isnull(S_APR,0) <>0 then (select max(d.date1)  from dbo.days_month(4,@cYear)d) else null end,
		S_MAY = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 5 ),0),0),
		D5 = case when isnull(S_MAY,0) <>0 then (select max(d.date1)  from dbo.days_month(5,@cYear)d) else null end,
		S_JUN = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 6 ),0),0),
		D6 = case when isnull(S_JUN,0) <>0 then (select max(d.date1)  from dbo.days_month(6,@cYear)d) else null end,
		S_JUL = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 7 ),0),0),
		D7 = case when isnull(S_JUL,0) <>0 then (select max(d.date1)  from dbo.days_month(7,@cYear)d) else null end,
		S_AUG = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 8 ),0),0),
		D8 = case when isnull(S_AUG,0) <>0 then (select max(d.date1)  from dbo.days_month(8,@cYear)d) else null end,
		S_SEN = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 9 ),0),0), 
		D9 = case when isnull(S_SEN,0) <>0 then (select max(d.date1)  from dbo.days_month(9,@cYear)d) else null end,
		S_OKT = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 10 ),0),0),
		D10 = case when isnull(S_OKT,0) <>0 then (select max(d.date1)  from dbo.days_month(10,@cYear)d) else null end,
		S_NOV = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 11 ),0),0), 
		D11 = case when isnull(S_NOV,0) <>0 then (select max(d.date1)  from dbo.days_month(11,@cYear)d) else null end,
		S_DEC = isnull(round((SELECT isnull(summa,0) FROM #MONTHES where [month]= 12 ),0),0),
		D12 = case when isnull(S_DEC,0) <>0 then (select max(d.date1)  from dbo.days_month(12,@cYear)d) else null end
	FROM #Dohod_35_i  where mode = 5
	
	
	--сумма удержанного за год по месяцам
	INSERT INTO #Dohod_35_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 6,
		S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_JAN,0) + isnull(S_FEB,0), 
		S_MART =isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0),
		S_APR = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0),
		S_MAY = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0),
		S_JUN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0),
		S_JUL = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0),
		S_AUG = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0),
		S_SEN = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0), 
		S_OKT = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0),
		S_NOV = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0), 
		S_DEC = isnull(S_JAN,0) + isnull(S_FEB,0) + isnull(S_MART,0) + isnull(S_APR,0) + isnull(S_MAY,0) + isnull(S_JUN,0) + isnull(S_JUL,0) + isnull(S_AUG,0) + isnull(S_SEN,0) + isnull(S_OKT,0) + isnull(S_NOV,0) + isnull(S_DEC,0)
	FROM #Dohod_35_i  where mode = 5 
	

	------------------------------------------------
	-- 17. Перечисление НДФЛ по ставке 35%
	------------------------------------------------
	--месяц 
	INSERT INTO #Dohod_35_i (MODE, S_JAN, D1, S_FEB, D2, S_MART, D3, S_APR, D4, S_MAY, D5, S_JUN, D6, S_JUL, D7, S_AUG, D8, S_SEN, D9, S_OKT, D10, S_NOV, D11, S_DEC, D12)
	select 8, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL
	update	#Dohod_35_i	
	set 
		d1 = (select max(d.date1)  from dbo.days_month(1,@cYear)d),
		d2 = (select max(d.date1)  from dbo.days_month(2,@cYear)d),
		d3 = (select max(d.date1)  from dbo.days_month(3,@cYear)d),
		d4 = (select max(d.date1)  from dbo.days_month(4,@cYear)d),
		d5 = (select max(d.date1)  from dbo.days_month(5,@cYear)d),
		d6 = (select max(d.date1)  from dbo.days_month(6,@cYear)d),
		d7 = (select max(d.date1)  from dbo.days_month(7,@cYear)d),
		d8 = (select max(d.date1)  from dbo.days_month(8,@cYear)d),
		d9 = (select max(d.date1)  from dbo.days_month(9,@cYear)d),
		d10 =(select max(d.date1)  from dbo.days_month(10,@cYear)d),
		d11 =(select max(d.date1)  from dbo.days_month(11,@cYear)d),
		d12 =(select max(d.date1)  from dbo.days_month(12,@cYear)d)
	FROM #Dohod_35_i where mode = 8	
	
	set @db = @BEGIN_YEAR
	set @de = (select top 1 d1  FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL1 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL1 OUT

	set @de = (select top 1 d2  FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL2 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL2 OUT

	set @de = (select top 1 d3  FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL3 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL3 OUT

	set @de = (select top 1 d4 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL4 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL4 OUT

	set @de = (select top 1 d5 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL5 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL5 OUT

	set @de = (select top 1 d6 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL6 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL6 OUT

	set @de = (select top 1 d7 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL7 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL7 OUT

	set @de = (select top 1 d8 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL8 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL8 OUT

	set @de = (select top 1 d9 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL9 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL9 OUT

	set @de = (select top 1 d10 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL10 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL10 OUT

	set @de = (select top 1 d11 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL11 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL11 OUT

	set @de = (select top 1 d12 FROM #Dohod_35_i where mode = 8)
	EXEC dbo.SA_NDFL_PLAT @db, @de, @DEP_LINK, @SUMMA_PLAT_ALL12 OUT
	EXEC dbo.SA_NDFL_NACHISL @db, @de, @DEP_LINK, @SUMMA_NACH_ALL12 OUT

	--- расчет перечисленных сумм расчитывается в зависимости от удержанных сум, 
	---  если получившаяся перечисленная сумма больше начисленной , то перечисленную сумму обрезаем до начисленной
	UPDATE #Dohod_35_i
	 SET S_JAN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL1 * (CASE WHEN @SUMMA_NACH_ALL1 > 0 THEN ((select top 1 S_JAN from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL1) ELSE 0 END), 0)),													
		 S_FEB = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL2 * (CASE WHEN @SUMMA_NACH_ALL2 > 0 THEN ((select top 1 S_FEB from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL2) ELSE 0 END), 0)),
		 S_MART= CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL3 * (CASE WHEN @SUMMA_NACH_ALL3 > 0 THEN ((select top 1 S_MART from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL3) ELSE 0 END), 0)), 
		 S_APR = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL4 * (CASE WHEN @SUMMA_NACH_ALL4 > 0 THEN ((select top 1 S_APR from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL4) ELSE 0 END), 0)),
		 S_MAY = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL5 * (CASE WHEN @SUMMA_NACH_ALL5 > 0 THEN ((select top 1 S_MAY from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL5) ELSE 0 END), 0)),
		 S_JUN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL6 * (CASE WHEN @SUMMA_NACH_ALL6 > 0 THEN ((select top 1 S_JUN from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL6) ELSE 0 END), 0)),
		 S_JUL = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL7 * (CASE WHEN @SUMMA_NACH_ALL7 > 0 THEN ((select top 1 S_JUL from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL7) ELSE 0 END), 0)),
		 S_AUG = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL8 * (CASE WHEN @SUMMA_NACH_ALL8 > 0 THEN ((select top 1 S_AUG from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL8) ELSE 0 END), 0)),
		 S_SEN = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL9 * (CASE WHEN @SUMMA_NACH_ALL9 > 0 THEN ((select top 1 S_SEN from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL9) ELSE 0 END), 0)),
		 S_OKT = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL10 * (CASE WHEN @SUMMA_NACH_ALL10 > 0 THEN ((select top 1 S_OKT from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL10) ELSE 0 END), 0)),
		 S_NOV = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL11 * (CASE WHEN @SUMMA_NACH_ALL11 > 0 THEN ((select top 1 S_NOV from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL11) ELSE 0 END), 0)),
		 S_DEC = CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL12 * (CASE WHEN @SUMMA_NACH_ALL12 > 0 THEN ((select top 1 S_DEC from #Dohod_35_i where mode = 6)/ @SUMMA_NACH_ALL12) ELSE 0 END), 0))
	from #Dohod_35_i where mode = 8
			
	UPDATE #Dohod_35_i
	 SET S_JAN = CASE WHEN S_JAN > ISNULL((select top 1 S_JAN from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_JAN from #Dohod_35_i where mode = 3),0))
					  ELSE S_JAN END,													
		
		 S_FEB = CASE WHEN S_FEB > ISNULL((select top 1 S_FEB from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_FEB from #Dohod_35_i where mode = 3),0))
					  ELSE S_FEB END,
		
		 S_MART= CASE WHEN S_MART > ISNULL((select top 1 S_MART from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_MART from #Dohod_35_i where mode = 3),0))
					  ELSE S_MART END, 
		
		 S_APR = CASE WHEN S_APR > ISNULL((select top 1 S_APR from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_APR from #Dohod_35_i where mode = 3),0))
					  ELSE S_APR END,
		
		 S_MAY = CASE WHEN S_MAY > ISNULL((select top 1 S_MAY from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_MAY from #Dohod_35_i where mode = 3),0))
					  ELSE S_MAY END,
		
		 S_JUN = CASE WHEN S_JUN > ISNULL((select top 1 S_JUN from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_JUN from #Dohod_35_i where mode = 3),0))
					  ELSE S_JUN END,
		
		 S_JUL = CASE WHEN S_JUL> ISNULL((select top 1 S_JUL from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_JUL from #Dohod_35_i where mode = 3),0))
					  ELSE S_JUL END,
		
		 S_AUG = CASE WHEN S_AUG > ISNULL((select top 1 S_AUG from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_AUG from #Dohod_35_i where mode = 3),0))
					  ELSE S_AUG END,
		
		 S_SEN = CASE WHEN S_SEN > ISNULL((select top 1 S_SEN from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_SEN from #Dohod_35_i where mode = 3),0))
					  ELSE S_SEN END,
		
		 S_OKT = CASE WHEN S_OKT > ISNULL((select top 1 S_OKT from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_OKT from #Dohod_35_i where mode = 3),0))
					  ELSE S_OKT END,
		
		 S_NOV = CASE WHEN S_NOV > ISNULL((select top 1 S_NOV from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_NOV from #Dohod_35_i where mode = 3),0))
					  ELSE S_NOV END,
		
		 S_DEC = CASE WHEN S_DEC > ISNULL((select top 1 S_DEC from #Dohod_35_i where mode = 3),0)
					  THEN (ISNULL((select top 1 S_DEC from #Dohod_35_i where mode = 3),0))
					  ELSE S_DEC END
	from #Dohod_35_i where mode = 8	
---CONVERT(NUMERIC(18,0), ISNULL(@SUMMA_PLAT_ALL1 * (CASE WHEN @SUMMA_NACH_ALL1 > 0 THEN ((select S_JAN from #Dohod_35_i where mode = 5)/ @SUMMA_NACH_ALL1) ELSE 0 END),0)),
	
	update	#Dohod_35_i 
	set 
		d1 = case when isnull(S_JAN,0) <> 0 then d1 else null end,
		d2 = case when isnull(S_FEB,0) <> 0 then d2 else null end,
		d3 = case when isnull(S_MART,0) <> 0 then d3 else null end,
		d4 = case when isnull(S_APR,0) <> 0 then d4 else null end,
		d5 = case when isnull(S_MAY,0) <> 0 then d5 else null end,
		d6 = case when isnull(S_JUN,0) <> 0 then d6 else null end,
		d7 = case when isnull(S_JUL,0) <> 0 then d7 else null end,
		d8 = case when isnull(S_AUG,0) <> 0 then d8 else null end,
		d9 = case when isnull(S_SEN,0) <> 0 then d9 else null end,
		d10 = case when isnull(S_OKT,0) <> 0 then d10 else null end,
		d11 = case when isnull(S_NOV,0) <> 0 then d11 else null end,
		d12 = case when isnull(S_DEC,0) <> 0 then d12 else null end
	FROM #Dohod_35_i  where mode = 8	
	

	--год
	INSERT INTO #Dohod_35_i (MODE, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL,S_AUG, S_SEN,S_OKT, S_NOV, S_DEC)
	SELECT
		MODE = 7,
		S_JAN = isnull(S_JAN,0), 
		S_FEB = isnull(S_FEB,0) - isnull(S_JAN,0) , 
		S_MART =isnull(S_MART,0) - isnull(S_FEB,0) ,
		S_APR = isnull(S_APR,0) - isnull(S_MART,0),
		S_MAY = isnull(S_MAY,0) - isnull(S_APR,0),
		S_JUN = isnull(S_JUN,0) - isnull(S_MAY,0),
		S_JUL = isnull(S_JUL,0) - isnull(S_JUN,0),
		S_AUG = isnull(S_AUG,0) - isnull(S_JUL,0),
		S_SEN = isnull(S_SEN,0) - isnull(S_AUG,0), 
		S_OKT = isnull(S_OKT,0) - isnull(S_SEN,0),
		S_NOV = isnull(S_NOV,0) - isnull(S_OKT,0), 
		S_DEC = isnull(S_DEC,0) - isnull(S_NOV,0)
	FROM #Dohod_35_i where mode = 8	
	
	------------------------------------------------
	-- 14. Расчет сумм материальной выгоды на дату погашения
	------------------------------------------------
	
	------------------------------------------------
	-- 18.Взыскание/Возврат НДФЛ
	------------------------------------------------
	
	------------------------------------------------
	-- 19. Расчеты по налогу
	------------------------------------------------
	
	-- задолженность по ндфл на начало месяца
	--------
	
	CREATE  TABLE #NALOG_RASH (Mode int, S_JAN NUMERIC(10,2), S_FEB NUMERIC(10,2), S_MART NUMERIC(10,2), S_APR NUMERIC(10,2), S_MAY NUMERIC(10,2), S_JUN NUMERIC(10,2),S_JUL NUMERIC(10,2),S_AUG NUMERIC(10,2), S_SEN NUMERIC(10,2),S_OKT NUMERIC(10,2), S_NOV NUMERIC(10,2), S_DEC NUMERIC(10,2),SNN NUMERIC(10,2), SNU NUMERIC(10,2), DOLG_NAEND NUMERIC(10,2), DOLG_NPEND NUMERIC(10,2))
	insert into #NALOG_RASH
	SELECT		
		MODE = 1,
		S_JAN = 0 , 
		S_FEB = 0 , 
		S_MART = 0, 
		S_APR = 0, 
		S_MAY = 0, 
		S_JUN = 0,
		S_JUL = 0,
		S_AUG = 0, 
		S_SEN = 0,
		S_OKT = 0, 
		S_NOV = 0, 
		S_DEC = 0,
		snn = 0,
		snu = 0,
		DOLG_NAEND  = 0,
		DOLG_NPEND = 0

	
	-- за налогоплательщиком долг если в плюсе
	-- если в минусе то за налоговым агентом
		
	UPDATE #NALOG_RASH 
	set S_JAN = round(isnull(((n1.s_jan + n2.s_jan) - (U1.s_jan + U2.s_jan)  ),0),0) ,
		S_FEB = round(isnull(((n1.S_FEB + n2.S_FEB) - (U1.S_FEB + U2.S_FEB) ),0),0),
		S_MART= round(isnull(((n1.S_MART + n2.S_MART) - (U1.S_MART + U2.S_MART)),0),0),
		S_APR = round(isnull(((n1.S_APR + n2.S_APR) - (U1.S_APR + U2.S_APR)),0),0),
		S_MAY = round(isnull(((n1.S_MAY + n2.S_MAY) - (U1.S_MAY + U2.S_MAY)),0),0),
		S_JUN = round(isnull(((n1.S_JUN + n2.S_JUN) - (U1.S_JUN + U2.S_JUN)),0),0),
		S_JUL = round(isnull(((n1.S_JUL + n2.S_JUL) - (U1.S_JUL + U2.S_JUL)),0),0),
		S_AUG = round(isnull(((n1.S_AUG + n2.S_AUG) - (U1.S_AUG + U2.S_AUG)),0),0),
		S_SEN = round(isnull(((n1.S_SEN + n2.S_SEN) - (U1.S_SEN + U2.S_SEN)),0),0),
		S_OKT = round(isnull(((n1.S_OKT + n2.S_OKT) - (U1.S_OKT + U2.S_OKT)),0),0),
		S_NOV = round(isnull(((n1.S_NOV + n2.S_NOV) - (U1.S_NOV + U2.S_NOV)),0),0),
		S_DEC = round(isnull(((n1.S_DEC + n2.S_DEC) - (U1.S_DEC + U2.S_DEC)),0),0),
		
	 SNN = (COALESCE(Sn1.S_DEC,0)+COALESCE(Sn2.S_DEC,0)),
							
	 SNU = (COALESCE(SU1.S_DEC,0)+COALESCE(SU2.S_DEC,0))
	
	from #NDFL_13_i N1, #Dohod_35_i  N2 , #NDFL_13_i U1, #Dohod_35_i  U2, #NDFL_13_i SN1, #Dohod_35_i  SN2 ,  #NDFL_13_i SU1, #Dohod_35_i  SU2
		where n1.mode = 6
		  and n2.mode = 5 
		  and U1.MODE = 8
		  AND U2.MODE = 4	
		  AND Sn1.mode = 5
		  and Sn2.mode = 8 
		  and SU1.MODE = 7
		  AND SU2.MODE = 3	
		  
			
	-- долг за налоговым агентом		
	UPDATE #NALOG_RASH  SET DOLG_NPEND = SNN - SNU, DOLG_NAEND = 0
	-- долг за налогоплательщиком
	UPDATE #NALOG_RASH SET DOLG_NAEND = -DOLG_NPEND, DOLG_NPEND = 0 WHERE DOLG_NPEND <0

	insert into #NALOG_RASH
	SELECT		
		MODE = 2,
		S_JAN = 0 , 
		S_FEB = 0 , 
		S_MART = 0, 
		S_APR = 0, 
		S_MAY = 0, 
		S_JUN = 0,
		S_JUL = 0,
		S_AUG = 0, 
		S_SEN = 0,
		S_OKT = 0, 
		S_NOV = 0, 
		S_DEC = 0,
		snn = 0,
		snu = 0,
		DOLG_NAEND  = 0,
		DOLG_NPEND = 0

	
	-- за налогоплательщиком долг если в плюсе
	-- если в минусе то за налоговым агентом
		
	UPDATE #NALOG_RASH 
	set S_JAN = case when isnull((select top 1 s_jan from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 s_jan from #NALOG_RASH where mode = 1),0) end ,
		S_FEB = case when isnull((select top 1 S_FEB from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_FEB from #NALOG_RASH where mode = 1),0) end ,
		S_MART= case when isnull((select top 1 S_MART from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_MART from #NALOG_RASH where mode = 1),0) end ,
		S_APR = case when isnull((select top 1 S_APR from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_APR from #NALOG_RASH where mode = 1),0) end ,
		S_MAY = case when isnull((select top 1 S_MAY from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_MAY from #NALOG_RASH where mode = 1),0) end ,
		S_JUN = case when isnull((select top 1 S_JUN from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_JUN from #NALOG_RASH where mode = 1),0) end ,
		S_JUL = case when isnull((select top 1 S_JUL from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_JUL from #NALOG_RASH where mode = 1),0) end ,
		S_AUG = case when isnull((select top 1 S_AUG from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_AUG from #NALOG_RASH where mode = 1),0) end ,
		S_SEN = case when isnull((select top 1 S_SEN from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_SEN from #NALOG_RASH where mode = 1),0) end ,
		S_OKT = case when isnull((select top 1 S_OKT from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_OKT from #NALOG_RASH where mode = 1),0) end ,
		S_NOV = case when isnull((select top 1 S_NOV from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_NOV from #NALOG_RASH where mode = 1),0) end ,
		S_DEC = case when isnull((select top 1 S_DEC from #NALOG_RASH where mode = 1),0) > 0 then 0 else isnull((select top 1 S_DEC from #NALOG_RASH where mode = 1),0) end ,
		
	 SNN = SNN,
							
	 SNU = SNU
	
	from #NALOG_RASH
		where mode = 2 
		 
			
	-- долг за налоговым агентом		
	UPDATE #NALOG_RASH  SET DOLG_NPEND = SNN - SNU, DOLG_NAEND = 0
	-- долг за налогоплательщиком
	UPDATE #NALOG_RASH SET DOLG_NAEND = -DOLG_NPEND, DOLG_NPEND = 0 WHERE DOLG_NPEND <0

 ----Начислено НДФЛ всего, в том числе по ставкам
	INSERT INTO #NALOG_RASH (Mode, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL, S_AUG, S_SEN ,S_OKT, S_NOV, S_DEC, SNN, SNU, DOLG_NAEND, DOLG_NPEND)
	SELECT 3, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
		 
		
	UPDATE #NALOG_RASH 
	set S_JAN = (select (n1.s_jan + n2.s_jan) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4),
		S_FEB = (select (n1.S_FEB + n2.S_FEB) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_MART =(select (n1.S_MART + n2.S_MART) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_APR = (select (n1.S_APR + n2.S_APR) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_MAY = (select (n1.S_MAY + n2.S_MAY) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_JUN = (select (n1.S_JUN + n2.S_JUN) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_JUL = (select (n1.S_JUL + n2.S_JUL) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_AUG = (select (n1.S_AUG + n2.S_AUG) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_SEN = (select (n1.S_SEN + n2.S_SEN) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_OKT = (select (n1.S_OKT + n2.S_OKT) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_NOV = (select (n1.S_NOV + n2.S_NOV) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 ),
		S_DEC = (select (n1.S_DEC + n2.S_DEC) from #NDFL_13_i N1, #Dohod_35_i  N2 where n1.mode = 6 and n2.mode = 4 )
	FROM #NALOG_RASH
		where Mode = 3
	--- 13%
	
	INSERT INTO #NALOG_RASH (Mode, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL, S_AUG, S_SEN ,S_OKT, S_NOV, S_DEC, SNN, SNU, DOLG_NAEND, DOLG_NPEND)
	SELECT 4, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	
	if @varKSCOEFF = 0.13
	begin	
		UPDATE #NALOG_RASH 
		set S_JAN = (select top 1 s_jan from #NDFL_13_i where mode = 6),
			S_FEB = (select top 1 S_FEB from #NDFL_13_i where mode = 6),
			S_MART =(select top 1 S_MART from #NDFL_13_i where mode = 6),
			S_APR = (select top 1 S_APR from #NDFL_13_i where mode = 6),
			S_MAY = (select top 1 S_MAY from #NDFL_13_i where mode = 6),
			S_JUN = (select top 1 S_JUN from #NDFL_13_i where mode = 6),
			S_JUL = (select top 1 S_JUL from #NDFL_13_i where mode = 6),
			S_AUG = (select top 1 S_AUG from #NDFL_13_i where mode = 6),
			S_SEN = (select top 1 S_SEN from #NDFL_13_i where mode = 6),
			S_OKT = (select top 1 S_OKT from #NDFL_13_i where mode = 6),
			S_NOV = (select top 1 S_NOV from #NDFL_13_i where mode = 6),
			S_DEC = (select top 1 S_DEC from #NDFL_13_i where mode = 6),


		 SNN = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #NDFL_13_i where mode = 5),
								
		 SNU = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #NDFL_13_i where mode = 7)
		from #NALOG_RASH 
			where Mode = 4	

		UPDATE #NALOG_RASH  SET DOLG_NPEND = SNN - SNU, DOLG_NAEND = 0
		from #NALOG_RASH 
			where Mode = 4	
		
		UPDATE #NALOG_RASH 
			SET DOLG_NAEND = -DOLG_NPEND, DOLG_NPEND = 0 
		from #NALOG_RASH 
			where Mode = 4	
			and DOLG_NPEND <0
	end
		
	-- 35%	
	INSERT INTO #NALOG_RASH (Mode, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL, S_AUG, S_SEN ,S_OKT, S_NOV, S_DEC, SNN, SNU, DOLG_NAEND, DOLG_NPEND)
	SELECT 5, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
		
	UPDATE #NALOG_RASH 
	set S_JAN = (select top 1 s_jan from #Dohod_35_i  where mode = 4),
		S_FEB = (select top 1 S_FEB from #Dohod_35_i  where mode = 4),
		S_MART =(select top 1 S_MART from #Dohod_35_i  where mode = 4),
		S_APR = (select top 1 S_APR from #Dohod_35_i  where mode = 4),
		S_MAY = (select top 1 S_MAY from #Dohod_35_i  where mode = 4),
		S_JUN = (select top 1 S_JUN from #Dohod_35_i  where mode = 4),
		S_JUL = (select top 1 S_JUL from #Dohod_35_i  where mode = 4),
		S_AUG = (select top 1 S_AUG from #Dohod_35_i  where mode = 4),
		S_SEN = (select top 1 S_SEN from #Dohod_35_i  where mode = 4),
		S_OKT = (select top 1 S_OKT from #Dohod_35_i  where mode = 4),
		S_NOV = (select top 1 S_NOV from #Dohod_35_i  where mode = 4),
		S_DEC = (select top 1 S_DEC from #Dohod_35_i  where mode = 4),
	
	 SNN = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #Dohod_35_i  where mode = 3 ),
							
	 SNU = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #Dohod_35_i  where mode = 8 )
	from #NALOG_RASH 
		where Mode = 5
		
	UPDATE #NALOG_RASH  SET DOLG_NPEND = SNN - SNU, DOLG_NAEND = 0
	from #NALOG_RASH 
		where Mode = 5
	
	UPDATE #NALOG_RASH SET DOLG_NAEND = -DOLG_NPEND, DOLG_NPEND = 0 
	from #NALOG_RASH 
		where Mode = 5	and DOLG_NPEND <0

	-- 30%
	INSERT INTO #NALOG_RASH (Mode, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL, S_AUG, S_SEN ,S_OKT, S_NOV, S_DEC, SNN, SNU, DOLG_NAEND, DOLG_NPEND)
	SELECT 6, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	
	if @varKSCOEFF = 0.30
	begin	
		UPDATE #NALOG_RASH 
		set S_JAN = (select top 1  s_jan from #NDFL_13_i where mode = 6),
			S_FEB = (select top 1  S_FEB from #NDFL_13_i where mode = 6),
			S_MART =(select top 1  S_MART from #NDFL_13_i where mode = 6),
			S_APR = (select top 1  S_APR from #NDFL_13_i where mode = 6),
			S_MAY = (select top 1  S_MAY from #NDFL_13_i where mode = 6),
			S_JUN = (select top 1 S_JUN from #NDFL_13_i where mode = 6),
			S_JUL = (select top 1 S_JUL from #NDFL_13_i where mode = 6),
			S_AUG = (select top 1 S_AUG from #NDFL_13_i where mode = 6),
			S_SEN = (select top 1 S_SEN from #NDFL_13_i where mode = 6),
			S_OKT = (select top 1 S_OKT from #NDFL_13_i where mode = 6),
			S_NOV = (select top 1 S_NOV from #NDFL_13_i where mode = 6),
			S_DEC = (select top 1 S_DEC from #NDFL_13_i where mode = 6),


		 SNN = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #NALOG_RASH where mode = 5),
								
		 SNU = (SELECT TOP 1 COALESCE(S_DEC,0) FROM #NDFL_13_i where mode = 7)
		from #NALOG_RASH 
			where Mode = 4	

		UPDATE #NALOG_RASH  SET DOLG_NPEND = SNN - SNU, DOLG_NAEND = 0
		from #NALOG_RASH 
			where Mode = 4	
		
		UPDATE #NALOG_RASH 
			SET DOLG_NAEND = -DOLG_NPEND, DOLG_NPEND = 0 
		from #NALOG_RASH 
			where Mode = 4	
			and DOLG_NPEND <0
	end

	-- 15%
	INSERT INTO #NALOG_RASH
	SELECT 7, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	-- 9%
	INSERT INTO #NALOG_RASH
	SELECT 8, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	
	-- 6%
	INSERT INTO #NALOG_RASH
	SELECT 9, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	
	-- Удержано НДФЛ	
	INSERT INTO #NALOG_RASH (Mode, S_JAN, S_FEB, S_MART, S_APR, S_MAY, S_JUN,S_JUL, S_AUG, S_SEN ,S_OKT, S_NOV, S_DEC, SNN, SNU, DOLG_NAEND, DOLG_NPEND)
	SELECT 10, 
		0, 
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0

		
	UPDATE #NALOG_RASH 
	set S_JAN = isnull((select U1.s_jan + U2.s_jan  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5 ),0),
		S_FEB = isnull((select U1.S_FEB + U2.S_FEB  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_MART = isnull((select U1.S_MART + U2.S_MART  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_APR = isnull((select U1.S_APR + U2.S_APR  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_MAY = isnull((select U1.S_MAY + U2.S_MAY  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_JUN = isnull((select U1.S_JUN + U2.S_JUN  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_JUL = isnull((select U1.S_JUL + U2.S_JUL  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_AUG = isnull((select U1.S_AUG + U2.S_AUG  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_SEN = isnull((select U1.S_SEN + U2.S_SEN  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_OKT = isnull((select U1.S_OKT + U2.S_OKT  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_NOV = isnull((select U1.S_NOV + U2.S_NOV  from #NDFL_13_i U1, #Dohod_35_i  U2 where u1.mode = 8 and u2.mode = 5),0),
		S_DEC = isnull((select U1.S_DEC + U2.S_DEC  from #NDFL_13_i U1, #Dohod_35_i  U2	where u1.mode = 8 and u2.mode = 5),0)
	from #NALOG_RASH 
		where Mode = 10		

-------------------------------------------------------		
-- 20. Общая сумма налога по итогам налогового периода
-------------------------------------------------------
	CREATE  TABLE #ALL_NALOG_Y (PER_Stav varchar(4), S_NN NUMERIC(10,2), S_NU NUMERIC(10,2), S_PERECH NUMERIC(10,2), S_PERED NUMERIC(10,2), S_VOZV NUMERIC(10,2), S_ZACH NUMERIC(10,2),DOLG_NP NUMERIC(10,2),DOLG_NA NUMERIC(10,2))
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '6%',
		S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 9),
		S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 9) ,
		S_PERECH =  case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 9),0) > 0 then (SELECT TOP 1 S_DEC FROM #NDFL_13_i where mode = 10) else 0 end ,
		S_PERED = 0,
		S_VOZV = 0,
		S_ZACH = 0,
		DOLG_NP = 0,
		DOLG_NA = 0
		
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NP = S_NN - S_NU,  
		DOLG_NA = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '6%'	
			
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NA = -DOLG_NP,
		DOLG_NP = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '6%'	
		and DOLG_NP <0		
	---
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '9%',
		S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 8),
		S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 8) ,
		S_PERECH = case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 8),0) > 0 then (SELECT TOP 1 S_DEC FROM #NDFL_13_i where mode = 10) else 0 end ,
		S_PERED = 0, 
		S_VOZV = 0, 
		S_ZACH = 0, 
		DOLG_NP = 0,
		DOLG_NA = 0	
	
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NP = S_NN - S_NU,  
		DOLG_NA = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '9%'	
			
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NA = -DOLG_NP,
		DOLG_NP = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '9%'	
		and DOLG_NP <0	
	
	---
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '13%',
		S_NN = 0 ,
		S_NU = 0 ,
		S_PERECH = 0 , 
		S_PERED = 0, 
		S_VOZV = 0, 
		S_ZACH = 0, 
		DOLG_NP = 0,
		DOLG_NA = 0	
	
	if @varKSCOEFF = 0.13
	begin	
		UPDATE #ALL_NALOG_Y 
		set S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 4),
			S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 4) ,
			S_PERECH = case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 4),0) > 0 then (SELECT TOP 1 S_DEC FROM #NDFL_13_i where mode = 10) else 0 end ,
			S_PERED = 0,
			S_VOZV = 0,
			S_ZACH = 0
		from #ALL_NALOG_Y 
			where PER_STAV = '13%'	
		
			UPDATE #ALL_NALOG_Y 
			SET DOLG_NP = S_NN - S_NU,  
				DOLG_NA = 0
			from #ALL_NALOG_Y 
				where PER_STAV = '13%'	
			
			UPDATE #ALL_NALOG_Y 
				SET DOLG_NA = -DOLG_NP,
					DOLG_NP = 0
			from #ALL_NALOG_Y 
				where PER_STAV = '13%'	
				and DOLG_NP <0	
	end
	----
	
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '15%',
		S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 7),
		S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 7) ,
		S_PERECH = case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 7),0) > 0 then (SELECT TOP 1 S_DEC FROM #NDFL_13_i where mode = 10) else 0 end , 
		S_PERED = 0, 
		S_VOZV = 0, 
		S_ZACH = 0, 
		DOLG_NP = 0,
		DOLG_NA = 0	
	
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NP = S_NN - S_NU,  
		DOLG_NA = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '15%'	
			
	UPDATE #ALL_NALOG_Y 
	SET DOLG_NA = -DOLG_NP,
		DOLG_NP = 0
	from #ALL_NALOG_Y 
	where PER_STAV = '15%'	
		and DOLG_NP <0	
	----
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '30%',
		S_NN = 0 ,
		S_NU = 0 ,
		S_PERECH = 0 , 
		S_PERED = 0, 
		S_VOZV = 0, 
		S_ZACH = 0, 
		DOLG_NP = 0,
		DOLG_NA = 0	

	if @varKSCOEFF = 0.30
	begin	
			
		UPDATE #ALL_NALOG_Y 
		set S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 6),
			S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 6),
			S_PERECH = case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 6),0) > 0 then (SELECT TOP 1 S_DEC FROM #NDFL_13_i where mode = 10) else 0 end ,
			S_PERED = 0,
			S_VOZV = 0,
			S_ZACH = 0
		from #ALL_NALOG_Y 
			where PER_STAV = '30%'	
		
			UPDATE #ALL_NALOG_Y 
			SET DOLG_NP = S_NN - S_NU,  
				DOLG_NA = 0
			from #ALL_NALOG_Y 
				where PER_STAV = '30%'	
			
			UPDATE #ALL_NALOG_Y 
				SET DOLG_NA = -DOLG_NP,
					DOLG_NP = 0
			from #ALL_NALOG_Y 
				where PER_STAV = '30%'	
				and DOLG_NP <0		
	end
	---
		
	insert into #ALL_NALOG_Y
	SELECT		
		PER_STAV = '35%',
		S_NN = 0  ,
		S_NU = 0 ,
		S_PERECH = 0 , 
		S_PERED = 0, 
		S_VOZV = 0, 
		S_ZACH = 0, 
		DOLG_NP = 0,
		DOLG_NA = 0	
	
	UPDATE #ALL_NALOG_Y 
		set	S_NN = (SELECT TOP 1 SNN FROM #NALOG_RASH where mode = 5),
			S_NU = (SELECT TOP 1 SNU FROM #NALOG_RASH where mode = 5),
			S_PERECH = case when isnull((select top 1  s_jan from #NALOG_RASH where mode = 5),0) > 0 then (SELECT TOP 1 S_DEC FROM #Dohod_35_i where mode = 8) else 0 end 
		from #ALL_NALOG_Y 
		where PER_STAV = '35%'
		
	UPDATE #ALL_NALOG_Y 
		SET DOLG_NP = S_NN - S_NU, DOLG_NA = 0
		from #ALL_NALOG_Y where PER_STAV = '35%'	
			
	UPDATE #ALL_NALOG_Y 
		SET DOLG_NA = -DOLG_NP, DOLG_NP = 0
		from #ALL_NALOG_Y where PER_STAV = '35%' and DOLG_NP <0		
	
-------------------------------------------------------	

	
--print '1. Налоговый агент и Налогоплательщик'
	---
	SELECT  d.*, CAST(  (CAST (d.DOCCOUNT AS INT) - @varKSCNT) AS VARCHAR(254) ) AS DOCCOUNT2 , r.* FROM #DEP d , #PERSON R  
	---

--print 'Дети'	
--print '3.  Стандартный налоговый вычет'	
	declare @count1 int,
			@count2 int
	set @count1 = 0			
 
	SELECT * FROM #RES_VICHET

	
--print 'Имущественный налоговый вычет'	
	set @count1 = 0			
	set @count1 = (SELECT count(*)	FROM #RES_IM_VICHET)		
	
	if 	@count1 < 1
	begin 
		insert into #RES_IM_VICHET
		select distinct	
			 null,null,null,' ',null,' ',' ',null,null,null,null,0,null,null
	end 
	select * from #RES_IM_VICHET
		order by code_ded

--print '4. Необлагаемые доходы'
	set @count1 = 0			
	set @count1 = (SELECT count(*)	FROM #RES_NE_VICHET)		
	
	if 	@count1 < 1
	begin 
		insert into #RES_NE_VICHET
		select distinct	
			 '',null,null,null,null,0,0,0,0,0,0,0,0,0,0,0,0 
	end 
	select * from #RES_NE_VICHET
					
	--select * from #RES_NonNDFL_VICHET
--print '5. Налоговые ставки'	
	
--print 'и Таблица 5.2 Виды доходов (доходы не по ставке 13%)'
	--select * from #RES_EMP_STATUS
	
	set @count1 = (select count(*) from #RES_EMP_STATUS )
	set @count2 = (select count(*) from #vid_dohod_not13 ) 

	if @count1 > 0 and @count1 >= @count2 
	begin
		update #RES_EMP_STATUS 
		set month_d = v.month_d, 
	   		year_d = v.year_d,
	   		link_inc = v.link_inc,
	   		link_dep = v.link_dep,
	   		sname = v.sname,
	   		name = v.name,
	   		flag = v.flag,
	   		perc_stav = v.perc_stav
		 from #RES_EMP_STATUS r, #vid_dohod_not13 v 
		 where v.year_d = @cYear	
	end  
	else	
		begin
			insert into #RES_EMP_STATUS 
			select distinct	
			   null, 
			   null,
			   null, 
			   null,
			   NULL,
			   [month_d] = v.month_d, 
	   		   [year_d] = v.year_d,
	   		   [link_inc] = v.link_inc,
	   		   [link_dep] = v.link_dep,
	   		   [sname] = v.sname,
	   		   [name] = v.name,
	   		   [flag] = v.flag,
	   		   [perc_stav] = v.perc_stav
			FROM 
				#vid_dohod_not13 v
	  end	

	select * from #RES_EMP_STATUS 


	--select * from  #vid_dohod_not13
	
--print '6.предыдущее место работы'	
	declare @countPrevInfo int
	set @countPrevInfo = 0
	set @countPrevInfo = (SELECT count(*)	FROM #DEP_Prev)
	
	if 	@countPrevInfo < 1
	begin 
		insert into #DEP_Prev
		select distinct	
			[LINK_DEP] = null,[NALOG] = ' ',[INN] = ' ',[KPP] = ' ',[OKATO] = ' ',[OKTMO] = ' ',[FULL_NAME] = ' ',[ADDRES] = ' ',[SUMMA_13]= 0
	end 
	SELECT * FROM #DEP_Prev
		
	
--print ' Сумма доходов, облагаемых по ставке 13% '	
	--set @count1 = 0
	--set @count1 = (SELECT count(*)	FROM #Prev_dohod)
	
	--if 	@count1 < 1
	--begin 
	--	insert into #Prev_dohod
	--	select distinct	
	--		[LINK_EMPL] = 1,
	--		[REF_TYP_INCOMS] = 0, 
	--		[COD_INC] = '.',
	--		[NAME_INC] = '.',
	--	    [SUMM_INC] = 0
	--end 
	--select * from #Prev_dohod	

--print ' Сумма необлагаемых доходов по ставке 13% '	
	set @count1 = 0
	if	@countPrevInfo < 1
	begin 
		delete from #Prev_dohod_NO
	end	
	
	set @count1 = (SELECT count(*)	FROM #Prev_dohod_NO)

	if 	@count1 < 1 
	begin 
		insert into #Prev_dohod_NO
		select distinct	
			[LINK_EMPL] = 0,[REF_TYP_INCOMS] = ' ',	[COD_INC] = ' ',[NAME_INC] = ' ', [SUMM_INC] = 0, [PER_YEAR] = ' '
	end 
	select * from #Prev_dohod_NO	
	
--print 'Налоговые вычеты с предыдущего места работы по типам'
	set @count1 = 0

	if	@countPrevInfo < 1
	begin 
		delete from #Prev_ded
	end	
	
	set @count1 = (SELECT count(*)	FROM #Prev_ded)
	
	if 	@count1 < 1 or 	@countPrevInfo < 1
	begin 
		insert into #Prev_ded
		select distinct	
			[LINK_EMPL] = 0,[LINK_DED] = 0,[CODE_DED] = ' ',[NAME_DED] = ' ',[SUMM_DED] = 0,[TYPE] = null,[PER_YEAR] = null
	end 	
	select * from #Prev_ded
--print '7. доходы облагаемые по ставке 13%'  	
--	select * from #Dohod_13	
	set @count1 = 0
	set @count1 = (SELECT count(*)	FROM #Dohod_13_1)
	
	if 	@count1 < 1
	begin 
		insert into #Dohod_13_1
		select 
			null,' ',' ',null,null,null,0,null,null,0,null,null,0,null,null,0,null,null,0,null,null,0,
			null,null,0,null,null,0,null,null,0,null,null,0,null,null,0,null,null,0																							
	end 	
	select * from #Dohod_13_1
--print ' Итого 13% месяц и год '
	select * from #Dohod_13_i
--print '8. необлагаемые суммы налогов'  
	set @count1 = 0
	set @count1 = (SELECT count(*)	FROM #Dohod_13_predel)
	if 	@count1 < 1
	begin 
		insert into #Dohod_13_predel
		select
			null, 
			null, 
			null, 
			0,
			0,
            0,          
            0,    
			0,        
            0,          
            0,          
            0,        
            0,      
            0,         
            0,         
            0,          
            0	
    end  
	select * from #Dohod_13_predel
--print ' Итого месяц и год'	
	select * from #Dohod_13_predel_i
--print '9. Сумма облагаемых доходов (месяц и год)'
	select * from #Obl_Dohod_i
--print '10. Вычеты фактически предоставленные , стандартные, имущестевнные, проффессиональные'
	set @count1 = 0
	set @count1 = (SELECT count(*)	FROM #DED_FACT)
	if 	@count1 < 1
	begin 
		insert into #DED_FACT
		select
			null, 
			null, 
			null, 
			null,
			null,
            null,          
            null,         
       null,        
            0,          
            null,          
            null,        
            0,      
            null,         
            null,         
            0,          
            null,	
            null,        
            0,      
            null,         
            null,         
            0,          
            null,
            null,        
            0,      
            null,         
            null,         
            0,          
            null,
            null,        
            0,      
            null,         
            null,         
            0,          
            null,
            null,        
            0,      
            null,         
            null,         
            0,          
    null,
            null,         
            0,       
            null
    end  
	select * from #DED_FACT 
--	select * from #DED_FACT_i
--	select * from #OBL_base_fi
		-- итоги по месяцам и за год 
		--	 mode = 1 и mode = 2
		
--print '11.Облагаемая база ставка 13% ' 	
		-- итоги по месяцам и за год 
		--	 mode = 3 и mode = 4
--print '12.НДФЛ по ставке 13% 	--сумма начисленного налого С НАЧАЛА ГОДА , за месяц'
		-- за месяц и год по начисленным 	 mode = 5 и mode = 6
		-- за месяц и год по удержанным 	 mode = 7 и mode = 8
		select * from #NDFL_13_i  order by mode

--print '13. Перечисление НДФЛ по ставке 13% --сумма перечисленного налога С НАЧАЛА ГОДА , за месяц'



--print '15.ДОходы, облагаемая база со ставкой  35%'
	set @count1 = 0
	set @count1 = (SELECT count(*)	FROM #Dohod_35)
	
	if 	@count1 < 1
	begin 
		insert into #Dohod_35_m
		select 
		   [link_empl] = 1,  
		   [name]  = ' ', 
		   [sname] = ' ', 
		   [link_inc] = null,	
		   [NUM1] = null,
		   [summa_1] = null,
		   [d1] = null,
		   [num2] = null,
		   [summa_2] = null,
		   [d2] = null,
		   [num3] = null,
		   [summa_3] = null,
		   [d3] = null,
		   [num4] = null,
		   [summa_4] = null,
		   [d4] = null,
		   [num5]= null,
		   [summa_5] = null,
		   [d5] = null,
		   [num6]= null,
		   [summa_6] = null,
		   [d6] = null,
		   [num7]= null,
		   [summa_7]  = null,
		   [d7] = null,
		   [num8]= null,
		   [summa_8]  = null,
		   [d8]  = null,
		   [num9]= null,
		   [summa_9] = null,
		   [d9] = null,
		   [num10]= null,
		   [summa_10] = null,
		   [d10] = null,
		   [num11]= null,
		   [summa_11] = null,
		   [d11] = null,
		   [num12]= null,
		   [summa_12] = null ,
		   [d12] = null 
		    
	end		   
---	select * from #Dohod_35
	select * from #Dohod_35_m
--print 'Итого за месяц'	
--print '16.НДФЛ по ставке 13 %'
	select * from #Dohod_35_i
--print '17.Расчеты по налогу  и 20. общая сумма по итогам налогового периода '	
	select * from #NALOG_RASH	
	select * from #ALL_NALOG_Y

	---	

	---
	EXEC dbo.BufferClear

	DROP TABLE #E_SUBDIV
	DROP TABLE #S_OBOSOB
	DROP TABLE #P_OBOSOB	
	DROP TABLE #PERSON
	DROP TABLE #RES_VICHET
--	DROP TABLE #RES_CHILD_VICHET
	DROP TABLE #RES_IM_VICHET
	DROP TABLE #RES_NE_VICHET
	--DROP TABLE #RES_NonNDFL_VICHET
	DROP TABLE #RES_EMP_STATUS
	drop table #vid_dohod_not13
	DROP TABLE #DEP_Prev
	DROP TABLE #Prev_dohod	
	DROP TABLE #Prev_dohod_NO
	DROP TABLE #Prev_ded
	DROP TABLE #Dohod_13
	DROP TABLE #Dohod_13_1
	drop table #Dohod_13_predel
	drop table #Dohod_13_i
	drop table #Dohod_13_predel_i
	drop table #Obl_Dohod_i
	drop table #DED_FACT 
--	drop table #DED_FACT_i
--	drop table #OBL_base_fi

	drop table #NDFL_13_i

	drop table #Dohod_35
	drop table #Dohod_35_m
	drop table #Dohod_35_i

	drop table #MONTHES
	drop table #NALOG_RASH	
	drop table #ALL_NALOG_Y	


END






GO


GRANT EXECUTE ON dbo.[SS_REP_CARD_NDFL] TO PUBLIC

GO




GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_PRINTDOC_AVANSE_REP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_PRINTDOC_AVANSE_REP]
GO

-- Печать авансового отчета --
CREATE PROCEDURE dbo.BK_PRINTDOC_AVANSE_REP
	@intLINK_DOC	INT
AS
BEGIN
	DECLARE
		@intPrintKBK TINYINT,
		@intPrintSGU TINYINT

	-- Титульный лист --
	DECLARE @TAB_TITLE TABLE 
		(
		LINK		INT,
		DOC_NUM		VARCHAR (60),
		DOC_DATE	DATETIME,
		WHY_AVA		VARCHAR (254),
		KA_CODE		VARCHAR (30),

		GET_SUM		NUMERIC (28,2),
		PREV_SUM1	NUMERIC (28,2),
		PREV_SUM2	NUMERIC (28,2),
		TOT_SUM		NUMERIC (28,2),
		REST_SUM	NUMERIC (28,2),
		OUT_SUM		NUMERIC (28,2),

		CNT_DOC		NUMERIC (5),
		CNT_SHEET	NUMERIC (5),
	
		EMP_CODE	VARCHAR (30),
		EMP_NAME	VARCHAR (254),
		EMPL_SIGN	VARCHAR (254),
		SUB_NAME	VARCHAR (254),
		POST_NAME	VARCHAR (254),
		EMP_FIO		VARCHAR (254),
		
		DEP_OKPO	VARCHAR (30),
		DEP_NAME	VARCHAR (254),
		GET_DATE	DATETIME,
		GET_DOC		VARCHAR (1000)
		)

	DECLARE @T_GET_DOC	TABLE 
		(
		DOC_LINK	INT,
		DOC_DATE	DATETIME,
		DOC_NUM		VARCHAR (60),
		DOC_INFO	VARCHAR (254),
		DOC_SUM		NUMERIC (28,4)
		)

	INSERT @T_GET_DOC
		(
		DOC_LINK,
		DOC_DATE,
		DOC_NUM,
		DOC_INFO,
		DOC_SUM	
		)
	SELECT 
		T1.LINK_UP,
		G.[DATE],
		G.NUMBER,
		dbo.GetDocumentName (G.LINK, G.[OBJECT])
			+ ' № ' + RTRIM (G.NUMBER)
			+ ' от ' + CONVERT (VARCHAR (10), G.[DATE], 104),
		G.SUMMA	
	FROM (
		SELECT
			TTT.LINK_UP,
			TTT.OSNOV
		FROM dbo.DOC_AO_RKO_TABLE TTT
		GROUP BY
			TTT.LINK_UP,
			TTT.OSNOV
			) AS T1
	INNER JOIN dbo.OSNOV O1 ON (O1.LINK = T1.OSNOV)
	INNER JOIN dbo.G_PROV G ON (G.LINK = O1.LINK_G_PROV)
	WHERE T1.LINK_UP = @intLINK_DOC
--		AND (SELECT COUNT (DISTINCT T2.LINK_UP) FROM dbo.DOC_AO_RKO_TABLE T2 WHERE T2.LINK_UP = T1.LINK_UP) = 1

	INSERT INTO @TAB_TITLE
	SELECT
		DOC.LINK,
		DOC.NUMBER,
		DOC.[DATE],
		ISNULL (DOC.[TARGET], ''),
		ISNULL (DOC.KTACCOUNT, ''),
		
		ISNULL (DOC.AVANSESUMMA, 0),
		CASE
			WHEN ISNULL (DOC.PREVSUMMA, 0) >= 0 THEN ISNULL (DOC.PREVSUMMA, 0)
			ELSE 0.00
		END,
		CASE	
			WHEN ISNULL (DOC.PREVSUMMA, 0) < 0 THEN ABS (ISNULL (DOC.PREVSUMMA, 0))
			ELSE 0.00
		END,
		ISNULL (DOC.ITOG_SUM, 0.00),
		ISNULL (DOC.REST_SUM, 0.00),
		ISNULL (DOC.RASHOD_SUM, 0.00),

		ISNULL (DOC.DOC, 0.00),
		ISNULL (DOC.PAGES, 0.00),

		DOC.EMP_CODE,
		DOC.EMP_NAME,
		CASE
			WHEN DOC.[OPTION] = 1 THEN dbo.BK_Get_EMPL_Signature (DOC.EMP_LINK, DEFAULT)
			WHEN DOC.[OPTION] = 2 THEN dbo.BK_Get_PERSON_Signature (DOC.EMP_LINK, DEFAULT)
		END,
		CASE
			WHEN DOC.[OPTION] = 1 THEN EMP.SUBDIV_NAME
			WHEN DOC.[OPTION] = 2 THEN ''
		END,	
		CASE
			WHEN DOC.[OPTION] = 1 THEN EMP.POST_NAME
			WHEN DOC.[OPTION] = 2 THEN ''
		END,
		CASE
			WHEN DOC.[OPTION] = 1 THEN EMP.FIO
			WHEN DOC.[OPTION] = 2 THEN LTRIM (RTRIM (PERS.FM)) + SPACE (1) + LTRIM (RTRIM (PERS.IM)) + SPACE (1) + LTRIM (RTRIM (PERS.OT))
		END,
		DEP.OKPO,
		dbo.BK_GET_PRINT_DEP_NAME (DEP.LINK),
--		TGD.DOC_DATE,
--		ISNULL (TGD.DOC_INFO, '')
		NULL, 
		SUBSTRING ((SELECT
						', ' + ISNULL (TGD.DOC_INFO, '')
					FROM @T_GET_DOC TGD
					WHERE TGD.DOC_LINK = DOC.LINK
					FOR XML PATH ('')),
					3,
					1000)
	FROM dbo.BV_DOC_AVANSE_REP DOC
	INNER JOIN dbo.DEPARTMENTS DEP ON (DEP.LINK = DOC.DEP_LINK)
	LEFT JOIN dbo.KU_EMPL_PLACING EMP ON (DOC.[OPTION] = 1
		AND EMP.LINK = DOC.EMP_LINK)
	LEFT JOIN dbo.PERSON PERS ON (DOC.[OPTION] = 2
		AND PERS.LINK = DOC.EMP_LINK)
--	LEFT JOIN @T_GET_DOC TGD ON (TGD.DOC_LINK = DOC.LINK)	
	WHERE DOC.LINK = @intLINK_DOC

-- SELECT '@T_GET_DOC', * FROM @T_GET_DOC

	-- КО на перерасход\возврат --
	SELECT
		@intPrintKBK = PRN_KBK,
		@intPrintSGU = PRN_SGU
	FROM dbo.BK_GET_PRINT_NASTRDOC ('BV_DOC_AVANSE_REP')

	DECLARE @TAB_KO1 TABLE
		(	
		LINK_AO	INT,
		KO_NUM	VARCHAR (30),
		KO_DATE VARCHAR (10), 
		ACCT_CODE	VARCHAR (60),
		ACCT_GR	VARCHAR (20),
		PKO_SUM	NUMERIC (28,4),
		RKO_SUM NUMERIC (28,4)
		)

	INSERT INTO @TAB_KO1		
	SELECT
		T1.G_PRIMARY,
		T1.NUMBER,
		CONVERT (VARCHAR (10), T1.[DATE], 104),
		dbo.BK_GetAcctFullCode1 (GAP.ACCOUNT, GAP.KBK, GAP.SGU,
			@intPrintKBK, @intPrintSGU),
		SA.CODE,
		CASE
			WHEN T1.DOC_CODE = 'DOCUMENTS_PKO' THEN G2.SUMMA  ELSE 0 
		END,
		CASE
			WHEN T1.DOC_CODE = 'DOCUMENTS_RKO' THEN G2.SUMMA  ELSE 0 
		END
	FROM dbo.XK_GetTable_Doc_FOREIGN (@intLINK_DOC) T1
	INNER JOIN dbo.G_PROV1 G1 ON (G1.LINK_UP = T1.LINK)
	INNER JOIN dbo.G_PROV2 G2 ON (G2.LINK_UP = G1.LINK)
	INNER JOIN dbo.G_PROV_AP GAP ON (GAP.LINK_UP = G2.LINK)
	INNER JOIN dbo.S_ACCOUNTS SA ON (SA.LINK = GAP.ACCOUNT
			AND SA.cSINTH = '208')
	WHERE T1.DOC_CODE IN ('DOCUMENTS_PKO', 'DOCUMENTS_RKO')

	--- Проводки АО (на титульную страницу) ---
	DECLARE @TAB_TITLE_PROV TABLE
			(
			DB_ACCT	VARCHAR (60),
			KR_ACCT	VARCHAR (60),
			SUM_PROV NUMERIC (28,2)
			)
			
	IF EXISTS (SELECT * FROM dbo.BV_DOC_AO_OPTIONS WHERE ISNULL (TITLE_PROV, 0) = 1)
		-- Проводки из документов на выдачу аванса --
		INSERT INTO @TAB_TITLE_PROV		
		SELECT
			ISNULL (dbo.BK_GetAcctFullCode1 (GAP_D.ACCOUNT, GAP_D.KBK, GAP_D.SGU,
						@intPrintKBK, @intPrintSGU), ''),
			ISNULL (dbo.BK_GetAcctFullCode1 (GAP_K.ACCOUNT, GAP_K.KBK, GAP_K.SGU,
						@intPrintKBK, @intPrintSGU), ''),
			ISNULL (G2.SUMMA, 0)
		FROM dbo.DOC_AO_RKO_TABLE T1
		INNER JOIN dbo.OSNOV OSNOV ON (OSNOV.LINK = T1.OSNOV)
		INNER JOIN dbo.G_PROV G ON (G.LINK = OSNOV.LINK_G_PROV)
		INNER JOIN dbo.G_PROV1 G1 ON (G1.LINK_UP = G.LINK)
		INNER JOIN dbo.G_PROV2 G2 ON (G2.LINK_UP = G1.LINK)
		LEFT JOIN dbo.G_PROV_AP GAP_D ON (GAP_D.LINK_UP = G2.LINK
			AND GAP_D.DB_KR = 0)
		LEFT JOIN dbo.G_PROV_AP GAP_K ON (GAP_K.LINK_UP = G2.LINK
			AND GAP_K.DB_KR = 1)
		WHERE T1.LINK_UP = @intLINK_DOC
	ELSE
		-- Проводки из авансового отчета --
		INSERT INTO @TAB_TITLE_PROV		
		SELECT
			ISNULL (ACCT_CD_D, ''),
			ISNULL (ACCT_CD_K, ''),
			ISNULL (SUMMA, 0)
		FROM dbo.BK_PrintDocProv (@intLINK_DOC, DEFAULT)

	SELECT
		*,
		(SELECT
			SUM (SUM_PROV)
		FROM @TAB_TITLE_PROV) AS SUM_PROV0
	FROM @TAB_TITLE

	SELECT
		T1.EMP_NAME, 
		T1.DOC_NUM AS DOC_NUM,
		CONVERT (VARCHAR (10), T1.DOC_DATE, 104) AS DOC_DATE, 
		T1.CNT_DOC AS CNT_DOC, 
		ISNULL (T1.OUT_SUM, 0.00) AS OUT_SUM,
		ISNULL (T2.ACCT_CODE, '') AS ACCT_KO, 
		ISNULL (T2.PKO_SUM, 0.00) AS PKO_SUM, 
		ISNULL (T2.RKO_SUM, 0.00) AS RKO_SUM, 
		ISNULL (T2.KO_NUM, '') AS KO_NUM, 
		ISNULL (T2.KO_DATE, '') AS KO_DATE, 
		0 AS T0
	FROM @TAB_TITLE T1 
	LEFT OUTER JOIN @TAB_KO1 T2 ON (T2.LINK_AO = T1.LINK) 
	WHERE T1.LINK = @intLINK_DOC 

	SELECT
		DB_ACCT,
		KR_ACCT,
		SUM (SUM_PROV) AS SUM_PROV
	FROM @TAB_TITLE_PROV
	GROUP BY
		DB_ACCT,
		KR_ACCT

	--- Оборотная сторона ---
	SELECT 
		ISNULL (T1.NUMBER, 0) AS NUM_POS,
		ISNULL (CONVERT (VARCHAR (10), (T1.DATEDOC), 104), '') AS D_DATE,
		ISNULL (T1.NUMDOC, '') AS D_NUM,
		ISNULL (T1.NAMEDOC, '') AS D_NAME,
		ISNULL (T1.SUMREPORT, 0.00) AS SUMMA1,
		ISNULL (T1.SUMACCEPTED, 0.00) AS SUMMA2,
		COALESCE (T3.ACCT_CD_D, T1.DTACCOUNT, '') AS D_ACCT,
		COALESCE (T3.ACCT_CD_K, T1.KTACCOUNT, '') AS K_ACCT,
		T2.EMP_NAME AS E_NAME, 
		T2.EMPL_SIGN AS E_SIGN,
		CASE
			WHEN T2.REST_SUM > 0 THEN T2.REST_SUM
			ELSE 0.00
		END	 AS REST_D,
		CASE
			WHEN T2.REST_SUM < 0 THEN ABS (T2.REST_SUM)
			ELSE 0.00
		END AS REST_K 
	FROM dbo.BK_DOC_TABLE_AO_FN (@intLINK_DOC) T1
	INNER JOIN @TAB_TITLE T2 ON (T2.LINK = T1.LINK_UP)
	LEFT JOIN dbo.BK_PrintDocProv (@intLINK_DOC, DEFAULT) T3 ON (T3.LINK_G1 = T1.LINK_OPER)

	-- Документы на выдачу --
	SELECT *
	FROM @T_GET_DOC
	ORDER BY 
		DOC_INFO

END

GO

GRANT EXECUTE ON dbo.[BK_PRINTDOC_AVANSE_REP] TO PUBLIC

GO

--Расширенные свойства--

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[XK_NASTR_S_ACCOUNTS_KOSGU]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[XK_NASTR_S_ACCOUNTS_KOSGU]

GO
-- Установка настроек плана счетов на КОСГУ --
CREATE PROCEDURE dbo.XK_NASTR_S_ACCOUNTS_KOSGU
	(
	@intLINK_ACCT	INT = NULL,
	@BUF_NAME	VARCHAR (100) = '',
	@iTYPE_REC		TINYINT = 0,
	@intDEP_LINK	INT = NULL
	)

AS
BEGIN
	SET @BUF_NAME = ISNULL (@BUF_NAME, '')
	

	UPDATE SA_SGU
	SET
		COMMENT = CONVERT (VARCHAR (254), LTRIM (SA_SGU_NASTR.[NAME]))
	FROM dbo.S_ACCOUNTS_SGU SA_SGU
	INNER JOIN dbo.S_ACCOUNTS SA ON	(SA.LINK = SA_SGU.ACCOUNT)
	INNER JOIN dbo.KOSGU ON (KOSGU.LINK = SA_SGU.LINK_SGU)
	INNER JOIN dbo.S_ACCOUNTS_NASTR_KOSGU SA_SGU_NASTR ON
		(
		SA_SGU_NASTR.SINTH = SA.cSINTH
		AND SA_SGU_NASTR.ANALITH = SA.cANALIT
		AND SA_SGU_NASTR.SGU = KOSGU.CODE
		)
	LEFT JOIN dbo.S_ACCOUNTS_NEW_CONV BUF ON (BUF.BUF_NAME = @BUF_NAME
		AND BUF.SINTH_NEW = SA_SGU_NASTR.SINTH
		AND BUF.ANALITH_NEW = SA_SGU_NASTR.ANALITH
		)
	WHERE
		(@intLINK_ACCT IS NULL AND @BUF_NAME = ''
		OR @intLINK_ACCT IS NOT NULL AND SA_SGU.ACCOUNT = @intLINK_ACCT AND @BUF_NAME = ''
		OR @intLINK_ACCT IS NULL AND @BUF_NAME <> '' AND BUF.BUF_NAME = @BUF_NAME)
		AND BUF.TYPE_ACCT = @iTYPE_REC

	INSERT INTO dbo.S_ACCOUNTS_SGU 
		(
		ACCOUNT,
		LINK_SGU,
		COMMENT
		)
	SELECT
		SA.LINK,
		KOSGU.LINK,
		SA_SGU_NASTR.[NAME]
	FROM dbo.S_ACCOUNTS_NASTR_KOSGU SA_SGU_NASTR 
	INNER JOIN
		(
		SELECT '1' AS CODE UNION ALL SELECT '2' 
		UNION ALL 
		SELECT '3' UNION ALL SELECT '4' 
		) AS T111 ON (SA_SGU_NASTR.SINTH LIKE '50%' OR T111.CODE = '1')
	INNER JOIN dbo.S_ACCOUNTS SA ON
		(
		SA.cSINTH = SA_SGU_NASTR.SINTH
		AND (
			SA_SGU_NASTR.SINTH LIKE '50%' AND SA_SGU_NASTR.ANALITH <> '' AND SA_SGU_NASTR.ANALITH <> '00'
			AND SA.cANALIT = (T111.CODE + RIGHT (SA_SGU_NASTR.ANALITH, 1))
			OR SA.cANALIT = SA_SGU_NASTR.ANALITH
			)
		)
	INNER JOIN dbo.KOSGU ON (KOSGU.CODE = SA_SGU_NASTR.SGU)
	LEFT JOIN dbo.S_ACCOUNTS_NEW_CONV BUF ON (BUF.BUF_NAME = @BUF_NAME
		AND BUF.SINTH_NEW = SA_SGU_NASTR.SINTH
		AND BUF.ANALITH_NEW = SA_SGU_NASTR.ANALITH
		)
	LEFT MERGE JOIN dbo.S_ACCOUNTS_SGU SA_SGU1 ON
		(
		SA_SGU1.ACCOUNT = SA.LINK
		AND SA_SGU1.LINK_SGU = KOSGU.LINK
		)
	WHERE
		(@intLINK_ACCT IS NULL AND @BUF_NAME = ''
		OR @intLINK_ACCT IS NOT NULL AND SA.LINK = @intLINK_ACCT AND @BUF_NAME = ''
		OR @intLINK_ACCT IS NULL AND @BUF_NAME <> '' AND BUF.BUF_NAME = @BUF_NAME)
		AND BUF.TYPE_ACCT = @iTYPE_REC
		AND SA_SGU1.ACCOUNT IS NULL
		AND SA_SGU1.LINK_SGU IS NULL

	RETURN 0
END



GO


GRANT EXECUTE ON dbo.[XK_NASTR_S_ACCOUNTS_KOSGU] TO PUBLIC

GO


--Расширенные свойства--


GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BB_DOLG_KNIGA]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[BB_DOLG_KNIGA]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


/*
c Кейсистемс (Keysystems), 2005
*/

create  procedure dbo.BB_DOLG_KNIGA
	@dDateB 	datetime,
	@dDateE 	datetime

as
declare @iOwnDep	int,
		@dDateRest  datetime
	
declare @tRest table(DOC int,
		      		SUMMA numeric(28,2),
					[TYPE]	tinyint)

declare @tOborot table(	DOC int,
						[DATE] datetime,
						SUM_PER numeric(28,2),
						SUM_UPL numeric(28,2),
						PROC_N numeric(28,2),
						PROC_P numeric(28,2))

declare @tDoc table(LINK_AP1 int,
					LINK_G int,
					INFO varchar(1000),
		      		KDEP_NAME varchar(1000),
		      		SUMMA numeric(28,2),
					[TYPE_NAME]	varchar(1000),
					DATE_BEG datetime,
					DATE_END datetime,
					[PROC] numeric(10,4),
					[TYPE]	tinyint)
		
set @iOwnDep = isnull (dbo.BK_GetDepZB (), dbo.GetOwnDepLink())

exec dbo.BufferClear 'CREDIT_ACC'
exec dbo.BufferClear 'CREDIT_PER_D'
exec dbo.BufferClear 'CREDIT_PL_N'
exec dbo.BufferClear 'CREDIT_DOH_N'
exec dbo.BufferClear 'OSNOV'
exec dbo.BufferClear 'SGU_D'
exec dbo.BufferClear 'SGU_K'
exec dbo.BufferClear 'SGU_K_P'
exec dbo.BufferClear 'SGU_K_KL_N'
exec dbo.BufferClear 'CREDIT_ACC_11'

insert into BUFFER (link, id)
select link, 'CREDIT_ACC' from s_accounts where code like '%301.1[1,2,3]'

insert into BUFFER (link, id)
select link, 'CREDIT_PER' from s_accounts where code like '%210.02%' or code like '%201.07%' or code like '%201.11%' or code like '%401.30%'

insert into BUFFER (link, id)
select link, 'CREDIT_PL' from s_accounts where code like '%304.05%' or code like '%201.07%' or code like '%201.11%'

insert into BUFFER (link, id)
select link, 'CREDIT_PL_N' from s_accounts where code like '%401.[1-2]0%'

insert into BUFFER (link, id)
select link, 'SGU_D' from dbo.KOSGU where CODE like '8%'

insert into BUFFER (link, id)
select link, 'SGU_K' from dbo.KOSGU where CODE like '7%'

insert into BUFFER (link, id)
select link, 'SGU_K_P' from dbo.KOSGU where CODE like '23%'

insert into BUFFER (link, id)
select link, 'SGU_K_PL_N' from dbo.KOSGU where CODE like '171'

insert into BUFFER (link, id)
select link, 'CREDIT_ACC_11' from s_accounts where code = '11'

--insert into @tDoc 
--select * from (
--	select  O.LINK,
--			O.DOC_LINK,
--			O.INFO, 
--			C.KDEP_NAME,
--			C.SUMMA,
--			C.[TYPE_NAME],
--			--C.DATE_BEG,
--			C.DATE,
--			C.DATE_END,
--			[PROC] = dbo.BB_CREDIT_PROC(C.LINK, @dDateE,'PROC',0),
--			[TYPE] = case when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.11' where GAP.AP1 = O.LINK) then 1
--							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.12' where GAP.AP1 = O.LINK) then 2
--							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.13' where GAP.AP1 = O.LINK) then 3
--							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '11' where GAP.AP1 = O.LINK) then 4
--					 else 0 end
--	from dbo.BD_OSNOV O
--	inner join dbo.BB_P_CREDIT C on C.LINK = O.DOC_LINK
--	where C.DEP_LINK = @iOwnDep and C.DATE_BEG <= @dDateE and C.DATE_END >= @dDateB) A
--where [TYPE] <> 0


insert into @tOborot
select isnull(S.KT_AP1, S.DT_AP1), S.DATE_PROV, sum(S.SUMMA), 0, 0, 0
from dbo.AProvByBufferConditions(@dDateB, @dDateE, 'CREDIT_PER', 'CREDIT_ACC',
			 null,null,null,null,null,null,null,null,null,null,null,null,null, null,null,
			 null,null,null,null,null,null,null,null,null,null,'SGU_K',null, null, null,null) S
where S.SUMMA <> 0
group by isnull(S.KT_AP1, S.DT_AP1), S.DATE_PROV, S.KT_ACCOUNT

insert into @tOborot
select isnull(S.DT_AP1, S.KT_AP1), S.DATE_PROV, 0, sum(S.SUMMA), 0, 0
from dbo.AProvByBufferConditions(@dDateB, @dDateE, 'CREDIT_ACC', 'CREDIT_PL',
			 null,null,null,null,null,null,null,null,null,null,'SGU_D',null, null, null,null,
			 null,null,null,null,null,null,null,null,null,null,'SGU_D',null,null, null,null) S
where S.SUMMA <> 0
group by isnull(S.DT_AP1, S.KT_AP1), S.DATE_PROV, DT_ACCOUNT

insert into @tOborot
select isnull(S.KT_AP1, S.DT_AP1), S.DATE_PROV, 0, 0, sum(S.SUMMA), 0
from dbo.AProvByBufferConditions(@dDateB, @dDateE, 'CREDIT_PL_N', 'CREDIT_ACC',
				 null,null,null,null,null,null,null,null,null,null,'SGU_K_P',null,null, null,null,
				 null,null,null,null,null,null,null,null,null,null,'SGU_K',null, null, null,null) S
where S.SUMMA <> 0
group by isnull(S.KT_AP1, S.DT_AP1), S.DATE_PROV, S.KT_ACCOUNT

insert into @tOborot
select isnull(S.DT_AP1, S.KT_AP1), S.DATE_PROV, 0, 0, 0, sum(S.SUMMA)
from dbo.AProvByBufferConditions(@dDateB, @dDateE, 'CREDIT_ACC', 'CREDIT_PL',
				 null,null,null,null,null,null,null,null,null,null,'SGU_D',null, null, null,null,
				 null,null,null,null,null,null,null,null,null,null,'SGU_K_P',null,null, null,null) S
where S.SUMMA <> 0
group by isnull(S.DT_AP1, S.KT_AP1), S.DATE_PROV, DT_ACCOUNT


insert into @tOborot
select GAP.AP1, G.DATE_PROV, CASE GAP.DB_KR when 0 THEN sum(G2.SUMMA) ELSE 0 END, CASE GAP.DB_KR when 1 THEN sum(G2.SUMMA) ELSE 0 END, 0, 0
from dbo.G_PROV G
INNER JOIN dbo.G_PROV1 G1 ON (G1.LINK_UP = G.LINK)
INNER JOIN dbo.G_PROV2 G2 ON (G2.LINK_UP = G1.LINK)
INNER JOIN dbo.G_PROV_AP GAP ON (GAP.LINK_UP = G2.LINK)
INNER JOIN S_ACCOUNTS SA ON (GAP.ACCOUNT = SA.LINK)
where G.DATE_PROV BETWEEN @dDateB AND @dDateE
		AND G.LINK = G1.LINK_UP
		and G2.SUMMA <> 0
		AND sa.CODE = '11'
group by GAP.AP1, G.DATE_PROV, GAP.DB_KR

insert into @tRest
select R.AP1, sum(R.K_SUMMA - R.D_SUMMA), case KBK.TYPE when 1 then 1 else 0 end
from dbo.aRestTableByDateAccounts(@dDateB,'CREDIT_ACC') R
inner join dbo.KL_KBK KBK on R.KBK = KBK.LINK and KBK.TYPE <> 2
group by R.AP1, KBK.TYPE, ACCOUNT

set @dDateE = @dDateE + 1
insert into @tRest
select R.AP1, sum(R.K_SUMMA - R.D_SUMMA), 2 + case KBK.TYPE when 1 then 1 else 0 end 
from dbo.aRestTableByDateAccounts(@dDateE,'CREDIT_ACC') R
inner join dbo.KL_KBK KBK on R.KBK = KBK.LINK and KBK.TYPE <> 2
group by R.AP1, KBK.TYPE, ACCOUNT

insert into @tRest
select R.AP1, sum(R.D_SUMMA - R.K_SUMMA), 0
from dbo.aRestTableByDateAccounts(@dDateB,'CREDIT_ACC_11') R
group by R.AP1, ACCOUNT

set @dDateE = @dDateE + 1
insert into @tRest
select R.AP1, sum(R.D_SUMMA - R.K_SUMMA), 2
from dbo.aRestTableByDateAccounts(@dDateE,'CREDIT_ACC_11') R
group by R.AP1, ACCOUNT

insert into @tDoc 
select * from (
	select  O.LINK,
			O.DOC_LINK,
			O.INFO, 
			C.KDEP_NAME,
			C.SUMMA,
			C.[TYPE_NAME],
			--C.DATE_BEG,
			C.DATE,
			C.DATE_END,
			[PROC] = dbo.BB_CREDIT_PROC(C.LINK, @dDateE,'PROC',0),
			[TYPE] = case when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.11' where GAP.AP1 = O.LINK) then 1
							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.12' where GAP.AP1 = O.LINK) then 2
							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '1.301.13' where GAP.AP1 = O.LINK) then 3
							when exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '11' where GAP.AP1 = O.LINK) then 4
					 else 0 end
	from dbo.BD_OSNOV O
	left join dbo.BB_P_CREDIT C on C.LINK = O.DOC_LINK
	where C.LINK is not null and C.DEP_LINK = @iOwnDep and C.DATE_BEG <= @dDateE and C.DATE_END >= @dDateB
			or exists(select * from dbo.G_PROV_AP GAP inner join dbo.S_ACCOUNTS SA on SA.LINK = GAP.ACCOUNT and SA.CODE = '11' where GAP.AP1 = O.LINK)
			) A
where [TYPE] <> 0

--select * from @tDoc where [type] = 4
--select * from @tRest where doc in (select LINK_AP1 from @tDoc where [type] = 4)


exec dbo.BufferClear 'CREDIT_ACC'
exec dbo.BufferClear 'CREDIT_PER_D'
exec dbo.BufferClear 'CREDIT_PL_N'
exec dbo.BufferClear 'CREDIT_DOH_N'
exec dbo.BufferClear 'SGU_D'
exec dbo.BufferClear 'SGU_K'
exec dbo.BufferClear 'SGU_K_KL_N'
exec dbo.BufferClear 'CREDIT_ACC_11'

select	DOC = D.LINK_G, 
		D.INFO, 
		D.KDEP_NAME,
		D.SUMMA,
		D.[TYPE_NAME],
		D.DATE_BEG,
		D.DATE_END,
		OB.[DATE],
		D.[PROC],
		REST_B = isnull(RB.SUMMA,0),
		REST_E = isnull(RE.SUMMA,0),
		REST_BP = isnull(RPB.SUMMA,0),
		REST_EP = isnull(RPE.SUMMA,0),
		SUM_PER = isnull(OB.SUM_PER,0), 
		SUM_UPL = isnull(OB.SUM_UPL,0),
		PROC_N = isnull(OB.PROC_N,0),
		PROC_P = isnull(OB.PROC_P,0),
		OPER_NAME = case when isnull(OB.PROC_N,0) <> 0 or isnull(OB.PROC_N,0) <> 0 then 'Начисление процентов' else '' end
		
from @tDoc D
left join (select DOC, [DATE], 
			SUM_PER = sum(isnull(SUM_PER,0)), SUM_UPL = sum(isnull(SUM_UPL,0)), 
			PROC_N = sum(isnull(PROC_N,0)), PROC_P = sum(isnull(PROC_P,0))
			from @tOborot  group by DOC, [DATE]) OB on OB.DOC = D.LINK_AP1
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 1
union
select	0,	'', '', 0, '', NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''
where not exists(select * from @tDoc where [TYPE] = 1)
order by D.LINK_G, OB.[DATE] 



select	0, [MONTH] = 'на начало года',
		REST = sum(isnull(RB.SUMMA,0)),
		REST_P = sum(isnull(RPB.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
where D.[TYPE] = 1
union
select	M.NUM, M.MON, 0, 0,
		sum(isnull(OB.SUM_PER,0)), 
		sum(isnull(OB.SUM_UPL,0)),
		sum(isnull(OB.PROC_N,0)),
		sum(isnull(OB.PROC_P,0))
from dbo.Months M
left join @tOborot OB on month(OB.DATE) = M.NUM
left join @tDoc D on OB.DOC = D.LINK_AP1 and D.[TYPE] = 1
where D.[TYPE] = 1 --or OB.DATE is null
group by M.NUM, M.MON
union
select	13, [MONTH] = 'на конец года',
		REST = sum(isnull(RE.SUMMA,0)),
		REST_P = sum(isnull(RPE.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 1
order by 1

select	DOC = D.LINK_G, 
		D.INFO, 
		D.KDEP_NAME,
		D.SUMMA,
		D.[TYPE_NAME],
		D.DATE_BEG,
		D.DATE_END,
		OB.[DATE],
		D.[PROC],
		REST_B = isnull(RB.SUMMA,0),
		REST_E = isnull(RE.SUMMA,0),
		REST_BP = isnull(RPB.SUMMA,0),
		REST_EP = isnull(RPE.SUMMA,0),
		SUM_PER = isnull(OB.SUM_PER,0), 
		SUM_UPL = isnull(OB.SUM_UPL,0),
		PROC_N = isnull(OB.PROC_N,0),
		PROC_P = isnull(OB.PROC_P,0),
		OPER_NAME = case when isnull(OB.PROC_N,0) <> 0 or isnull(OB.PROC_N,0) <> 0 then 'Начисление процентов' else '' end
		
from @tDoc D
left join (select DOC, [DATE], 
			SUM_PER = sum(isnull(SUM_PER,0)), SUM_UPL = sum(isnull(SUM_UPL,0)), 
			PROC_N = sum(isnull(PROC_N,0)), PROC_P = sum(isnull(PROC_P,0))
			from @tOborot  group by DOC, [DATE]) OB on OB.DOC = D.LINK_AP1
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 3
union
select	0,	'', '', 0, '', NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''
where not exists(select * from @tDoc where [TYPE] = 3)
order by D.LINK_G, OB.[DATE] 



select	0, [MONTH] = 'на начало года',
		REST = sum(isnull(RB.SUMMA,0)),
		REST_P = sum(isnull(RPB.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
where D.[TYPE] = 3
union
select	M.NUM, M.MON, 0, 0,
		sum(isnull(OB.SUM_PER,0)), 
		sum(isnull(OB.SUM_UPL,0)),
		sum(isnull(OB.PROC_N,0)),
		sum(isnull(OB.PROC_P,0))
from dbo.Months M
left join @tOborot OB on month(OB.DATE) = M.NUM
left join @tDoc D on OB.DOC = D.LINK_AP1 -- and D.[TYPE] = 2
where D.[TYPE] = 3 --or OB.DATE is null
group by M.NUM, M.MON
union
select	13, [MONTH] = 'на конец года',
		REST = sum(isnull(RE.SUMMA,0)),
		REST_P = sum(isnull(RPE.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 3
order by 1

select	DOC = D.LINK_G, 
		D.INFO, 
		D.KDEP_NAME,
		D.SUMMA,
		D.[TYPE_NAME],
		D.DATE_BEG,
		D.DATE_END,
		OB.[DATE],
		D.[PROC],
		REST_B = isnull(RB.SUMMA,0),
		REST_E = isnull(RE.SUMMA,0),
		REST_BP = isnull(RPB.SUMMA,0),
		REST_EP = isnull(RPE.SUMMA,0),
		SUM_PER = isnull(OB.SUM_PER,0), 
		SUM_UPL = isnull(OB.SUM_UPL,0),
		PROC_N = isnull(OB.PROC_N,0),
		PROC_P = isnull(OB.PROC_P,0),
		OPER_NAME = case when isnull(OB.PROC_N,0) <> 0 or isnull(OB.PROC_N,0) <> 0 then 'Начисление процентов' else '' end
		
from @tDoc D
left join (select DOC, [DATE], 
			SUM_PER = sum(isnull(SUM_PER,0)), SUM_UPL = sum(isnull(SUM_UPL,0)), 
			PROC_N = sum(isnull(PROC_N,0)), PROC_P = sum(isnull(PROC_P,0))
			from @tOborot  group by DOC, [DATE]) OB on OB.DOC = D.LINK_AP1
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 2
union
select	0,	'', '', 0, '', NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''
where not exists(select * from @tDoc where [TYPE] = 2)
order by D.LINK_G, OB.[DATE] 



select	0, [MONTH] = 'на начало года',
		REST = sum(isnull(RB.SUMMA,0)),
		REST_P = sum(isnull(RPB.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
where D.[TYPE] = 2
union
select	M.NUM, M.MON, 0, 0,
		sum(isnull(OB.SUM_PER,0)), 
		sum(isnull(OB.SUM_UPL,0)),
		sum(isnull(OB.PROC_N,0)),
		sum(isnull(OB.PROC_P,0))
from dbo.Months M
left join @tOborot OB on month(OB.DATE) = M.NUM
left join @tDoc D on OB.DOC = D.LINK_AP1 -- and D.[TYPE] = 2
where D.[TYPE] = 2 --or OB.DATE is null
group by M.NUM, M.MON
union
select	13, [MONTH] = 'на конец года',
		REST = sum(isnull(RE.SUMMA,0)),
		REST_P = sum(isnull(RPE.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 2
order by 1


select	DOC = D.LINK_G, 
		D.INFO, 
		D.KDEP_NAME,
		D.SUMMA,
		D.[TYPE_NAME],
		D.DATE_BEG,
		D.DATE_END,
		OB.[DATE],
		D.[PROC],
		REST_B = isnull(RB.SUMMA,0),
		REST_E = isnull(RE.SUMMA,0),
		REST_BP = isnull(RPB.SUMMA,0),
		REST_EP = isnull(RPE.SUMMA,0),
		SUM_PER = isnull(OB.SUM_PER,0), 
		SUM_UPL = isnull(OB.SUM_UPL,0),
		PROC_N = isnull(OB.PROC_N,0),
		PROC_P = isnull(OB.PROC_P,0),
		OPER_NAME = case when isnull(OB.PROC_N,0) <> 0 or isnull(OB.PROC_N,0) <> 0 then 'Начисление процентов' else '' end
		
from @tDoc D
left join (select DOC, [DATE], 
			SUM_PER = sum(isnull(SUM_PER,0)), SUM_UPL = sum(isnull(SUM_UPL,0)), 
			PROC_N = sum(isnull(PROC_N,0)), PROC_P = sum(isnull(PROC_P,0))
			from @tOborot  group by DOC, [DATE]) OB on OB.DOC = D.LINK_AP1
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 4
union
select	0,	'', '', 0, '', NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''
where not exists(select * from @tDoc where [TYPE] = 4)
order by D.LINK_G, OB.[DATE] 



select	0, [MONTH] = 'на начало года',
		REST = sum(isnull(RB.SUMMA,0)),
		REST_P = sum(isnull(RPB.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
where D.[TYPE] = 4
union
select	M.NUM, M.MON, 0, 0,
		sum(isnull(OB.SUM_PER,0)), 
		sum(isnull(OB.SUM_UPL,0)),
		sum(isnull(OB.PROC_N,0)),
		sum(isnull(OB.PROC_P,0))
from dbo.Months M
left join @tOborot OB on month(OB.DATE) = M.NUM
left join @tDoc D on OB.DOC = D.LINK_AP1 -- and D.[TYPE] = 2
where D.[TYPE] = 4 --or OB.DATE is null
group by M.NUM, M.MON
union
select	13, [MONTH] = 'на конец года',
		REST = sum(isnull(RE.SUMMA,0)),
		REST_P = sum(isnull(RPE.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
where D.[TYPE] = 4
order by 1

select	0, [MONTH] = 'на начало года',
		REST = sum(isnull(RB.SUMMA,0)),
		REST_P = sum(isnull(RPB.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RB on RB.DOC = D.LINK_AP1 and RB.[TYPE] = 0
left join @tRest RPB on RPB.DOC = D.LINK_AP1 and RPB.[TYPE] = 1
--where D.[TYPE] = 4
union
select	M.NUM, M.MON, 0, 0,
		sum(isnull(OB.SUM_PER,0)), 
		sum(isnull(OB.SUM_UPL,0)),
		sum(isnull(OB.PROC_N,0)),
		sum(isnull(OB.PROC_P,0))
from dbo.Months M
left join @tOborot OB on month(OB.DATE) = M.NUM
left join @tDoc D on OB.DOC = D.LINK_AP1 -- and D.[TYPE] = 2
--where --D.[TYPE] = 4 or OB.DATE is null
group by M.NUM, M.MON
union
select	13, [MONTH] = 'на конец года',
		REST = sum(isnull(RE.SUMMA,0)),
		REST_P = sum(isnull(RPE.SUMMA,0)),
		SUM_PER = 0, 
		SUM_UPL = 0,
		PROC_N = 0,
		PROC_P = 0
from @tDoc D
left join @tRest RE on RE.DOC = D.LINK_AP1 and RE.[TYPE] = 2
left join @tRest RPE on RPE.DOC = D.LINK_AP1 and RPE.[TYPE] = 3
--where D.[TYPE] = 4
order by 1


return 1

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
grant execute on dbo.BB_DOLG_KNIGA to public
GO


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[XD_CORRECT_PROV_FULL_BY_XO_BUF]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[XD_CORRECT_PROV_FULL_BY_XO_BUF]

GO
-- Переформирование корректных поводок. В буфере перечень ХО, для которых обновить --
CREATE PROCEDURE dbo.XD_CORRECT_PROV_FULL_BY_XO_BUF
	(@strBUFFER		VARCHAR (254) = '',	-- Если имя буфера не указано, обновятся все проводки
	@intClear_Buf	TINYINT = 1		-- @intClear_Buf = 1, после завершения процедуры почистить буфер
	)
AS
BEGIN

	SET NOCOUNT ON
	
	-- Если нужно обновить все, кладем все хоз. операции в буфер --
	IF @strBUFFER = ''
	BEGIN
		EXEC dbo.GetRandStr 40, @strBUFFER OUTPUT
		SET @strBUFFER = 'UPDATE_ALL_CORRECT_PROV_' + @strBUFFER

		EXEC dbo.BufferPushTable
			'dbo.XOZ_OPER',
			@strBUFFER,
			'LINK'
			
		SET @intClear_Buf = 1	
	END
	
	-- Удаляем старые значения --
	DELETE CPF
	FROM dbo.CORRECT_PROV_FULL CPF
	INNER JOIN dbo.BufferGetTableByID (@strBUFFER) BUF ON (BUF.LINK = CPF.LINK_HOZ)

-- SELECT * FROM CORRECT_PROV_FULL
	-- Заполняем по новой --
	DECLARE
		@Curs CURSOR,
		@CurLinkHOZ int,
		@CurLinkDt int,
		@CurLinkKt int,
		@CurLinkDtSgu int,
		@CurLinkKtSgu int
		
	SET @Curs = CURSOR STATIC LOCAL
	FOR
	SELECT
		CP.LINK_HOZ,
		CP.LINK_DT,
		CP.DT_SGU,
		CP.LINK_KT,
		CP.KT_SGU 
	FROM dbo.CORRECT_PROV CP
	INNER JOIN dbo.BufferGetTableByID (@strBUFFER) BUF ON (BUF.LINK = CP.LINK_HOZ)
	INNER JOIN dbo.S_ACCOUNTS DT ON (DT.LINK  = CP.LINK_DT)
	INNER JOIN dbo.S_ACCOUNTS KT ON (KT.LINK = CP.LINK_KT)

-- SELECT * FROM CORRECT_PROV
	OPEN @Curs

	FETCH FROM @Curs
		INTO
			@CurLinkHOZ,
			@CurLinkDt,
			@CurLinkDtSgu,
			@CurLinkKt,
			@CurLinkKtSgu

	WHILE @@FETCH_STATUS = 0
	BEGIN
		INSERT INTO dbo.CORRECT_PROV_FULL (LINK_HOZ,LINK_DT,DT_CODE,LINK_DT_SGU,DT_SGU_CODE,LINK_KT,KT_CODE,LINK_KT_SGU,KT_SGU_CODE)
		SELECT @CurLinkHOZ,
			   S1.LINK,S1.CODE,@CurLinkDtSgu,(SELECT CODE FROM dbo.KOSGU WHERE LINK = @CurLinkDtSgu) AS DT_SGU_CODE,
			   S2.LINK, S2.CODE,@CurLinkKtSgu,(SELECT CODE FROM dbo.KOSGU WHERE LINK = @CurLinkKtSgu) AS KT_SGU_CODE
		FROM S_ACCOUNTS S1,S_ACCOUNTS S2
		 WHERE S1.LINK IN (Select LINK from dbo.AccountsFullSubtreeByRoot(@CurLinkDt) WHERE dbo.AccountsHasNoChild(LINK) = 1)
		  AND S2.LINK IN (Select LINK from dbo.AccountsFullSubtreeByRoot(@CurLinkKt ) WHERE dbo.AccountsHasNoChild(LINK) = 1)
		  AND S1.cSource = S2.cSource 
		
		FETCH NEXT FROM @Curs
			INTO
				@CurLinkHOZ,
				@CurLinkDt,
				@CurLinkDtSgu,
				@CurLinkKt,
				@CurLinkKtSgu
	END
	
	CLOSE @Curs
	DEALLOCATE @Curs
	
	-- Очистка буфера --
	IF ISNULL (@intClear_Buf, 0) = 1
		EXEC dbo.BufferClear @strBUFFER

	SET NOCOUNT OFF

END

GO


GRANT EXECUTE ON dbo.[XD_CORRECT_PROV_FULL_BY_XO_BUF] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[RO_PRINT_125_2015]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[RO_PRINT_125_2015]

GO

/*
© Кейсистемс (Keysystems), 2009
*/

CREATE PROCEDURE dbo.[RO_PRINT_125_2015]
	@LSF	bigint,
	@bDeleteEmptyRows BIT = NULL,  --  NULL - данные выбираются не для печати, 1 - удаление пустых строк (поле DEL = 1), 0 - не удалять.
    @data int=1, -- c_nastr не будет создаваться!
	@notNullCol tinyint = 0,
	@AtrInOnePage tinyint = 0,
	@WEB_excel tinyint = 0 -- 1 - вызывается для печати из WEB для excel-генератора
AS

	if isnull(@WEB_excel, 0) <> 1
		select '' col1 
	declare  @atr varchar(254), @atr_value varchar(254)
	if YEAR((select begin_date from dbo.report_saved_forms where link_saved_form = @LSF)) > 2010
		set @atr = 'REPORTS_ATR_ACC_2011'
	else
		set @atr = 'REPORTS_ATR_ACC'
	set @atr_value = dbo.RN_GET_ATR_Value(@LSF, @atr)
	create table #all (ATR varchar(100), COL1 varchar(8000), COL2 varchar(8000), COL3 varchar(8000), COL4 varchar(8000), COL5 varchar(8000), COL6 varchar(8000), COL7 float, COL8 float, COL9 varchar (8000), COL10 varchar (8000), COL11 varchar (8000), COL12 varchar (8000), COL13 varchar (8000), COL14 varchar (8000), COL15 varchar (8000), COL16 varchar (8000), COL17 varchar (8000), COL18 varchar (8000), COL19 varchar (8000), CODE varchar(50), DEL bit, ITOG int, orders int IDENTITY(1,1))
	create table #doh (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(8000), Col2 varchar(8000), Col3 varchar(8000), Col4 varchar(8000), Col5 varchar(8000), Col6 varchar(8000), Col7 float, Col8 float, col9 varchar(8000), col10 varchar(8000), col11 varchar(8000), col12 varchar(8000), col13 varchar(8000), col14 varchar(8000), col15 varchar(8000), col16 varchar(8000), col17 varchar(8000), atr varchar(250) )
	create table #rash (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(8000), Col2 varchar(8000), Col3 varchar(8000), Col4 varchar(8000), Col5 varchar(8000), Col6 varchar(8000), Col7 varchar(8000), Col8 varchar(8000), Col9 varchar(8000), col10 float, col11 float, col12 varchar(8000), col13 varchar(8000), col14 varchar(8000), col15 varchar(8000), col16 varchar(8000), col17 varchar(8000), col18 varchar(8000), col19 varchar(8000), atr varchar(250) )
	create table #ist (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(8000), Col2 varchar(8000), Col3 varchar(8000), Col4 varchar(8000), Col5 varchar(8000), Col6 varchar(8000), Col7 varchar(8000), Col8 float, Col9 float, col10 varchar(8000), col11 varchar(8000), col12 varchar(8000), col13 varchar(8000), col14 varchar(8000), col15 varchar(8000), col16 varchar(8000), col17 varchar(8000), atr varchar(250) )
	create table #itog (checked tinyint, Upd tinyint, del tinyint, link_saved_form int, link_row int, orders int, Calc_orders int, Print_NULL tinyint, Code varchar(50), Col1 varchar(8000), Col2 varchar(8000), Col3 varchar(8000), Col4 varchar(8000), Col5 varchar(8000), Col6 varchar(8000), Col7 float, Col8 float, col9 varchar(8000), col10 varchar(8000), col11 varchar(8000), col12 varchar(8000), col13 varchar(8000), col14 varchar(8000), atr varchar(250))


	insert #doh exec dbo.ro_get_all_atr_table @LSF, 1, @bDeleteEmptyRows, @AtrInOnePage, @atr
	insert #rash exec dbo.ro_get_all_atr_table @LSF, 2, @bDeleteEmptyRows, @AtrInOnePage, @atr
	insert #ist exec dbo.ro_get_all_atr_table @LSF, 3, @bDeleteEmptyRows, @AtrInOnePage, @atr
	insert #itog exec dbo.ro_get_all_atr_table @LSF, 4, @bDeleteEmptyRows, @AtrInOnePage, @atr


	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, code, del, itog)
	SELECT atr, RTRIM(COL1), COL2, COL3, COL4, COL5, COL6+COL14,COL7,COL8,COL9,COL10,COL11,COL12,COL13, col14,COL15,COL16, col17,CODE, 0 as DEL, 0 from #doh ORDER BY 1,3,4,5,6

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col10, col11, col12, col13, col14, col15, col16, col17, code, del, itog)
	SELECT atr, RTRIM(COL1), COL2, COL3, COL4, COL5, COL6+COL7+COL8+COL9,COL10,COL11, col12, col13, col14, col15, col16, col17, col18, col19,CODE, 0 as DEL, 0 from #rash ORDER BY 1,3,4,5,6

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col10, col11, col12, col13, col14, col15, col16, col17, code, del, itog)
	SELECT atr, RTRIM(COL1), COL2, COL3, COL4, col5, COL6+COL7,COL8,COL9, col10, col11, col12, col13, col14, col15, col16, col17,CODE, 0 as DEL, 0 from #ist ORDER BY 1,3,4,5,6

	if not exists(select top 1 * from #all)
		insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
		select atr, '', '', '', '', '','', NULL, NULL,'','','','', '', 0, 0
		from #itog 
		group by atr

	if not exists(select top 1 * from #all)
		insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
		select @atr_value, '', '', '', '', '', '', null, null,'','','','', '', 0, 0

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr, 'Итого:', max(COL2), 'X' AS COL3, 'X' AS COL4, 'X' AS COL5, 'X' AS COL6, max(COL7) , max(COL8),max(COL9),max(COL10),max(COL11), 'X' AS COL12, max(CODE) AS CODE, 0 as DEL, 1  
	from #itog WHERE RTRIM(LTRIM(CODE)) = 'Итого'
	group by atr

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr, 'Итого:', '' AS COL2, 'X' AS COL3, 'X' AS COL4, 'X' AS COL5, 'X' AS COL6, 0 as COL7 , 0 as COL8, '' AS COL9, '' AS COL10, '' AS COL11, 'X' AS COL12, '' AS CODE, 0 as DEL, 1  
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RTRIM(LTRIM(A1.CODE)) = 'Итого')
	group by atr

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	select atr, 'в том числе по', '', '', '', '', '', NULL, NULL, '', '', '', '', '', 0, 1
	from #all
	group by atr

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	SELECT atr, 'номеру (коду) счета:', COL2, COL3, COL4, COL5,COL6,COL7, col9, col8, col10, col11,'X' AS COL12, CODE, 0 as DEL, 1  from #itog 
	WHERE RIGHT(RTRIM(CODE),2) = 'ИП' ORDER BY 1, 2, 3, 4, 5,6

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	select atr, 'номеру (коду) счета:', '', '', '', '', '', NULL, NULL, '', '', '', 'X', '', 0, 1
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RIGHT(RTRIM(A1.CODE),2) = 'ИП')
	group by atr

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	select atr, 'номеру (коду) счета:', '', '', '', '', '', NULL, NULL, '', '', '', 'X', '', 0, 1
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RIGHT(RTRIM(A1.CODE),2) = 'ИП')
	group by atr

	update A
	set col1 = ''
	from #all A
	where col1 = 'номеру (коду) счета:' and exists(select top 1 * from #all A1 where A.atr = A1.atr and A1.col1 = 'номеру (коду) счета:' and A1.orders < A.orders)

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	select atr, 'из них:', '', '', '', '', '', NULL, NULL, '', '', '', '', '', 0, 1
	from #all 
	group by atr
	
	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	SELECT atr, 'денежные расчеты', '', '', '', '', '',COL7,COL8, '', '', '', '', CODE, 0 as DEL, 1   from #itog 
	WHERE RTRIM(LTRIM(CODE)) = 'итог_денежные_рассчёты'

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr, 'денежные расчеты', '', '', '', '', '',0 as COL7,0 as COL8, '', '', '', '', '' as CODE, 0 as DEL, 1   
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RTRIM(LTRIM(A1.CODE)) = 'итог_денежные_рассчёты')
	group by atr

	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	SELECT atr, '', COL2,COL3,COL4,COL5,COL6, COL7,COL8, col9, col10, col11, col12, CODE, 0 as DEL, 1 from #itog WHERE RIGHT(RTRIM(LTRIM(CODE)),2) = 'ИД'  ORDER BY 1, 2, 3, 4, 5,6
   
	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr, '', '', '', '', '', '',0 as COL7,0 as COL8, '', '', '', '', '' as CODE, 0 as DEL, 1   
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RIGHT(RTRIM(LTRIM(A1.CODE)),2) = 'ИД')
	group by atr


	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	SELECT atr, 'неденежные расчеты', '', '', '', '', '',COL7,COL8, '', '', '', '',CODE, 0 as DEL,1  
	from #itog WHERE LTRIM(RTRIM(CODE)) = 'итог_неденежные_рассчёты'

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr,'неденежные расчеты', '', '', '', '', '',0 as COL7,0 as COL8, '', '', '', '', '' as CODE, 0 as DEL, 1   
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and LTRIM(RTRIM(A1.CODE)) = 'итог_неденежные_рассчёты')
	group by atr
	
	insert #all (atr, COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8, col9, col10, col11, col12, CODE, DEL, ITOG)
	SELECT atr, '', COL2,COL3,COL4,COL5,COL6,COL7,COL8, col9, col10, col11, col12,CODE, 0 as DEL, 1  from #itog WHERE RIGHT(LTRIM(RTRIM(CODE)),2) = 'ИН'  ORDER BY 1, 2, 3, 4, 5,6

	insert #all (atr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog)
	SELECT atr, '', '', '', '', '', '',0 as COL7,0 as COL8, '', '', '', '', '' as CODE, 0 as DEL, 1   
	from #all A
	where not exists(select top 1 * from #itog A1 where A.atr = A1.atr and RIGHT(RTRIM(LTRIM(A1.CODE)),2) =  'ИН')
	group by atr

	select atr as colatr, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, code, del, itog as colitog, orders from #all order by atr, orders

	drop table #all
	drop table #ist
	drop table #doh
	drop table #rash
	drop table #itog

	if isnull(@WEB_excel, 0) <> 1
	select cells as style,style as value from report_print_style where 1=0 order by cells



GO


GRANT EXECUTE ON dbo.[RO_PRINT_125_2015] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BA_SELECT_REST_MP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BA_SELECT_REST_MP]

GO

/*******************************************************************************

	© Кейсистемс (Keysystems), 2006

*******************************************************************************/
-- Процедура выборки данных для заполения списка инвентаря в режиме "Списание мягкого и хозяйственного инвентаря".
CREATE PROCEDURE dbo.[BA_SELECT_REST_MP]
	@dDATE		 DATETIME     = NULL,   
	@iDEP_LINK	 INT          = NULL,
	@iEMP_LINK	 INT          = NULL
AS

   SELECT [INV_TYPE] = 'BV_NOMENCLATURE',
          [INV_LINK] = T1.[LINK],
          [INV_CODE] = T1.[CODE],
          [INV_NAME] = T1.[NAME],
          [UM_NAME],
          [QTY]      = [QUANTITY],
          [REST]     = [QUANTITY],
          SUM_REST	=	SUMMA,
          [PRICE],
          [SUMMA]    = SUMMA,
          ACCOUNT	=	ACC_LINK,
          ACCT_CODE	=	ACC_CODE
   FROM dbo.[BV_ViborRestMz](@dDATE,
                             'BV_NOMENCLATURE') T1
   WHERE [DEP_LINK] = @iDEP_LINK
	AND [EMP_LINK] = ISNULL(@iEMP_LINK,0)
	AND (T1.GRP_CODE LIKE '101_6%'
		OR T1.GRP_CODE LIKE '105_[5-6]%')
   UNION
   SELECT [INV_TYPE] = 'INVENTORY_CARD',
          [INV_LINK] = T1.[LINK],
          [INV_CODE] = T1.[CODE],
          [INV_NAME] = T1.[NAME],
          [UM_NAME],
          [QTY]      = [QUANTITY],
          [REST]     = [QUANTITY],
          SUM_REST	=	SUMMA,
          [PRICE],
          [SUMMA]    = SUMMA,
          ACCOUNT	=	ACC_LINK,
          ACCT_CODE	=	ACC_CODE
   FROM dbo.[BV_ViborRestMz](@dDATE,
                             'INVENTORY_CARD') T1
   WHERE [DEP_LINK] = @iDEP_LINK         
         AND [EMP_LINK] = ISNULL(@iEMP_LINK,0)  
	 	AND T1.GRP_CODE LIKE '101_6%'





SET QUOTED_IDENTIFIER OFF 

GO


GRANT EXECUTE ON dbo.[BA_SELECT_REST_MP] TO PUBLIC

GO


--Расширенные свойства--


GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FB_BUDG_SMETA_REPORT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[FB_BUDG_SMETA_REPORT]
GO

CREATE          PROCEDURE dbo.FB_BUDG_SMETA_REPORT
		@dDate		 datetime,
		@iDocType	 tinyint,
		--@iDopEkr	 tinyint,
		@cVal1		 char(1), 
		@nOtborLink1 int,
		@cVal2		 char(1) = '', 
		@nOtborLink2 int,
		@cVal3		 char(1) = '', 
		@nOtborLink3 int
			

AS
DECLARE		@cCROSS_TABLE 	char(100),
			@cSQL_STR		VARCHAR (8000),
			@cSQL_STRU		VARCHAR (8000),
			@iAccount		int,
			@dDateBegP		datetime,
			@varKSiOwnDep	int,
			@cYear			char(4),
			@iMonthCount	tinyint,
			@iMonth			tinyint
		


-- Выбираем КБК из фильтров по Подразделам и ЦС
DECLARE @tVKR  TABLE (LINK [INT])	
DECLARE @tSGU  TABLE (LINK [INT])	
DECLARE @tDCL  TABLE (LINK [INT])	

IF LEN (@cVal1) > 0
	INSERT INTO @tVKR
	SELECT RECORD
	FROM dbo.OBJECT_VAR_KBK
	where LINK_UP = @nOtborLink1

IF LEN (@cVal2) > 0
	INSERT INTO @tSGU
	SELECT RECORD
	FROM dbo.OBJECT_VAR_KOSGU 
	where LINK_UP = @nOtborLink2

IF LEN (@cVal3) > 0
	INSERT INTO @tDCL
	SELECT RECORD
	FROM dbo.OBJECT_VAR_DOP_CLASSIF 
	where LINK_UP = @nOtborLink3

set @dDateBegP = dbo.DateBeginOfYear(@dDate)
select @iAccount = LINK 
from dbo.S_ACCOUNTS
where CODE = '1.501.13' 

set @varKSiOwnDep = isnull(dbo.BK_GetDepZB(),dbo.GetOwnDepLink())

CREATE TABLE #TAB_TEMPI (
	PER_NUM		int,
	VKR			int, 
	EKR			INT, 
	SUMMA	[numeric](28, 2) NULL)

CREATE TABLE #TAB_TEMP (
	VKR			int, 
	EKR			INT, 
	SUMMA	[numeric](28, 2) NULL)


insert into #TAB_TEMP
select  L.KBK,
		L.EKR,
		sum(isnull(k_summa,0))
from dbo.FB_LimitOborotByPeriod(@dDateBegP,@dDate, @iAccount) L
where  L.DEP_LINK = @varKSiOwnDep and 
		exists(select * from dbo.FINANSE_HEAD where LINK = L.LINK_UP and (PARAM & 0x1) = 0) and 
		(@cVal1 = '' or @cVal1 <> '' and L.KBK in (select LINK from @tVKR)) and
		(@cVal2 = '' or @cVal2 <> '' and L.SGU in (select LINK from @tSGU)) and
		(@cVal3 = '' or @cVal3 <> '' and L.AP2 in (select LINK from @tDCL)) and 
		@iDocType < 3
GROUP BY L.KBK,L.EKR
HAVING sum(isnull(k_summa,0)) <> 0


insert into #TAB_TEMPI
select  month(L.DATE_PROV),
		L.KBK,
		L.EKR,
		sum(isnull(k_summa,0))
from dbo.FB_LimitOborotByPeriod(@dDateBegP,@dDate, @iAccount) L
where  L.DEP_LINK = @varKSiOwnDep and 
		exists(select * from dbo.FINANSE_HEAD where LINK = L.LINK_UP and (PARAM & 0x1) = 1)  and 
		(@cVal1 = '' or @cVal1 <> '' and L.KBK in (select LINK from @tVKR)) and
		(@cVal2 = '' or @cVal2 <> '' and L.SGU in (select LINK from @tSGU))and
		(@cVal3 = '' or @cVal3 <> '' and L.AP2 in (select LINK from @tDCL))
GROUP BY L.KBK,L.EKR, month(L.DATE_PROV)
HAVING sum(isnull(k_summa,0)) <> 0

	

if @iDocType > 1
begin
	select @iMonthCount = count(*) 
	from (select PER_NUM
			from #TAB_TEMPI
			group by PER_NUM) A
	if @iMonthCount = 0
	begin 
		select 0 where 0>1
		return 0
	end
			
	set @cSQL_STR = '
	CREATE TABLE ##TAB_TEMP_R (
	VKR		int,
	EKR		int'

	set @cSQL_STRU = '
	update ##TAB_TEMP_R set '


	set @iMonth = 1
	WHILE @iMonth <= @iMonthCount 
	BEGIN
		set @cSQL_STR = @cSQL_STR + ',
	PER_NUM_' + ltrim(rtrim(str(@iMonth))) + '			int,
	SUMMA_' + ltrim(rtrim(str(@iMonth))) + '		NUMERIC (28,4)'
		set @cSQL_STRU = @cSQL_STRU + '
		PER_NUM_' + ltrim(rtrim(str(@iMonth))) + 
		' = (select top 1 PER_NUM_' + ltrim(rtrim(str(@iMonth))) + ' from ##TAB_TEMP_R where PER_NUM_' + ltrim(rtrim(str(@iMonth))) + ' is not null),'
		set @iMonth = @iMonth + 1
	END

	set @cSQL_STR = @cSQL_STR + ',
	SUMMA		NUMERIC (28,4),
	SUMMAI		NUMERIC (28,4),
	VKR_CODE	VARCHAR(20),
	EKR_CODE	char(3),
	NAME		VARCHAR(254),
	DIV_CODE	VARCHAR(4),
	DIV_NAME	VARCHAR(254),
	VKR_NAME	VARCHAR(254),
	YEAR  		CHAR(4))'
	
	
	set @cSQL_STRU = left(@cSQL_STRU,len(@cSQL_STRU)- 1)
	
	EXEC (@cSQL_STR)

	-- Разворачиваем таблицу по месяцам
	EXEC X_GET_TABLE_NAME @cCROSS_TABLE OUTPUT
	EXEC M_CROSS_TABLE 'VKR, EKR', 'PER_NUM', 'INT', 'SUMMA', 'NUMERIC (28,4)', 'SUM (SUMMA) AS SUMMA', '#TAB_TEMPI', @cCROSS_TABLE
	
	set @cSQL_STR = '
	insert into ##TAB_TEMP_R
	select T.*,
			SUMMA = isnull(TS.SUMMA,0),
			SUMMAI = isnull(TI.SUMMA,0) + isnull(TS.SUMMA,0),
			VKR_CODE = KBK.CODE,
			EKR_CODE = isnull(SGU.CODE,''''),
			NAME = 	coalesce(SGU.NAME,KBK.NAME),
			KBK.DIV_CODE,
			KBK.DIV_NAME,
			VKR_NAME = KBK.NAME,
			YEAR = ' + ltrim(str(year(@dDate))) + '
	from (select VKR, EKR from #TAB_TEMP union
		  select VKR, EKR from #TAB_TEMPI) C
	LEFT JOIN ' + rtrim(@cCROSS_TABLE) + ' T ON T.VKR = C.VKR and T.EKR = C.EKR 
	LEFT JOIN dbo.BI_DICTION_KBK_FULL KBK ON C.VKR = KBK.LINK
	LEFT JOIN dbo.KOSGU SGU ON C.EKR = SGU.LINK
	LEFT JOIN (select VKR, EKR, sum(SUMMA) as SUMMA from #TAB_TEMPI GROUP BY VKR, EKR) TI ON TI.VKR = C.VKR and TI.EKR = C.EKR
	LEFT JOIN (select VKR, EKR, sum(SUMMA) as SUMMA from #TAB_TEMP GROUP BY VKR, EKR) TS ON TS.VKR = C.VKR and TS.EKR = C.EKR
	'
	EXEC (@cSQL_STR)
	
	EXEC ('DROP TABLE ' + @cCROSS_TABLE)
	
	EXEC (@cSQL_STRU)
	print @cSQL_STRU
	
	EXEC ('select * from ##TAB_TEMP_R ORDER BY DIV_CODE, VKR_CODE, EKR_CODE')
	EXEC ('DROP TABLE ##TAB_TEMP_R')


end
else
	select T.*,
			VKR_CODE = KBK.CODE,
			EKR_CODE = isnull(SGU.CODE,''''),
			NAME = 	coalesce(SGU.NAME,KBK.NAME),
			KBK.DIV_LINK,
			KBK.DIV_NAME,
			VKR_NAME = KBK.NAME,
			YEAR = ltrim(str(year(@dDate)))
	from #TAB_TEMP T 
	LEFT JOIN dbo.BI_DICTION_KBK_FULL KBK ON T.VKR = KBK.LINK
	LEFT JOIN dbo.KOSGU SGU ON T.EKR = SGU.LINK
	ORDER BY KBK.CODE,isnull(SGU.CODE,'')
DROP TABLE #TAB_TEMP
DROP TABLE #TAB_TEMPI


RETURN 1



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

grant all on dbo.FB_BUDG_SMETA_REPORT to public
GO

	
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_VAC_CHILD_GET_SUM]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_VAC_CHILD_GET_SUM]

GO

CREATE PROCEDURE [dbo].[SA_VAC_CHILD_GET_SUM]
(
	@LINK_EMPL INT,
	@CNT INT = 1,
	@DATE DATETIME,
	@DATE1 DATETIME,
	@DATE2 DATETIME,
	@link_pay INT,
	@link_r INT,
	@linkDep int,
	@INSTRUCT TINYINT = 1
)

AS

declare @LINK_BL INT, @RefArche INT, @SR_ZAR numeric(18,2), @SUM_LIMIT numeric(18,2), @SUM numeric(18,2)
declare @varKStrancount int

SET @varKStrancount = @@TRANCOUNT
SET IMPLICIT_TRANSACTIONS ON
BEGIN TRAN
COMMIT TRAN


Set @RefArche = (Select top 1 link from dbo.Netrud where DEKRET = 1)

IF COALESCE(@RefArche,0) = 0
BEGIN
	ROLLBACK
	RETURN -101
END

exec SD_DIS_SAVE @LINK_BL OUT, 
	'#1', 		-- @Number	varchar(15)
	@DATE, 	--@Date		datetime = null,
	@RefArche, 	--int = null,
	'Расчет пособия', --varchar(100) = '',
	@LINK_EMPL,	-- int = null,
	@DATE1,	-- datetime = null,
	@DATE2,	-- datetime = null,
	1,		-- numeric(4,0) = 0,	
	1,		--@STAGMONTH numeric(2,0) = 0,
	1,		--@STAGDAY numeric(2,0) = 0,
	1,		--@Hours numeric(10,2) = 0.0,	
	0,		--@REF_DOC int = 0
	0,		--@REF_DOC int = 0
	@linkDep

IF @@ERROR <> 0
BEGIN
	ROLLBACK
	RETURN -102
END


--Сбросим начало расчётного периода, чтобы в расчёте оно было вычисленно заново
UPDATE dbo.SDOC_ADIS SET DATE_BEGIN = @DATE1 WHERE LINK_UP = @link_r

exec dbo.SA_N_BOL_FILL @link_r OUT, @LINK_BL, @link_pay, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, @INSTRUCT
IF @@ERROR <> 0
BEGIN
	ROLLBACK
	RETURN -102
END

Set @SR_ZAR = (select top 1 SR_ZAR from sdoc_adis where LINK_UP = @link_r)
Set @SUM_LIMIT = (select top 1 SUM_LIMIT from SDOC_ADIS_TABLE1 where LINK_UP = @link_r)

DECLARE @VAC_CHILD_OPT1 numeric(18,2) --Мин. размер пособия по уходу за 1 ребенком
DECLARE @VAC_CHILD_OPT2 numeric(18,2) --Мин. размер пособия по уходу за 2 и более дет.
DECLARE @VAC_CHILD_OPT3 numeric(18,2) --Макс. размер пособия по уходу за 1 ребенком
DECLARE @VAC_CHILD_OPT4 numeric(18,2) --Макс.  размер пособия по уходу за 2 и более дет.
DECLARE @VAC_CHILD_OPT5 numeric(18,2) --Ср.м. число кал. дней для расчета пособ.
DECLARE @VAC_CHILD_OPT6 numeric(18,2) --Процент заработка 

SET @VAC_CHILD_OPT1 = dbo.sa_get_option_by_code('VAC_CHILD_OPT1')
IF COALESCE(@VAC_CHILD_OPT1,0) = 0
BEGIN
	ROLLBACK
	RETURN -103
END
SET @VAC_CHILD_OPT2 = dbo.sa_get_option_by_code('VAC_CHILD_OPT2')
IF COALESCE(@VAC_CHILD_OPT2,0) = 0
BEGIN
	ROLLBACK
	RETURN -104
END
SET @VAC_CHILD_OPT3 = dbo.sa_get_option_by_code('VAC_CHILD_OPT3')
IF COALESCE(@VAC_CHILD_OPT3,0) = 0
BEGIN
	ROLLBACK
	RETURN -105
END
SET @VAC_CHILD_OPT4 = dbo.sa_get_option_by_code('VAC_CHILD_OPT4')
IF COALESCE(@VAC_CHILD_OPT4,0) = 0
BEGIN
	ROLLBACK
	RETURN -106
END
SET @VAC_CHILD_OPT5 = dbo.sa_get_option_by_code('VAC_CHILD_OPT5')
IF COALESCE(@VAC_CHILD_OPT5,0) = 0
BEGIN
	ROLLBACK
	RETURN -107
END
SET @VAC_CHILD_OPT6 = dbo.sa_get_option_by_code('VAC_CHILD_OPT6')
IF COALESCE(@VAC_CHILD_OPT6,0) = 0
BEGIN
	ROLLBACK
	RETURN -108
END

SET @SUM = @SR_ZAR * @VAC_CHILD_OPT5 * @VAC_CHILD_OPT6 / 100
SET @SUM = CASE WHEN @CNT = 1 THEN CASE WHEN @SUM < @VAC_CHILD_OPT1 THEN @VAC_CHILD_OPT1 ELSE CASE WHEN @SUM > @VAC_CHILD_OPT3 THEN @VAC_CHILD_OPT3 ELSE @SUM END END
		ELSE CASE WHEN @SUM < @VAC_CHILD_OPT2 THEN @VAC_CHILD_OPT2 ELSE CASE WHEN @SUM > @VAC_CHILD_OPT4 THEN @VAC_CHILD_OPT4 ELSE @SUM END END
	END	

delete from SDOC_ADIS_TABLE1 where link_up = @link_r
insert into SDOC_ADIS_TABLE1 (LINK_UP, ORDERS, DATE1, DATE2, SUM_LIMIT, DAYS, HOURS, SUMMA, PERC, SR_ZP, PAYER, LINK_KBK, KOEF_KBK)
VALUES(@link_r, 1, @DATE1, @DATE2, @SUM_LIMIT, @VAC_CHILD_OPT5, 0, @SUM, @VAC_CHILD_OPT6, CONVERT(NUMERIC(18,2),@SR_ZAR * @VAC_CHILD_OPT5), 0, NULL, 1)

update SDOC_ADIS 
set REF_DOC = NULL
where link_up = @link_r

delete from sdoc where link = @LINK_BL

SELECT @link_r as link_r, @SUM as SUMMA

IF @@TRANCOUNT > @varKStrancount  
	COMMIT TRAN
RETURN 0



GO


GRANT EXECUTE ON dbo.[SA_VAC_CHILD_GET_SUM] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[PA_SELECT_MENU_DECOMPOSE_INFO]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[PA_SELECT_MENU_DECOMPOSE_INFO]

GO

/*******************************************************************************

	© Кейсистемс (Keysystems), 2006

*******************************************************************************/
-- Процедура определения стоимости блюда.
CREATE PROCEDURE dbo.[PA_SELECT_MENU_DECOMPOSE_INFO]
   @iMode TINYINT, -- Режим работы : 0 - Получение данных по меню-раскладке;
                   --                1 - Получение данных по блюду.
   @iLINK INT      -- В режиме 0 - ссылка на меню (PA_MENU_DECOMPOSE), в режиме 1 - на блюдо (PA_DISH).
  
AS
PRINT 'Х.п. PA_SELECT_MENU_DECOMPOSE_INFO : Вход.'

IF @iMode = 0
BEGIN

   SELECT [CHECKED]    = 0,
          [VISIBLE]    = 0,
          [NOMEN_LINK] = [N].[LINK],
          [NOMEN_NAME] = [N].[NAME],
          [UM]         = [U].[NAME],
          [USE]        = 0,
          [TOTAL]      = 0,-- [M].[GROSS],
          [BALANCE]    = ISNULL([R].[SUM],0)
/*   FROM (SELECT [LINK_NOMEN],
                [GROSS] = SUM([PORTIONS]*[GROSS])
         FROM dbo.[PA_SELECT_MENU_DECOMPOSE_NOMEN](@iLINK)
         GROUP BY [LINK_NOMEN]) [M]*/
   FROM (SELECT DISTINCT [LINK_NOMEN]
         FROM dbo.[PA_SELECT_MENU_DECOMPOSE_NOMEN](@iLINK)) [M]
   JOIN dbo.[NOMENCLATURE]                                  [N] ON [M].[LINK_NOMEN] = [N].[LINK]
   LEFT JOIN dbo.[DICTION]                                       [U] ON [U].[LINK] = [N].[UM]
   LEFT JOIN (SELECT [V].[LINK],
                     [SUM] = SUM([V].[QUANTITY])
              FROM dbo.[BA_SELECT_DEPARTMENTS_ZB]()        [D]
              JOIN dbo.[BV_ViborRestMz](DEFAULT,
                                        'BV_NOMENCLATURE') [V] ON [V].[DEP_LINK] = [D].[LINK]

              GROUP BY [V].[LINK]) [R] ON [R].[LINK] = [N].[LINK]

END
ELSE
BEGIN
   SELECT [NOMEN_LINK] = [N].[LINK],
          [NOMEN_NAME] = [N].[NAME],        
          [GROSS]      = [U].[GROSS],
          [UM]         = [S].[NAME],
          [BALANCE]    = ISNULL([R].[SUM],0)
   FROM dbo.[PV_UnfoldDish](@iLINK) [U]
   JOIN dbo.[NOMENCLATURE]          [N] ON [N].[LINK] = [U].[LINK_NOM]
   LEFT JOIN dbo.[DICTION]               [S] ON [S].[LINK] = [N].[UM]
   LEFT JOIN (SELECT [V].[LINK],
                     [SUM] = SUM([V].[QUANTITY])
              FROM dbo.[BA_SELECT_DEPARTMENTS_ZB]()        [D]   
              JOIN dbo.[BV_ViborRestMz](DEFAULT,
                                        'BV_NOMENCLATURE') [V] ON [V].[DEP_LINK] = [D].[LINK]
              GROUP BY [V].[LINK]) [R] ON [R].[LINK] = [U].[LINK_NOM]
END

PRINT 'Х.п. PA_SELECT_MENU_DECOMPOSE_INFO : Выход.'
RETURN 0 -- Выход без ошибок.

GO


GRANT EXECUTE ON dbo.[PA_SELECT_MENU_DECOMPOSE_INFO] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BA_SAVE_MP_CHARGE_TABLE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BA_SAVE_MP_CHARGE_TABLE]

GO

-- Процедура сохранения строки таблицы BA_MOL.
CREATE PROCEDURE dbo.[BA_SAVE_MP_CHARGE_TABLE]
	@iLINK		  INT	OUTPUT,
	@iLINK_UP	  INT,
	@vcINV_TYPE   VARCHAR(30),
	@iINV_LINK    INT,
	@nQTY         NUMERIC(12,4),
	@iORDERS      INT,
	@ACCOUNT	INT = NULL,
	@QTY_REST	NUMERIC (28,4) = 0,
	@SUMMA		NUMERIC (28,4) = 0,
	@PRICE		NUMERIC (28,4) = 0,
	@PRICE_FACT	NUMERIC (28,4) = 0,
	@SUM_REST	NUMERIC (28,4) = 0
AS
	DECLARE
		@liSO_LINK  INT, -- Ссылка на метаобъект (S_OBJECTS).
		@liRowCount INT, -- Количество обработанных строк.
		@liError    INT  -- Код ошибки.

	SET IMPLICIT_TRANSACTIONS OFF  -- Режим явного определения транзакций.
	SET LOCK_TIMEOUT 3000          -- Время ожидания разблокировки ресурсов 3 сек.
	PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Вход.'

	BEGIN TRANSACTION -- Начало новой транзакции.
	SAVE TRANSACTION SaveTran -- Создание точки сохранения.

	SET @liSO_LINK = dbo.[XA_GET_SO_LINK]('BA_DOC_MP_CHARGE_TABLE')

	IF @liSO_LINK IS NULL
	BEGIN
		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
		COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не выполнила.
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Удалена запись в связанном справочнике.'
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Выход. Код ошибки 3.'
		RETURN 3 -- Возврат кода ошибки.
	END

	-- Вставка/обновление OUT_TABLE_ROW
	EXECUTE @liError = dbo.[XA_UPDATE_OUT_TABLE_ROW]
		@iLINK OUTPUT, 
		@iLINK_UP, 
		@liSO_LINK, 
		@iORDERS
	    
	IF @liError <> 0
	BEGIN
		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
		COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не выполнила.
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Ошибка при вызове х.п. XA_UPDATE_OUT_TABLE_ROW.'
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Выход с кодом ошибки XA_UPDATE_OUT_TABLE_ROW.'
		RETURN @liError -- Возврат кода ошибки.
	END

	EXEC @liError = dbo.BK_UPDATE_OUT_TABLE_INV_TYPE
		@iLINK, 
		@vcINV_TYPE,
		@iINV_LINK

	IF @liError <> 0
	BEGIN
		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
		COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не выполнила.
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Ошибка при вызове х.п. XA_UPDATE_OUT_TABLE_SUMMA.'
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Выход с кодом ошибки XA_UPDATE_OUT_TABLE_SUMMA.'
		RETURN @liError -- Возврат кода ошибки.
	END

	EXEC @liError = dbo.BK_UPDATE_OUT_TABLE_MZ_CHARGE
		@intLINK_UP	=	@iLINK,
		@intACCOUNT	=	@ACCOUNT,
		@intNOMEN	=	NULL,
		@nQTY_REST	=	@QTY_REST,
		@nQTY		=	@nQTY,
		@nSUMMA		=	@SUMMA,
		@nPRICE		=	@PRICE,
		@nPRICE_FACT	=	@PRICE_FACT,
		@nSUM_REST	=	@SUM_REST

	IF @liError <> 0
	BEGIN
		ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
		COMMIT TRANSACTION -- Фиксация транзакции, которая ничего не выполнила.
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Ошибка при вызове х.п. XA_UPDATE_OUT_TABLE_SUMMA.'
		PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Выход с кодом ошибки XA_UPDATE_OUT_TABLE_SUMMA.'
		RETURN @liError -- Возврат кода ошибки.
	END

	PRINT 'Х.п. BA_SAVE_MP_CHARGE_TABLE : Выход.'
	COMMIT TRANSACTION -- Фиксация транзакции.
	RETURN 0 -- Ошибок нет.

GO

GRANT EXECUTE ON dbo.[BA_SAVE_MP_CHARGE_TABLE] TO PUBLIC

GO

--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_UPDATE_OUT_TABLE_MZ_CHARGE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_UPDATE_OUT_TABLE_MZ_CHARGE]

GO
CREATE PROCEDURE dbo.BK_UPDATE_OUT_TABLE_MZ_CHARGE
	(@intLINK_UP	INT,
	@intACCOUNT	INT,
	@intNOMEN	INT,
	@nQTY_REST	NUMERIC(28, 4),
	@nQTY		NUMERIC(28, 4),
	@nSUMMA		NUMERIC(28, 4),
	@nPRICE		NUMERIC(28, 4),
	@nPRICE_FACT	NUMERIC(28, 4),
	@nSUM_REST	NUMERIC(28, 4) = 0
	)
AS
BEGIN
	DECLARE
		@varKStrancount INT,
		@varKSRowCount INT,
		@varKSERROR INT

	IF NOT EXISTS (SELECT * FROM dbo.OUT_TABLE_ROW WHERE LINK = @intLINK_UP)
	BEGIN
		RAISERROR ('Строка была удалена!', 11, 1)
		RETURN 5
	END

	--- Проверяем значения перед сохранением ---
	SELECT
		@nQTY_REST	= ISNULL (@nQTY_REST, 0),
		@nQTY	= ISNULL (@nQTY, 0),
		@nSUMMA	= ISNULL (@nSUMMA, 0),
		@nPRICE	= ISNULL (@nPRICE, 0),
		@nPRICE_FACT	= ISNULL (@nPRICE_FACT, 0),
		@nSUM_REST	= ISNULL (@nSUM_REST, 0)

	IF @nPRICE = 0 AND @nQTY_REST <> 0
		SET @nPRICE = @nSUM_REST / @nQTY_REST

	SET @intACCOUNT = (SELECT LINK FROM dbo.S_ACCOUNTS WITH (NOLOCK) WHERE LINK = @intACCOUNT)
	SET @intNOMEN = (SELECT LINK FROM dbo.NOMENCLATURE WITH (NOLOCK) WHERE LINK = @intNOMEN)

	SET LOCK_TIMEOUT 30000
	SET @varKStrancount = @@TRANCOUNT
	SET IMPLICIT_TRANSACTIONS ON

	UPDATE dbo.OUT_TABLE_MZ_CHARGE
	SET 	
		ACCOUNT =	@intACCOUNT,
		NOMEN	=	@intNOMEN,
		QTY_REST = 	@nQTY_REST,
		QTY	=	@nQTY,
		SUMMA	=	@nSUMMA,
		PRICE	=	@nPRICE,
		PRICE_FACT	=	@nPRICE_FACT,
		SUM_REST	=	@nSUM_REST
	WHERE LINK_UP = @intLINK_UP

	SELECT
		@varKSRowCount = @@ROWCOUNT,
		@varKSERROR = @@ERROR
		
	IF @varKSERROR <> 0
	BEGIN
		ROLLBACK
		RETURN 7
	END

	IF @varKSRowCount = 0
	BEGIN
		INSERT INTO dbo.OUT_TABLE_MZ_CHARGE
			(LINK_UP,
			ACCOUNT,
			NOMEN,
			QTY_REST,
			QTY,
			SUMMA,
			PRICE,
			PRICE_FACT,
			SUM_REST)
		VALUES (@intLINK_UP,
			@intACCOUNT,
			@intNOMEN,
			@nQTY_REST,
			@nQTY,
			@nSUMMA,
			@nPRICE,
			@nPRICE_FACT,
			@nSUM_REST)

		SELECT @varKSRowCount = @@ROWCOUNT, @varKSERROR = @@ERROR

		IF @varKSERROR <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END

	IF @@TRANCOUNT > @varKStrancount
		COMMIT TRAN
	RETURN 0

END

GO


GRANT EXECUTE ON dbo.[BK_UPDATE_OUT_TABLE_MZ_CHARGE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BV_SAVE_G_PROV2_AP_AO_REP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BV_SAVE_G_PROV2_AP_AO_REP]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE	PROCEDURE dbo.BV_SAVE_G_PROV2_AP_AO_REP
	@varKSnLINK_GP1  INT,		
	@varKSnDT_LINK INT,			
	@varKSnKT_LINK  INT,			
	@varKSnEKR_DT INT =0,
	@varKSnEKR_KT INT =0,
	@varKSnEMP INT =0,
	@varKSnOSNOV INT =0,
	@varKSnINV INT =0,
	@varKSnNOMEN INT =0,
	@varKSnSUMMA	NUMERIC(28,2) = 0.00,
	@varKSnQTY	NUMERIC(19,4) = 0.0000,
	@varKSnKBK INT,
	@varKSnDEP INT,
	@varKSnSUB INT,
	@intAO_EMPL INT
	
AS

DECLARE 
--	@varKSnNOMEN INT,
--	@varKSnINV INT,
	@varKSnKAU INT,
	@varKSnDEP_ACC INT,
	@varKSnTMC INT,
	@varKSnINDATE DATETIME,
	@varKSnAP1 INT,
	@varKSnAP2 INT,
	@varKSnAP3 INT,
	@KBK_REST INT,


	@varKSnG2_LINK  INT,
	@varKScG2_NAME  VARCHAR(254),
	@varKSnG2_ECON_OPER INT,
	@varKSnG2_ORDERS INT,
	@varKSnLINK_GP2 INT,
	@varKSnSGU_DT INT,
	@varKSnSGU_KT INT,
	@varKSxRet INT,
	@intP_KASSA	TINYINT,
	@cSINTH		CHAR (3),
	
	@iDB_KR	TINYINT,
	@intEKR	INT,
	@intSGU	INT,
	@intACCOUNT	INT,
	@iP_EKR	INT,
	@iANALIT_EKR	INT,
	@intEMP_AP	INT,
	@KBK_AP INT,
	
	@ROWCOUNT	INT,
	@DATE_REST	DATETIME,
	@DEP_LINK	INT
	
	IF @varKSnLINK_GP1 IS NULL
		RETURN -1	

	-- Остатки --
	SELECT
		@DATE_REST	=	DATEADD (DAY, 1, G.[DATE]),
		@DEP_LINK	=	G.DEP
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV G ON (G.LINK = G1.LINK_UP)
	WHERE G1.LINK = @varKSnLINK_GP1
	
	SELECT TOP 1
		@varKSnKAU	=	T1.KAU,
		@varKSnAP1	=	T1.AP1,
		@varKSnAP2	=	T1.AP2,
		@KBK_REST		=	T1.KBK
	FROM dbo.ARestTableByDate (@DATE_REST, @varKSnKT_LINK) T1
	WHERE T1.DEP_LINK = @DEP_LINK
		AND T1.EMP = @intAO_EMPL
	
-- Берется первая хоз.операция , а надо бы вообще перевести грид авансового отчета на работу с хоз.операциями
SELECT TOP 1 @varKSnG2_ECON_OPER = T.LINK, @varKScG2_NAME = RTRIM(CONVERT(VARCHAR(254), XO.NAME))
FROM dbo.BX_BPROV_VIBOR_ECON_OPER(@varKSnDT_LINK,@varKSnKT_LINK) T, XOZ_OPER XO
WHERE XO.LINK = T.LINK
 
SET @varKSnG2_ORDERS = 1

SET @varKSnLINK_GP2 = NULL
EXEC @varKSxRet = dbo.X_UPDATE_G_PROV2 @varKSnLINK_GP2 OUTPUT, @varKSnLINK_GP1, NULL,
	@varKSnSumma, @varKSnQTY, 0, @varKScG2_NAME, @varKSnG2_ECON_OPER,  @varKSnG2_ORDERS
IF @varKSxRet <> 0
	RETURN @varKSxRet
IF @varKSnLINK_GP2 IS NULL
	RETURN -3	

SET @iDB_KR = 0

WHILE @iDB_KR < 2 
BEGIN
	IF @iDB_KR = 0 
		SELECT
			@intEKR = @varKSnEKR_DT,
			@intACCOUNT	= @varKSnDT_LINK,
			@KBK_AP	=	CASE
							WHEN ISNULL (@varKSnKBK, 0) = 0 THEN @KBK_REST
							ELSE @varKSnKBK
						END
	ELSE
		SELECT
			@intEKR = @varKSnEKR_KT,
			@intACCOUNT	= @varKSnKT_LINK,
			@KBK_AP	=	@KBK_REST

	SELECT
		@intP_KASSA = p_KASSA,
		@cSINTH = cSINTH,
		@iP_EKR	= P_EKR,
		@iANALIT_EKR = ANALIT_EKR 
	FROM dbo.S_ACCOUNTS
	WHERE LINK = @intACCOUNT

	IF @@ROWCOUNT > 0
	BEGIN
		IF @intP_KASSA = 1 AND @intEKR <> 0
			SET @intSGU = @intEKR
		ELSE
			SELECT TOP 1
				@intSGU = SGU_LINK
			FROM dbo.PLAN_ACCOUNTS_SGU
			WHERE ACCOUNT = @intACCOUNT
				AND DB_KR = @iDB_KR

		IF @iP_EKR = 1
			SET @intEKR = @iANALIT_EKR
			
		IF @cSINTH = '208'
			SET @intEMP_AP = @intAO_EMPL
		ELSE	
			SET @intEMP_AP = @varKSnEMP 
		
		EXEC @varKSxRet = dbo.X_UPDATE_G_PROV_AP @varKSnLINK_GP2, @iDB_KR, @intACCOUNT, @KBK_AP, @intEKR, @varKSnDEP,
					@varKSnSUB, @intEMP_AP, @varKSnNOMEN, @varKSnINV, @varKSnKAU,
					0, 0, NULL, @varKSnOSNOV, @varKSnAP2, 0, @intSGU
					
		IF @varKSxRet <> 0
			RETURN @varKSxRet

	END

/*
SELECT 
	@iDB_KR,
	(SELECT CODE FROM S_ACCOUNTS WHERE LINK = @intACCOUNT) AS ACCOUNT, 
	(SELECT CODE FROM KOSGU WHERE LINK = @intEKR) AS EKR, 
	(SELECT CODE FROM KOSGU WHERE LINK = @intSGU) AS SGU
*/
	SET @iDB_KR = @iDB_KR + 1
END


RETURN 0

GO


GRANT EXECUTE ON dbo.[BV_SAVE_G_PROV2_AP_AO_REP] TO PUBLIC

GO


--Расширенные свойства--

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SD_PAYS_EMPL_INDEX]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SD_PAYS_EMPL_INDEX]

GO

CREATE PROCEDURE dbo.SD_PAYS_EMPL_INDEX
@varKSStrReturn VARCHAR(150) OUTPUT,
 @LinkEmpl int,
 @LinkPays int,
 @DateBegin datetime,
 @Summa numeric(15,6) = 0,
 @ROUND_MODE tinyint = 1, --1 - не округлять, 2 - окр до 10 коп, 3 окр до руб, 4 окр до 10 руб, ...
 @roundFunction tinyint = 0 -- 0 - округлять, 1 - вниз, 2 - вверх
AS

--Параметры округления
SET @ROUND_MODE = COALESCE(@ROUND_MODE,1)
SET @roundFunction = COALESCE(@roundFunction,0)

DECLARE  
	@varKSNameEmpl Varchar(30),
	@varKSEventText Varchar(150),
	@varKSNamePays  Varchar(60),
	@varKSsoDictPE	int,	
	@varKSDate DATETIME,	
	@varKSSumma numeric(15,4),
	@LINK_KBK INT

SET @varKSNameEmpl = dbo.sd_GetEmplName(@LinkEmpl)
SELECT @varKSNamePays =  NAME FROM dbo.PAYS WHERE LINK = @LinkPays
SELECT @varKSsoDictPE = LINK  FROM S_OBJECTS WHERE CODE = 'DICTIONARY_PAYS_EMPL'

DECLARE @PART NUMERIC(18,2)
SET @PART = (CASE @ROUND_MODE 
				WHEN 1 THEN 0 --Не округлять
				WHEN 2 THEN 0.10 --Округлять до 10 копеек				
				WHEN 3 THEN 1 --Округлять до 1 рубля
				WHEN 4 THEN 5 --Округлять до 5 рублей
				WHEN 5 THEN 10 --Округлять до 10 рублей
				WHEN 6 THEN 50 --Округлять до 50 рублей
				WHEN 7 THEN 100 --Округлять до 100 рублей
				WHEN 8 THEN 1000 --Округлять до 1000 рублей
				WHEN 9 THEN 10000 --Округлять до 10000 рублей
				ELSE 0 --Не округлять
			END)

DECLARE @TABLE TABLE(LINK_EMPL INT,LINK_SOVM INT,LINK_PAYS INT,[DATE] DATETIME)

IF OBJECT_ID('TEMPDB..#PE','U') IS NOT NULL
	DROP TABLE #PE

CREATE TABLE #PE (LINK_EMPL INT, LINK_SOVM INT, LINK_PAYS INT, DATE_BEG DATETIME)

INSERT INTO #PE (LINK_EMPL, LINK_SOVM, LINK_PAYS, DATE_BEG)
SELECT LINK_EMPL, ISNULL(LINK_SOVM,0), LINK_PAYS, MAX(DATE)
FROM 
	dbo.PAYS_EMPL PE
WHERE
	PE.LINK_EMPL = @LinkEmpl
	AND
	PE.LINK_PAYS = @LinkPays
	AND
	PE.DATE <= @DateBegin
GROUP BY
	LINK_EMPL, ISNULL(LINK_SOVM,0), LINK_PAYS	
	
INSERT INTO dbo.PAYS_EMPL(LINK_EMPL,LINK_SOVM,LINK_PAYS,[DATE],SUMMA, LINK_KBK)
OUTPUT INSERTED.LINK_EMPL, INSERTED.LINK_SOVM, INSERTED.LINK_PAYS, INSERTED.[DATE] INTO @TABLE
SELECT 
	PE.LINK_EMPL, 
	PE.LINK_SOVM, 
	PE.LINK_PAYS, 
	@DateBegin, 
	NEW_SUMMA = dbo.SA_ROUND( (PE2.SUMMA * (1+@Summa/100)), @PART, @roundFunction), 
	ISNULL(@LINK_KBK,PE2.LINK_KBK)
FROM 
	#PE PE
	INNER JOIN dbo.PAYS_EMPL AS PE2 ON PE2.LINK_EMPL = PE.LINK_EMPL AND ISNULL(PE2.LINK_SOVM,0) = PE.LINK_SOVM AND PE2.LINK_PAYS = PE.LINK_PAYS AND PE2.[DATE] = PE.DATE_BEG
WHERE
	PE.DATE_BEG < @DateBegin	

UPDATE PE2 SET 
	PE2.SUMMA = dbo.SA_ROUND( (PE2.SUMMA * (1+@Summa/100)), @PART, @roundFunction), 
	LINK_KBK = ISNULL(@LINK_KBK,PE2.LINK_KBK)
OUTPUT INSERTED.LINK_EMPL, INSERTED.LINK_SOVM, INSERTED.LINK_PAYS, INSERTED.[DATE] INTO @TABLE	
FROM 
	#PE PE
	INNER JOIN dbo.PAYS_EMPL AS PE2 ON PE2.LINK_EMPL = PE.LINK_EMPL AND ISNULL(PE2.LINK_SOVM,0) = PE.LINK_SOVM AND PE2.LINK_PAYS = PE.LINK_PAYS AND PE2.[DATE] = PE.DATE_BEG
WHERE
	PE.DATE_BEG = @DateBegin	

IF EXISTS (SELECT * FROM @TABLE) BEGIN
	SET @varKSEventText = 'Индексация начисления: ('+ LTRIM(RTRIM(@varKSNamePays))+') ' +  RTRIM(LTRIM(@varKSNameEmpl)) + '  на  ' + LTRIM(RTRIM(STR(@Summa))) +'%' 
	EXECUTE WF_GENERATEEVENT 'Индексация начисления', @varKSEventText, @varKSsoDictPE, 'PAYS_EMPL'
END

GO


GRANT EXECUTE ON dbo.[SD_PAYS_EMPL_INDEX] TO PUBLIC

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_REP_ARCHE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_REP_ARCHE]

GO

CREATE   PROCEDURE [dbo].SA_REP_ARCHE @LINK_DOC INT
AS

DECLARE @REF_ARHE INT

Select 
	NUM_ARHE,  
	[PER_ARHE],
	NAME_EMPL,
	TAB_NUMER,
	SYST_PAY = CASE WHEN SYST_PAY = 2 THEN 'Почасовая система оплаты' else '' END,
	DATE1, 	DATE2, 	ITOGO_DNI,
	NAME_TYP = NAME_TYP_ARHE,
	CODE_PAY, NAME_PAY,
	DATE_BEGIN,
	TYP_PERIOD = 'Расчёт ' + CASE TYP_PERIOD WHEN 1 THEN 'по текущему месяцу'
						 WHEN 2 THEN 'по 2 предыдущим месяцам'
						 WHEN 3 THEN 'по 12 предыдущим месяцам'
				end
from dbo.DOCUMENTS_ADD_ARCHE where LINK = @LINK_DOC

-- информация о предыдущих больничных по той же причине
SELECT 
	DI.link, DI.NUMBER, DI.NAME_EMPL,
	DI.[DAYS],	DI.DATE1, DI.DATE2, DI.CODE_TYP_ARHE, DI.NAME_TYP_ARHE,
	DI.CODE_PAYS, DI.NAME_PAYS, DI.KIDS_FLAG, DI.PERS_KID,
	DI.FAMILY_NAME,DI.PERS_LINK		
FROM DOCUMENTS_ADD_ARCHE da 
	 INNER JOIN DIS di ON di.ref_empl = da.ref_empl
					   AND di.ref_typ_arhe = da.ref_typ_arhe
					   AND di.link_pays = da.ref_pay
					   AND year(di.date1) = year(da.date1)
					   AND di.date1 < da.date1
WHERE da.link = @LINK_DOC
UNION ALL -- если ничего не найдено
Select link = 0, number = '', name_empl = '', [days] = 0, date1 = '', date1 = '', 
	   CODE_TYP_ARHE = '', NAME_TYP_ARHE = '', CODE_PAYS = '', NAME_PAYS = '', KIDS_FLAG = 0, 
	   PERS_KID = '', FAMILY_NAME = '', PERS_LINK = 0
WHERE NOT EXISTS(SELECT DI.*		
				 FROM DOCUMENTS_ADD_ARCHE da 
				 INNER JOIN DIS di ON di.ref_empl = da.ref_empl
					   AND di.ref_typ_arhe = da.ref_typ_arhe
					   AND di.link_pays = da.ref_pay
					   AND year(di.date1) = year(da.date1)
					   AND di.date1 < da.date1
				 WHERE da.link = @LINK_DOC)

---начисление по видам оплат
DECLARE @COUNT_M INT
SET @COUNT_M = COALESCE((Select COUNT(DISTINCT PERIOD) from SDOC_ADIS_TABLE2 where LINK_UP = @LINK_DOC),0)

SET @COUNT_M = CASE WHEN @COUNT_M = 0 THEN 1 ELSE @COUNT_M END

DECLARE @SCRIPT1 VARCHAR(8000), 
	@I INT, 
	@DATE_BEGIN_RP DATETIME,
	@RP_SUMMA_PREM NUMERIC(18,2),
	@RP_SUMMA NUMERIC(18,2),
	@SR_PREM NUMERIC(18,2),
	@RP_DAYS INT,
	@RP_HOURS NUMERIC(18,2),
	@RP_DAYS_N INT,
	@RP_HOURS_N NUMERIC(18,2),
	@SUMMA_BASE0 NUMERIC(18,2),
	@ITOGO_DNI NUMERIC(18,2),
	@ITOGO_CH NUMERIC(18,2),
	@INSTRUCT TINYINT

SELECT  @SCRIPT1 = '', @I = 1, @DATE_BEGIN_RP = DATE_BEGIN,
	@RP_SUMMA_PREM = RP_SUMMA_PREM, @RP_SUMMA = RP_SUMMA, 
	@SR_PREM = SR_PREM, @RP_DAYS = RP_DAYS, @RP_HOURS = RP_HOURS,
	@RP_DAYS_N = RP_DAYS_N, @RP_HOURS_N = RP_HOURS_N,
	@SUMMA_BASE0 = ROUND(SUMMA_BASE0, 2 ,0), @ITOGO_DNI = ITOGO_DNI, @ITOGO_CH = ITOGO_CH,
	@INSTRUCT = INSTRUCT
FROM dbo.DOCUMENTS_ADD_ARCHE where LINK = @LINK_DOC

IF EXISTS (SELECT * FROM dbo.SDOC_ADIS_TABLE3 where LINK_UP = @LINK_DOC) BEGIN

	WHILE @I <= @COUNT_M AND @I <= 12
	BEGIN
		SET @SCRIPT1 = @SCRIPT1 
			+ ', N_' + RTRIM(LTRIM(CONVERT(VARCHAR(2),@I))) 
				+ CASE WHEN @INSTRUCT = 1 
						THEN 
							' = ''' 
							+ CASE MONTH(DATEADD(MONTH,@I-1,@DATE_BEGIN_RP))
								WHEN 1 THEN 'Янв.'
								WHEN 2 THEN 'Фев.'
								WHEN 3 THEN 'Мар.'
								WHEN 4 THEN 'Апр.'
								WHEN 5 THEN 'Май.'
								WHEN 6 THEN 'Июн.'
								WHEN 7 THEN 'Июл.'
								WHEN 8 THEN 'Авг.'
								WHEN 9 THEN 'Сен.'
								WHEN 10 THEN 'Окт.'
								WHEN 11 THEN 'Ноя.'
								WHEN 12 THEN 'Дек.'
							END 
							+ CONVERT(VARCHAR(4),YEAR(DATEADD(MONTH,@I-1,@DATE_BEGIN_RP)))
							+ ''''
						ELSE 
							' = ''' + CONVERT(VARCHAR(4),YEAR(@DATE_BEGIN_RP)+@I-1) + 'г.'''
					END		
			+ ', S_' + RTRIM(LTRIM(CONVERT(VARCHAR(2),@I)))  + ' = SUMMA' + RTRIM(LTRIM(CONVERT(VARCHAR(2),@I)))
		SET @I = @I + 1
	END

	SET @I = 1
	SET @SCRIPT1 = @SCRIPT1 + ', SUM_N = 0'
	WHILE @I <= @COUNT_M AND @I <= 12
	BEGIN
		SET @SCRIPT1 = @SCRIPT1 + '+ COALESCE(SUMMA' + RTRIM(LTRIM(CONVERT(VARCHAR(2),@I))) + ',0)'
		SET @I = @I + 1
	END

	SET @SCRIPT1 = 'Select ORDERS, LINK_PAY, NAME_PAY = ISNULL(P.NAME,''Заработок у других работодателей'') , LINK_KBK, CODE_KBK = KBK.CODE' + @SCRIPT1 
			+ ' from dbo.SDOC_ADIS_TABLE3 T3 LEFT JOIN dbo.PAYS P ON T3.LINK_PAY = P.LINK '
			+ ' LEFT JOIN dbo.SAL_SFIN KBK ON T3.LINK_KBK = KBK.LINK WHERE LINK_UP = ' 
		+ CONVERT(VARCHAR(20),@LINK_DOC) + ' ORDER BY ORDERS'
	exec (@SCRIPT1)
END
ELSE	--Если рассчитывали исходя из МРОТ
	Select ORDERS = 0, LINK_PAY = 0, NAME_PAY = '', LINK_KBK = 0, CODE_KBK = '', ORDERS = 0, N_1 = '', S_1 = 0, SUM_N = 0

---начисление по месяцам
Select 
	ORDERS, 
	PERIOD = CASE WHEN @INSTRUCT = 1 THEN 
					+ CASE MONTH(PERIOD)
						WHEN 1 THEN 'Янв.'
						WHEN 2 THEN 'Фев.'
						WHEN 3 THEN 'Мар.'
						WHEN 4 THEN 'Апр.'
						WHEN 5 THEN 'Май.'
						WHEN 6 THEN 'Июн.'
						WHEN 7 THEN 'Июл.'
						WHEN 8 THEN 'Авг.'
						WHEN 9 THEN 'Сен.'
						WHEN 10 THEN 'Окт.'
						WHEN 11 THEN 'Ноя.'
						WHEN 12 THEN 'Дек.'
					END 
					+ CONVERT(VARCHAR(4),YEAR(PERIOD))
				ELSE
					CONVERT(VARCHAR(4),YEAR(PERIOD)) + 'г.'
			END	, 
	SUMMA, SUMMA_PREM, DAYS, HOURS, DAYS_N, HOURS_N, CODE_KBK = KBK.CODE, 
	RP_S_PREM = @RP_SUMMA_PREM, RP_SUMMA = @RP_SUMMA, 
	RP_DAYS = @RP_DAYS, RP_HOURS = @RP_HOURS,
	RP_DAYS_N = @RP_DAYS_N, RP_HOURS_N = @RP_HOURS_N,
	SR_PREM = @SR_PREM, DSUM = @SUMMA_BASE0
from SDOC_ADIS_TABLE2 T2  LEFT JOIN dbo.SAL_SFIN KBK ON T2.LINK_KBK = KBK.LINK
where link_up = @LINK_DOC
UNION ALL --Если рассчитывали исходя из МРОТ
Select 0, NULL, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0
WHERE NOT EXISTS(SELECT * FROM dbo.SDOC_ADIS_TABLE2 WHERE link_up = @LINK_DOC)

---

Select @REF_ARHE = REF_DOC from dbo.SDOC_ADIS where LINK_UP = @LINK_DOC

DECLARE @CNT int, @TYP_CALC int, @DATE_R datetime, @DATE1 datetime, @DATE2 datetime
Select @CNT = CNT, @TYP_CALC = TYP_CALC, @DATE_R = DATE_R, @DATE1 = DATE1, @DATE2 = DATE2 from dbo.VAC_CHILD where LINK_R = @LINK_DOC

SET @CNT = COALESCE(@CNT,1)
SET @TYP_CALC = COALESCE(@TYP_CALC,2)

Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = case when @CNT = 1 then 'Первый ребенок' else 'Второй или последующий ребенок' end, summa = ''
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Дата рождения ребенка', summa = convert(varchar(20), @DATE_R, 104)
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Начало оплаты', summa = convert(varchar(20), @DATE1, 104)
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Завершение оплаты', summa = convert(varchar(20), @DATE2, 104)
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Сумма выплачивается ' + case @TYP_CALC 
																when 2 then 'пропорционально рабочим дням'
																when 3 then 'пропорционально календарным дням'
																else 'без учета дней' 
																end, summa = ''
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Мин. размер пособия по уходу за 1 ребенком', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT1')) where @CNT = 1
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Мин. размер пособия по уходу за 2 и более дет.', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT2'))  where @CNT >= 2
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Макс. размер пособия по уходу за 1 ребенком', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT3'))  where @CNT = 1
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Макс.  размер пособия по уходу за 2 и более дет.', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT4'))  where @CNT >= 2
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Ср.м. число кал. дней для расчета пособ.', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT5'))
UNION ALL
Select REF_ARHE = COALESCE(@REF_ARHE,0), [Name] = 'Процент заработка', summa = convert(varchar(20), dbo.sa_get_option_by_code('VAC_CHILD_OPT6'))

---начисление по больничному
Select ORDERS, DATE1, DATE2, SUM_LIMIT, DAYS, HOURS, SR_ZP, PERC, SUMMA, 
	PAYER = CASE WHEN  PAYER = 1 THEN 'Работодатель' else 'ФСС' end,
	CODE_KBK = KBK.CODE, ITOGO_DNI = @ITOGO_DNI, ITOGO_CH = @ITOGO_CH
from SDOC_ADIS_TABLE1 T2  LEFT JOIN dbo.SAL_SFIN KBK ON T2.LINK_KBK = KBK.LINK
where link_up = @LINK_DOC 

--ВЫВОД РАСШИФРОВКИ БАЗОВОЙ СУММЫ
DECLARE 
 @RefPay INT,
 @linkEmpl INT,
 @dDate1 DATETIME,
 @dDate2 DATETIME

SELECT 
	@RefPay = REF_PAY,
	@linkEmpl = REF_EMPL,
	@dDate1 = DATE_BEGIN,
	@dDate2 = DATEADD(MONTH,INSTRUCT*12,DATE_BEGIN) - 1
FROM 
	dbo.DOCUMENTS_ADD_ARCHE 
WHERE 
	LINK = @LINK_DOC

CREATE TABLE #BASE_SUM 
(
	CODE_PAYS VARCHAR(10), 
	NAME_PAYS VARCHAR(60),
	LINK_PAYS INT,
	LINK INT,
	SUMMA NUMERIC(18,2),
	[NAME_VKR] VARCHAR(20),
	MON TINYINT, 
	[YEAR] INT,  
	MON1 TINYINT, 
	YEAR1 INT
)

INSERT INTO #BASE_SUM (CODE_PAYS,NAME_PAYS,LINK_PAYS,LINK,SUMMA,NAME_VKR,MON,[YEAR],MON1,YEAR1)
EXECUTE [dbo].SALARY_BASE_SUM_PAY_EMPL @linkEmpl,@RefPay,@dDate1,@dDate2

IF EXISTS (SELECT * FROM #BASE_SUM)
	SELECT * FROM #BASE_SUM
ELSE
	SELECT CODE_PAYS = '',NAME_PAYS = '',LINK_PAYS = NULL,LINK = NULL,SUMMA = NULL,NAME_VKR = '',MON = NULL,[YEAR] = NULL,MON1 = NULL,YEAR1 = NULL



GO


GRANT EXECUTE ON dbo.[SA_REP_ARCHE] TO PUBLIC

GO


--Расширенные свойства--


GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BV_SAVE_G_PROV1_AVANSE_REP]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BV_SAVE_G_PROV1_AVANSE_REP]

GO

CREATE	PROCEDURE dbo.BV_SAVE_G_PROV1_AVANSE_REP
	@varKSnLINK_DOC INT,
	@varKSnDEL	TINYINT = 0	

AS

DECLARE 
--	@varKSnTYP_LINK INT,			
	@varKScNAME_OPER VARCHAR(250),
	@varKScNAME_DOC VARCHAR(100),
	@varKSnSUMMA NUMERIC(28,2),
	@varKSnQTY NUMERIC(19,4),
	@varKSnDT_LINK INT,
	@varKSnKT_LINK INT,
	@varKSnLINK_GP1 INT,
	@varKSnORDERS INT,
--	@varKSdCALC_DATE DATETIME,
	@varKSxRet	INT,
	@varKSnEKR_DT INT,
	@varKSnEKR_KT INT,
	@varKSnEMP INT,
	@varKSnOSNOV INT,
	@varKSnINV INT,
	@varKSnNOMEN INT,
	@varKScErrTxt VARCHAR(60),
	@intAO_EMPL INT,
	@intAO_KBK INT,
	@intAO_DEP INT,
	@intAO_SUB INT,
	@LINK_ROW	INT

DECLARE GRID_CUR CURSOR LOCAL STATIC READ_ONLY FOR
	SELECT
		LINK,
		NAMEDOC,
		SUMACCEPTED,
		DT,
		KT,
		EKR_LINK_DT,
		EKR_LINK_KT,
		EMP_LINK,
		OSNOV_LINK,
		CASE
			WHEN MZ_TYPE = 1 THEN MZ_LINK
			ELSE NULL
		END AS INV,
		CASE
			WHEN MZ_TYPE = 2 THEN MZ_LINK
			ELSE NULL
		END AS NOMEN,
		QTY
	FROM dbo.BK_DOC_TABLE_AO_FN (@varKSnLINK_DOC)
	WHERE SUMACCEPTED <> 0
		AND DTACCOUNT IS NOT NULL AND KTACCOUNT IS NOT NULL

SELECT 	@intAO_EMPL = EMP_LINK,
	@intAO_KBK = KBK_LINK,
	@intAO_DEP = DEP_LINK,
	@intAO_SUB = OTDEL_LINK
FROM dbo.BV_DOC_AVANSE_REP
WHERE LINK = @varKSnLINK_DOC

IF @varKSnLINK_DOC IS NULL OR @varKSnLINK_DOC <= 0
	RETURN -1	

IF @varKSnDEL = 1
  BEGIN
	PRINT 'Удаление существующих проводок'
	DELETE FROM G_PROV1 WHERE LINK_UP = @varKSnLINK_DOC
  END

SET @varKSnORDERS = 0

OPEN GRID_CUR
FETCH FROM GRID_CUR
	INTO @LINK_ROW,
		@varKScNAME_DOC,
		@varKSnSUMMA,
		@varKSnDT_LINK,
		@varKSnKT_LINK,
		@varKSnEKR_DT,
		@varKSnEKR_KT,
		@varKSnEMP,
		@varKSnOSNOV,
		@varKSnINV,
		@varKSnNOMEN,
		@varKSnQTY
		
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @varKSnORDERS = @varKSnORDERS + 1

	SET @varKScNAME_OPER = 'Содержание операции: ' + RTRIM(ISNULL(@varKScNAME_DOC,'информация отсутствует'))

	SET @varKSnLINK_GP1 = NULL
	EXEC dbo.X_UPDATE_G_PROV1 @varKSnLINK_GP1 OUTPUT, @varKSnLINK_DOC, NULL,
			@varKScNAME_OPER, @varKSnORDERS

	IF @varKSnLINK_GP1 IS NULL
		RETURN -3	
	SET @varKSnQTY = ISNULL(@varKSnQTY,0)
	EXEC @varKSxRet = dbo.BV_SAVE_G_PROV2_AP_AO_REP @varKSnLINK_GP1, @varKSnDT_LINK, @varKSnKT_LINK, @varKSnEKR_DT, @varKSnEKR_KT, @varKSnEMP, @varKSnOSNOV, @varKSnINV, @varKSnNOMEN, @varKSnSUMMA, @varKSnQTY,
		@intAO_KBK, @intAO_DEP, @intAO_SUB, @intAO_EMPL

	IF @varKSxRet <> 0
	  BEGIN
/*	    SET @varKScErrTxt = CASE @varKSxRet
				WHEN -1 THEN '"Не задан линк операции"'
				WHEN -2 THEN '"Не найден остаток по данному ОС"'
			   END */
	    PRINT 'Ошибка при записи проводки'
	    IF @varKSxRet = -2
		RETURN -5	
	    ELSE
		RETURN -4	
	  END

	UPDATE OTR
	SET LINK_OPER = @varKSnLINK_GP1
	FROM dbo.OUT_TABLE_ROW OTR
	WHERE OTR.LINK = @LINK_ROW

	FETCH NEXT FROM GRID_CUR
		INTO @LINK_ROW,
			@varKScNAME_DOC,
			@varKSnSUMMA,
			@varKSnDT_LINK,
			@varKSnKT_LINK,
			@varKSnEKR_DT,
			@varKSnEKR_KT,
			@varKSnEMP,
			@varKSnOSNOV,
			@varKSnINV,
			@varKSnNOMEN,
			@varKSnQTY

END

CLOSE GRID_CUR
DEALLOCATE GRID_CUR

EXEC dbo.X_SALDO_COMMITCHANGES	

RETURN 0

GO

GRANT EXECUTE ON dbo.[BV_SAVE_G_PROV1_AVANSE_REP] TO PUBLIC

GO


--Расширенные свойства--


GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SD_N_BOL_SEARCH]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SD_N_BOL_SEARCH]
GO

/*
© Кейсистемс (Keysystems), 2005
*/
CREATE PROCEDURE SD_N_BOL_SEARCH @DocLink int
AS

DECLARE @RefDoc int, @I int

SET @I = 0
SELECT @RefDoc = REF_DOC FROM dbo.DIS WHERE LINK = @DocLink
WHILE @RefDoc>0 and @I <100
BEGIN
	SET @I = @I+1
	SET @DocLink = @RefDoc
	SELECT @RefDoc = REF_DOC FROM dbo.DIS WHERE LINK = @DocLink
END

DECLARE @BEGIN_RP DATETIME
SELECT TOP 1 @BEGIN_RP = dbo.ConvertDMY2Date(1,1,dbo.IS_MIN(YEAR1, YEAR2)) 
FROM dbo.DIS D INNER JOIN dbo.VAC_PERIOD_CHANGE C ON C.LINK_EMPL = D.REF_EMPL
WHERE D.LINK = @DocLink AND D.DATE1 BETWEEN C.DATE1 AND C.DATE2

SELECT *, BEGIN_RP = @BEGIN_RP FROM dbo.DIS WHERE LINK = @DocLink

GO

GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BB_UPDATE_GZ_DOC_TABLE]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BB_UPDATE_GZ_DOC_TABLE]

GO

/*
© Кейсистемс (Keysystems), 2005
*/

CREATE	PROCEDURE [dbo].BB_UPDATE_GZ_DOC_TABLE
	@iLink		int	output,
	@iLinkUp	int,
	@iRecordNo	int,
	@iKBK		int,
	@iEKR		int,
	@iDopCl		int,
	@iOKDP		int,
	@iOKPD		int,
	@nQuantity	numeric(19,4),
	@nCost		numeric(19,4),
	@nSumma		numeric(19,2)
as
Declare @iError		int,
	@iRowCount	int,
	@iTranCount	int

SET @iTranCount = @@TRANCOUNT
set implicit_transactions on
	if @iLink is null OR @iLink = 0
	BEGIN
		INSERT INTO dbo.GZ_DOC_TABLE(LINK_UP, RECORD_NO, KBK, EKR, DOP_CL, OKDP, OKPD, QUANTITY, COST, SUMMA)
			VALUES (@iLinkUp, @iRecordNo, @iKBK, @iEKR, @iDopCl, @iOKDP, @iOKPD, @nQuantity, @nCost, @nSumma)
		SELECT @iError = @@ERROR, @iLink = @@IDENTITY
		IF @iError <> 0
		BEGIN
			ROLLBACK
			RETURN 7
		END
	END
	ELSE
	BEGIN
		UPDATE 	dbo.GZ_DOC_TABLE
		SET 	LINK_UP	     = @iLinkUp,
			RECORD_NO    = @iRecordNo,
			KBK 	     = @iKBK,
			EKR 	     = @iEKR,
			DOP_CL       = @iDopCl,
			OKDP = @iOKDP,
			OKPD = @iOKPD, 
			QUANTITY     = @nQuantity, 
			COST	     = @nCost,
			SUMMA  	     = @nSumma
		where LINK = @iLink
		select @iError = @@ERROR, @iRowCount = @@ROWCOUNT
		if @iError <> 0
		begin
			rollback
			return 7
		end
		if @iRowCount = 0
		begin
			rollback
			return 2
		end
	end
if @@TRANCOUNT > @iTranCount
	commit tran
return 0



GO


GRANT EXECUTE ON dbo.[BB_UPDATE_GZ_DOC_TABLE] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[BK_REPORT_CARD_MZ]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[BK_REPORT_CARD_MZ]

GO
--- Отчет: Карточка\книга складского учета ---
CREATE PROCEDURE dbo.BK_REPORT_CARD_MZ
	@dDate_Open DATETIME,	-- Начало расч. периода --
	@dDate_Close DATETIME,	-- Конец расч. периода --
	@nOption1 INT,	-- Отчет --
	@cVal_Emp VARCHAR (1), @iEMP_OTBOR	INT
AS
BEGIN
	DECLARE
		@intACCT_105	INT,
		@varKSDEP_LINK INT,
		@intSVOD_ZB	INT,		
		@strORGNAME	VARCHAR (254),
		@strOKPO	VARCHAR (50),
		@dDATE_REST_END	DATETIME

	SELECT @intACCT_105 = LINK FROM dbo.S_ACCOUNTS WHERE CODE = '105'
--
	DECLARE @TAB_OBOROT TABLE (
		DOC_LINK INT, EMP INT, NOMEN INT,
		DEP_KOR INT, EMP_KOR INT,
		TYPE_KOR TINYINT, 	-- 1- Орг-ция, 2 - Сотрудник
		TYPE_PRICE TINYINT, PRICE NUMERIC (20, 6),
		D_QTY NUMERIC (28,4), D_SUMMA NUMERIC (28,4),
		K_QTY NUMERIC (28,4), K_SUMMA NUMERIC (28,4),
		DEP_LINK	INT)

	SELECT @intSVOD_ZB = 0	-- ЗАГЛУШКА ДЛЯ СВОДНОГО ОТЧЕТА

	IF @intSVOD_ZB = 0	-- Сводный отчет не требуется --
		SET @varKSDEP_LINK = ISNULL (dbo.BK_GetDepZB (), dbo.GetOwnDepLink ())

/*
	IF LEN(@varKScVal1)>0 BEGIN
		INSERT INTO @EMP
			SELECT OVR.RECORD, D.TAB, D.[NAME_EMPL], D.POST_NAME
			FROM OBJECT_VAR_EMPL OVR, KU_EMPL_PLACING D
			WHERE D.LINK=OVR.RECORD AND OVR.LINK_UP=@varKSnOtborLink1
	END
	ELSE
	BEGIN
		INSERT INTO @EMP
			SELECT D.LINK, D.TAB, D.[NAME_EMPL], D.POST_NAME FROM KU_EMPL_PLACING D
		INSERT INTO @EMP VALUES (0, '', 'Не указан', '')
	END

*/
	-- Отбор сотрудников --
	DECLARE @TAB_EMP TABLE
		(EMP INT,
		EMP_CODE  VARCHAR(20),
		EMP_NAME VARCHAR(254),
		EMP_POST VARCHAR (254))

	IF LEN (@cVal_Emp) > 0
		INSERT INTO @TAB_EMP
		SELECT
			D.LINK,
			D.TAB,
			D.NAME_EMPL,
			D.POST_NAME
		FROM dbo.KU_EMPL_PLACING D
		INNER JOIN dbo.OBJECT_VAR_EMPL OVR ON 
			(OVR.LINK_UP = @iEMP_OTBOR
			AND OVR.RECORD = D.LINK)
	ELSE
		INSERT INTO @TAB_EMP
		SELECT
			D.LINK,
			D.TAB,
			D.NAME_EMPL,
			D.POST_NAME
		FROM dbo.KU_EMPL_PLACING D

		UNION ALL
		
		SELECT 0, '', 'Не указан', ''
	
--		WHERE OVR.

-- SELECT * FROM @TAB_EMP
		
--	@cVal_Emp VARCHAR (1), @iEMP_OTBOR	INT

	--- Обороты ---
	INSERT INTO @TAB_OBOROT
	SELECT
		T1.LINK_DOC,
		ISNULL (T1.EMP, 0),
		ISNULL (T1.NOMEN, 0),
		CASE WHEN SA_KOR.AP_DEP = 1 THEN GAP_KOR.DEP ELSE 0 END,
		CASE WHEN SA_KOR.AP_EMP = 1 THEN GAP_KOR.EMP ELSE 0 END,
		CASE
			WHEN SA_KOR.AP_EMP = 1 THEN 2
			WHEN SA_KOR.AP_DEP = 1 THEN 1
		ELSE 0 END,
		T1.PRICE_TYPE,
		T1.PRICE,
		CASE WHEN T1.DB_KR = 0 THEN T1.QTY ELSE 0 END,
		CASE WHEN T1.DB_KR = 0 THEN T1.SUMMA ELSE 0 END,
		CASE WHEN T1.DB_KR = 1 THEN T1.QTY ELSE 0 END,
		CASE WHEN T1.DB_KR = 1 THEN T1.SUMMA ELSE 0 END,
		T1.DEP_LINK
	FROM dbo.BK_GetTableOborotByDate1
				(@dDate_Open,
				@dDate_Close,
				DEFAULT,
				@intACCT_105,
				@varKSDEP_LINK) T1
	LEFT JOIN dbo.G_PROV_AP GAP_KOR ON (GAP_KOR.LINK_UP = T1.LINK_G2
		AND (T1.DB_KR = 0 AND GAP_KOR.DB_KR = 1
			OR T1.DB_KR = 1 AND GAP_KOR.DB_KR = 0)) 
	LEFT JOIN dbo.S_ACCOUNTS SA_KOR ON (SA_KOR.LINK = GAP_KOR.ACCOUNT)

	DECLARE @TAB_DEP TABLE (DEP_LINK INT)
	
	IF @varKSDEP_LINK IS NULL
		INSERT INTO @TAB_DEP
		SELECT LINK
		FROM dbo.DEPARTMENTS
		WHERE ZB = 1 OR TYPE = 4
	ELSE
		INSERT INTO @TAB_DEP
		SELECT @varKSDEP_LINK

	--- Остатки ---
	DECLARE @TAB_REST_IN TABLE
		(EMP INT,
		NOMEN INT,
		DEP_LINK	INT,
--		TYPE_PRICE TINYINT, PRICE NUMERIC (20, 6),
		QTY NUMERIC (28,4), SUMMA NUMERIC (28,4))

	INSERT INTO @TAB_REST_IN
	SELECT
		ISNULL (R.EMP, 0),
		ISNULL (R.NOMEN, 0),
		R.DEP_LINK,
		SUM (R.D_QUANTITY),
		SUM (R.D_SUMMA)
	FROM dbo.ARestTableByDate (@dDate_Open, @intACCT_105) R
	INNER JOIN @TAB_DEP D ON (D.DEP_LINK = R.DEP_LINK)
	GROUP BY
		ISNULL (R.EMP, 0),
		ISNULL (R.NOMEN, 0),
		R.DEP_LINK
	HAVING
		SUM (R.D_QUANTITY) <> 0
		OR SUM (R.D_SUMMA) <> 0
		
	DECLARE @TAB_REST_OUT TABLE
		(EMP INT,
		NOMEN INT,
		DEP_LINK	INT,
--		TYPE_PRICE TINYINT, PRICE NUMERIC (20, 6),
		QTY NUMERIC (28,4), SUMMA NUMERIC (28,4))

	SET @dDATE_REST_END = DATEADD (DAY, 1, @dDate_Close)

	INSERT INTO @TAB_REST_OUT
	SELECT
		ISNULL (R.EMP, 0),
		ISNULL (R.NOMEN, 0),
		R.DEP_LINK,
		SUM (R.D_QUANTITY),
		SUM (R.D_SUMMA)
	FROM dbo.ARestTableByDate (@dDATE_REST_END, @intACCT_105) R
	INNER JOIN @TAB_DEP D ON (D.DEP_LINK = R.DEP_LINK)
	GROUP BY
		ISNULL (R.EMP, 0),
		ISNULL (R.NOMEN, 0),
		R.DEP_LINK
	HAVING
		SUM (R.D_QUANTITY) <> 0
		OR SUM (R.D_SUMMA) <> 0

	IF @varKSDEP_LINK IS NULL
		SET @varKSDEP_LINK = dbo.GetOwnDepLink () 

	-- Итоговая таблица --
	DECLARE @TAB_GRP TABLE
		(EMP INT,
		NOMEN INT,
		DEP_LINK INT)

	INSERT INTO @TAB_GRP
		(EMP,
		NOMEN,
		DEP_LINK)
	SELECT
		EMP,
		NOMEN,
		DEP_LINK
	FROM @TAB_OBOROT

	UNION
	
	SELECT
		EMP,
		NOMEN,
		DEP_LINK
	FROM @TAB_REST_IN

	UNION
	
	SELECT
		EMP,
		NOMEN,
		DEP_LINK
	FROM @TAB_REST_OUT

-- SELECT * FROM @TAB_GRP

	-- Результат --
	SELECT @strORGNAME = RTRIM ([NAME]) +
			CASE
				WHEN @intSVOD_ZB = 1 THEN ' (ЦБ).'
				ELSE ''
			END,
		@strOKPO = OKPO
	FROM dbo.DEPARTMENTS
	WHERE LINK = @varKSDEP_LINK

	SELECT
		CONVERT (VARCHAR (10), G.DATE_PROV, 104) AS DATE_PROV,
		CONVERT (VARCHAR (10), G.[DATE], 104) AS DOC_DATE,
		G.NUMBER AS DOC_NUM,
		NOMEN.CODE AS INV_CODE,
		NOMEN.[NAME] AS INV_NAME,
		UM.CODE AS UM_CODE,
		UM.[NAME] AS UM_NAME,
		T1.*,

		OB.DOC_LINK, 
		OB.DEP_KOR, OB.EMP_KOR,
		OB.TYPE_KOR,
		OB.TYPE_PRICE, OB.PRICE,
		OB.D_QTY, OB.D_SUMMA,
		OB.K_QTY, OB.K_SUMMA,
			
		CASE 
			WHEN OB.TYPE_KOR = 1 THEN DEP_KOR.[NAME]
			WHEN OB.TYPE_KOR = 2 THEN EMP_KOR.[NAME_EMPL]
		END AS KORR_NAME,
		CONVERT (VARCHAR (10), @dDate_Open, 104) AS DATE_OPEN,
		CONVERT (VARCHAR (10), @dDate_Close, 104) AS DATE_CLOSE,
		EMP.TAB AS EMP_CODE,
		EMP.NAME_EMPL AS EMP_NAME,
		@strORGNAME AS ORGNAME,
		@strOKPO AS OKPO,
		CONVERT (VARCHAR (20), ISNULL (T1.EMP, 0))
		+ '#' + CONVERT (VARCHAR (20), ISNULL (T1.NOMEN, 0)) AS GRP_CARD,
		ISNULL (R_IN.QTY, 0.00) AS IN_QTY,
		ISNULL (R_IN.SUMMA, 0.00) AS IN_SUMMA,
		ISNULL (R_OUT.QTY, 0.00) AS OUT_QTY,
		ISNULL (R_OUT.SUMMA, 0.00) AS OUT_SUMMA
	FROM @TAB_GRP T1
	INNER JOIN @TAB_EMP E1 ON (E1.EMP = T1.EMP)
	LEFT JOIN @TAB_OBOROT OB ON 
		(OB.EMP = T1.EMP
		AND OB.NOMEN = T1.NOMEN
		AND OB.DEP_LINK = T1.DEP_LINK)
	LEFT JOIN dbo.G_PROV G ON (G.LINK = OB.DOC_LINK)
	INNER JOIN dbo.NOMENCLATURE NOMEN ON (NOMEN.LINK = T1.NOMEN)
	LEFT JOIN dbo.DEPARTMENTS DEP_KOR ON (OB.TYPE_KOR = 1
		AND DEP_KOR.LINK = OB.DEP_KOR)
	LEFT JOIN dbo.KU_EMPL_PLACING EMP_KOR ON (OB.TYPE_KOR = 2
		AND EMP_KOR.LINK = OB.EMP_KOR)
--		OR OB.TYPE_KOR = 2)
	LEFT JOIN dbo.DICTIONARY_DIGIT UM ON (UM.LINK = NOMEN.UM)
	LEFT JOIN dbo.KU_EMPL_PLACING EMP ON (EMP.LINK = OB.EMP)
	LEFT JOIN @TAB_REST_IN R_IN ON
		(R_IN.EMP = T1.EMP
		AND R_IN.NOMEN = T1.NOMEN
		AND R_IN.DEP_LINK = T1.DEP_LINK)
	LEFT JOIN @TAB_REST_OUT R_OUT ON
		(R_OUT.EMP = T1.EMP
		AND R_OUT.NOMEN = T1.NOMEN
		AND R_OUT.DEP_LINK = T1.DEP_LINK)
	ORDER BY
		OB.EMP,
		OB.NOMEN,
		G.[DATE]

	
-- EXEC dbo.BK_REPORT_CARD_MZ '20130101', '20131231', 0
END

GO


GRANT EXECUTE ON dbo.[BK_REPORT_CARD_MZ] TO PUBLIC

GO



GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[SA_FOT_NLIST]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE dbo.[SA_FOT_NLIST]

GO

CREATE  PROC [dbo].[SA_FOT_NLIST] (
	@PERIODBEGIN DATETIME, @PERIODEND DATETIME, /* ПЕРИОД */
	@VNS TINYINT = 1 /* ВКЛЮЧАТЬ ВНЕШНИХ СОВМЕСТИТЕЛЕЙ */,
	--ФИЛЬТРЫ
	@CVAL1 CHAR(1), @NOTBORLINK1 INT	/* ОТБОР СОТРУДНИКОВ */,
	@CVAL2 CHAR(1), @NOTBORLINK2 INT	/* ОТБОР ВИДОВ НАЧИСЛЕНИЙ */,
	@CVAL3 CHAR(1), @NOTBORLINK3 INT	/* ОТБОР ДОЛЖНОСТЕЙ */--,
	) AS

SET NOCOUNT ON

DECLARE @DEP_LINK INT
SELECT @DEP_LINK = DBO.GETCBDEPLINK()


----------------------------------------------
CREATE TABLE #STO_TAR_EMPL (LINK INT, LINK_EMPL INT, FIO VARCHAR(254), TAB VARCHAR(10), PERS_LINK INT, DATE_BEGIN DATETIME,
	DATE_END DATETIME, LINK_POST INT, POST_NAME VARCHAR(254), INST_CHIEF_ACC TINYINT, LINK_KATEG INT, KATEG_NAME VARCHAR(254),
	RAZR_BASE VARCHAR(10), INC_ETS1 TINYINT, INC_ETS1_NAME  VARCHAR(254), INC_ETS1_VALUE TINYINT, INC_ETS2 TINYINT, INC_ETS2_NAME VARCHAR(254),
	INC_ETS2_VALUE TINYINT, INC_ETS3 TINYINT, INC_ETS3_NAME VARCHAR(254), INC_ETS3_VALUE TINYINT, RAZR VARCHAR(10), IRAZR INT,
	DEP_LINK INT, NUM_STAKE NUMERIC(18,2), LINK_KBK  INT, SUBDIV_HEAD INT, SUBDIV_NAME  VARCHAR(254),[STATUS] TINYINT, LINK_TYPE INT, CODE_TYPE VARCHAR(4))

INSERT INTO #STO_TAR_EMPL ( LINK, LINK_EMPL, FIO, TAB, PERS_LINK, DATE_BEGIN, 
	DATE_END, LINK_POST, POST_NAME, INST_CHIEF_ACC, LINK_KATEG, KATEG_NAME,
	RAZR_BASE, INC_ETS1, INC_ETS1_NAME, INC_ETS1_VALUE, INC_ETS2, INC_ETS2_NAME, 
	INC_ETS2_VALUE, INC_ETS3, INC_ETS3_NAME, INC_ETS3_VALUE, RAZR, IRAZR,
	DEP_LINK, NUM_STAKE, LINK_KBK, SUBDIV_HEAD, SUBDIV_NAME, [STATUS], LINK_TYPE, CODE_TYPE)

SELECT 	LINK, LINK_EMPL, FIO, TAB, PERS_LINK, DATE_BEGIN, 
	DATE_END, LINK_POST, POST_NAME, INST_CHIEF_ACC, LINK_KATEG, KATEG_NAME,
	CONVERT(VARCHAR(10),RAZR_BASE), INC_ETS1, INC_ETS1_NAME, INC_ETS1_VALUE, INC_ETS2, INC_ETS2_NAME, 
	INC_ETS2_VALUE, INC_ETS3, INC_ETS3_NAME, INC_ETS3_VALUE, CONVERT(VARCHAR(10),RAZR), RAZR,
	DEP_LINK, T.NUM_STAKE, LINK_KBK, SUBDIV_HEAD, SUBDIV_NAME, COALESCE([STATUS],1), T.LINK_TYPE, T.CODE_TYPE
FROM 
	DBO.SA_EMPLS_W_FN(DEFAULT, @PERIODBEGIN, DEFAULT, @DEP_LINK) T
	LEFT JOIN DBO.EMPL_STATUS(@PERIODBEGIN) S ON S.EMPL_LINK = LINK_EMPL
WHERE

	DEP_LINK = @DEP_LINK
	--НЕ ВКЛЮЧАТЬ ВНЕШНИХ СОВМЕСТИТЕЛЕЙ,ВКЛЮЧАТЬ ВНЕШНИХ СОВМЕСТИТЕЛЕЙ,ВКЛЮЧАТЬ ТОЛЬКО ВНЕШНИХ СОВМЕСТИТЕЛЕЙ
	AND (@VNS = 1 AND COALESCE([STATUS],1) <> 3 OR @VNS = 2 OR @VNS = 3 AND COALESCE([STATUS],1) = 3 ) 
	AND @PERIODBEGIN BETWEEN T.DATE_BEGIN AND COALESCE(T.DATE_END, @PERIODBEGIN)
	AND (	--ОТБОР СОТРУДНИКОВ
		@CVAL1 <> '' AND LINK_EMPL IN (SELECT RECORD FROM DBO.OBJECT_VAR_EMPL WHERE LINK_UP = @NOTBORLINK1)
		OR
		@CVAL1 = '' )
	AND (	--ОТБОР СОТРУДНИКОВ
		@CVAL3 <> '' AND LINK_POST IN (SELECT RECORD FROM DBO.OBJECT_VAR_POST WHERE LINK_UP = @NOTBORLINK3)
		OR
		@CVAL3 = '' )	

-------------------------------------------
DECLARE @BUFF_ID VARCHAR(20)
EXEC X_GET_TABLE_NAME @BUFF_ID OUTPUT
	
INSERT INTO DBO.BUFFER (ID, LINK)
SELECT DISTINCT @BUFF_ID, LINK_EMPL
	FROM #STO_TAR_EMPL


----------------------------------------------
CREATE TABLE #ALL_PAYS_TAR_EMPL ( LINK_EMPL INT, LINK_TAR_EMPL INT, LINK_LES INT, LINK_PAY INT, NAME_PAY VARCHAR(254) , PERC NUMERIC(18,4), SUMMA NUMERIC(18,4), LINK_KBK INT, WAY_CALC INT, LINK_ETS INT, ISPERCENT INT , ISPERCENT_NAME VARCHAR(10))	
INSERT INTO #ALL_PAYS_TAR_EMPL ( LINK_EMPL, LINK_TAR_EMPL, LINK_LES, LINK_PAY, NAME_PAY, PERC, SUMMA, LINK_KBK, WAY_CALC, LINK_ETS, ISPERCENT, ISPERCENT_NAME)
SELECT 
	PTE.LINK_EMPL, 
	PTE.LINK_SOVM, 
	LINK_LES = NULL, 
	PTE.LINK_PAY, 
	p.NAME, 
	PTE.PERC,  
	SUM(PTE.SUMMA), 
	PTE.LINK_KBK, 
	P.WAY_CALC , 
	P.LINK_ETS, 
	ISPERCENT =  WC.ISPERCENT,
	ISPERCENT_NAME = CASE  WC.ISPERCENT WHEN 0 THEN 'СУММА' 
										WHEN 1 THEN 'ПРОЦЕНТ' 
										WHEN 2 THEN 'КОЭФ.ЕТС' 
										WHEN 3 THEN 'КОЭФ.ПКГ' 
										WHEN 4 THEN 'КОЭФ.' 
					END
FROM 
	DBO.SA_ALL_PAYS_ALL0(DEFAULT, @PERIODBEGIN, @BUFF_ID, @DEP_LINK, DEFAULT) PTE
	INNER JOIN  DBO.PAYS P ON PTE.LINK_PAY = P.LINK
	INNER JOIN 	DBO.WAY_CALC WC ON WC.CODE = P.WAY_CALC
	
WHERE
	(@CVAL2 <> '' AND PTE.LINK_PAY IN (SELECT RECORD FROM [DBO].[OBJECT_VAR_PAYS] WHERE LINK_UP = @NOTBORLINK2)
	OR
	@CVAL2 = '' )
	and WC.[TYPE] = 1
GROUP BY 
	PTE.LINK_EMPL, PTE.LINK_SOVM, PTE.LINK_PAY, PTE.PERC,  PTE.LINK_KBK, P.WAY_CALC, P.LINK_ETS , P.NAME, WC.ISPERCENT



select TE.LINK, TE.LINK_EMPL, TE.FIO, TE.TAB,TE.PERS_LINK, TE.LINK_POST,te.POST_NAME,SUB_HEAD = te.SUBDIV_HEAD,SUB_NAME = TE.SUBDIV_NAME,SFIN.LINK_PAY,SFIN.NAME_PAY, VALUE = (CASE WHEN SFIN.ISPERCENT <>0 THEN  SFIN.PERC ELSE  SFIN.SUMMA END ), ISPERC = SFIN.ISPERCENT_NAME, SFIN.SUMMA
from
#STO_TAR_EMPL AS TE
LEFT JOIN DBO.PERSON AS PERS ON TE.PERS_LINK = PERS.LINK
inner JOIN ( -- ВСЕ СТОЧНИКИ ЗА ПЕРИОД
			SELECT DISTINCT /*PTE.LINK_EMPL, LINK_SOVM = PTE.LINK_TAR_EMPL, LINK_KBK, LINK_ETS*/ LINK_EMPL, LINK_SOVM = PTE.LINK_TAR_EMPL, LINK_LES, LINK_PAY, NAME_PAY, PERC, SUMMA, LINK_KBK, WAY_CALC, LINK_ETS, ISPERCENT,ISPERCENT_NAME
			FROM #ALL_PAYS_TAR_EMPL AS PTE ) AS SFIN ON SFIN.LINK_EMPL = TE.LINK_EMPL AND SFIN.LINK_SOVM = TE.LINK
AND ((select IS_MEMBER ('Зарплата-КС')) = 1	or (select IS_MEMBER ('db_owner')) = 1)	
ORDER BY SFIN.LINK_PAY,TE.FIO



SET NOCOUNT OFF


RETURN 0



GO


GRANT EXECUTE ON dbo.[SA_FOT_NLIST] TO PUBLIC

GO



GO

--AFTER CODE 21.01.2015
-- Измение плана счетов по 98Н --
WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO

DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

IF dbo.BS_GetWorkMode (@BUF_NAME) = 0
BEGIN
	--- Формирование плана счетов при переходе на новый учет ---
	EXEC dbo.XK_CREATE_NEW_PLAN_ACCOUNTS @BUF_NAME

	--- Настройка плана счетов при переходе на новый учет ---
	EXEC dbo.XK_NASTR_NEW_PLAN_ACCOUNTS @BUF_NAME

	--- Настройка счетов на КОСГУ ---
	EXEC dbo.XK_NASTR_S_ACCOUNTS_KOSGU
		@intLINK_ACCT	= NULL,
		@BUF_NAME	= @BUF_NAME,
		@iTYPE_REC	= 3,
		@intDEP_LINK = NULL

	-- Установка флага завершения перехода --
	EXEC dbo.BS_SetWorkMode
		@WORK_MODE = @BUF_NAME,
	  	@WORK_STATUS =	10
END

GO

WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO


GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'Справочник счетов ОС, НМА, НПА', 38, (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DICTION_REPORTS_ACCT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='DICTIONARY_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DICT_SUBACCOUNTS_OS_NMA_NPA', NAME = 'Справочник счетов ОС, НМА, НПА', ORDERS = '38', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DICTION_REPORTS_ACCT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='DICTIONARY_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='DICT_SUBACCOUNTS_OS_NMA_NPA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DICT_ACCT_OS_NMA_NPA _MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DICT_ACCT_OS_NMA_NPA _MARKER', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DICT_ACCT_OS_NMA_NPA _MARKER', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DICT_ACCT_OS_NMA_NPA _MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DICT_ACCT_OS_NMA_NPA _CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DICT_ACCT_OS_NMA_NPA _CODE', 'Субсчет', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DICT_ACCT_OS_NMA_NPA _CODE', NAME = 'Субсчет', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DICT_ACCT_OS_NMA_NPA _CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DICT_ACCT_OS_NMA_NPA _NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DICT_ACCT_OS_NMA_NPA _NAME', 'Наименование субсчета', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DICT_ACCT_OS_NMA_NPA _NAME', NAME = 'Наименование субсчета', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='DICT_SUBACCOUNTS_OS_NMA_NPA'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DICT_ACCT_OS_NMA_NPA _NAME'
GO
EXEC X_SET_PROP 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'SELECT_RECORDS_METHOD', 'SQL.EXEC( "EXEC BK_GET_OTBOR_ACCOUNTS1 ''101,102,103,108'', '';;;01,02,03,51,52,54'', ''" + m.cFields + "''", m.cAlias)'
GO
EXEC X_SET_PROP 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'SELECT_RECORDS_METHOD_EDIT', ''
GO
EXEC X_SET_PROP 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'MSG_SEL_ALL', '[Отобраны все субсчета]'
GO
EXEC X_SET_PROP 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'MSG_SEL_ONE', 'CODE + [-] + NAME'
GO
EXEC X_SET_PROP 'DICT_SUBACCOUNTS_OS_NMA_NPA', 'SERVER_TABLE_NAME', 'S_ACCOUNTS'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _MARKER', 'VISIBLE', '9'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _MARKER', 'CONTROLSOURCE', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _MARKER', 'SHORT_CODE_OBJ', 'CHECKED'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _CODE', 'TITLE', 'Субсчет'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _CODE', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _CODE', 'CONTROLSOURCE', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _CODE', 'SHORT_CODE_OBJ', 'CODE'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _NAME', 'TITLE', 'Наименование субсчета'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _NAME', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _NAME', 'CONTROLSOURCE', 'm.cALias+".NAME"'
GO
EXEC X_SET_PROP 'DICT_ACCT_OS_NMA_NPA _NAME', 'SHORT_CODE_OBJ', 'NAME'
GO



GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='OTBOR_QUERY_SQL_ACCT_NMA_NPA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'OTBOR_QUERY_SQL_ACCT_NMA_NPA', 'Отбор субсчетов ОС, НМА, НПА', 84, (SELECT LINK FROM S_OBJECTS WHERE CODE='QUERY_OTBOR_CATALOG'), (SELECT LINK FROM S_OBJECTS WHERE CODE='QUERY_OTBOR_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'OTBOR_QUERY_SQL_ACCT_NMA_NPA', NAME = 'Отбор субсчетов ОС, НМА, НПА', ORDERS = '84', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='QUERY_OTBOR_CATALOG'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='QUERY_OTBOR_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='OTBOR_QUERY_SQL_ACCT_NMA_NPA'
GO
EXEC X_SET_PROP 'OTBOR_QUERY_SQL_ACCT_NMA_NPA', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICT_SUBACCOUNTS_OS_NMA_NPA'
GO



GO
DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

IF dbo.BS_GetWorkMode (@BUF_NAME) = 10
BEGIN
	-- Добавление групп ХО 11 (Касса) --
	IF NOT EXISTS (SELECT * FROM dbo.XOZ_OPER_GROUP WHERE CODE = '11')
		INSERT INTO dbo.XOZ_OPER_GROUP (CODE, NAME)
		SELECT '11', 'Касса'

		
	-- Добавление групп ХО 15 (Расчеты с дебиторами по доходам) --
	IF NOT EXISTS (SELECT * FROM dbo.XOZ_OPER_GROUP WHERE CODE = '15')
		INSERT INTO dbo.XOZ_OPER_GROUP (CODE, NAME)
		SELECT '15', 'Расчеты с дебиторами по доходам'

		
	-- Добавление групп ХО 17 (НФА) --
	IF NOT EXISTS (SELECT * FROM dbo.XOZ_OPER_GROUP WHERE CODE = '17')
		INSERT INTO dbo.XOZ_OPER_GROUP (CODE, NAME)
		SELECT '17', 'НФА'

		
	-- Добавление групп ХО 18 (Прочие операции) --
	IF NOT EXISTS (SELECT * FROM dbo.XOZ_OPER_GROUP WHERE CODE = '18')
		INSERT INTO dbo.XOZ_OPER_GROUP (CODE, NAME)
		SELECT '18', 'Прочие операции'

		
	IF OBJECT_ID ('TEMPDB..#NEW_XOZ_OPER') IS NOT NULL
		EXEC ('DROP TABLE #NEW_XOZ_OPER')

	CREATE TABLE #NEW_XOZ_OPER
		(
		[GROUP_LINK] int NOT NULL ,
		[CODE] char(2) NOT NULL ,
		[NAME] varchar(254) NOT NULL ,
		[SYSTEM] tinyint NOT NULL ,
		[BO] tinyint NOT NULL ,
		[ZP] tinyint NOT NULL ,
		[RBS] tinyint NOT NULL ,
		[USED] tinyint NOT NULL ,
		[GZ] tinyint NOT NULL ,
		[GZ2] tinyint NOT NULL ,
		[DO] tinyint NOT NULL ,
		[BO_DT_KT] tinyint NOT NULL ,
		[DO_DT_KT] tinyint NOT NULL ,
		[BO_MIN] tinyint NOT NULL ,
		[DO_MIN] tinyint NOT NULL ,
		)

	-- Загрузка ХО --
	INSERT INTO #NEW_XOZ_OPER ([GROUP_LINK], [CODE], [NAME], [SYSTEM], [BO], [ZP], [RBS], [USED], [GZ], [GZ2], [DO], [BO_DT_KT], [DO_DT_KT], [BO_MIN], [DO_MIN])
	SELECT XOG.LINK, '49' AS XO_CODE, 'Вложение НФА в уставный капитал (фонд) организаций' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '50' AS XO_CODE, 'Принятие к учету НФА при реорганизации учреждения' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '51' AS XO_CODE, 'Списание произведенных вложений в улучшение непроизвденных НПА' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '49' AS XO_CODE, 'Выбытие д/с из кассы при внесении наличных через банкомат, при передаче инкассаторам' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '11'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, 'Прием оплаты услуг, возврата дебиторской задолженности через платежный терминал' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '50' AS XO_CODE, 'Оприходование неучтенных денежных средств (документов)' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '11'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, 'Формирование резерва на оплату отпусков, з/п, др.расходы' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, 'Формирование резерва на восстановление последствий эксплуатации ОС' AS XO_NAME, 0 AS SYSTEM, 0 AS [BO], 0 AS [ZP], 0 AS [RBS], 1 AS [USED], 0 AS [GZ], 0 AS [GZ2], 0 AS [DO], 1 AS [BO_DT_KT], 1 AS [DO_DT_KT], 0 AS [BO_MIN], 0 AS [DO_MIN]
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	-- Загрузка хоз.операций --
	INSERT INTO dbo.XOZ_OPER 
		(
		GROUP_LINK,
		CODE,
		NAME,
		[SYSTEM],
		BO,
		ZP,
		RBS,
		USED,
		GZ,
		GZ2,
		DO,
		BO_DT_KT,
		DO_DT_KT,
		BO_MIN,
		DO_MIN	
		)
	SELECT
		T1.GROUP_LINK,
		T1.CODE,
		T1.NAME,
		T1.[SYSTEM],
		T1.BO,
		T1.ZP,
		T1.RBS,
		T1.USED,
		T1.GZ,
		T1.GZ2,
		T1.DO,
		T1.BO_DT_KT,
		T1.DO_DT_KT,
		T1.BO_MIN,
		T1.DO_MIN
	FROM #NEW_XOZ_OPER T1
	WHERE NOT EXISTS
		(
		SELECT * FROM dbo.XOZ_OPER TTT
			WHERE TTT.GROUP_LINK = T1.GROUP_LINK
				AND TTT.CODE = T1.CODE
		)
	
	-- Удаление таблицы для загрузки ХО --
	DROP TABLE #NEW_XOZ_OPER

	-- Установка флага завершения перехода --
	EXEC dbo.BS_SetWorkMode
		@WORK_MODE = @BUF_NAME,
	  	@WORK_STATUS =	11
END

GO

WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO


GO
-- Настройка ХО на ЖО по 98Н --
DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

IF dbo.BS_GetWorkMode (@BUF_NAME) = 11
BEGIN
	IF OBJECT_ID ('TEMPDB..#NEW_XOZ_OPER_JO') IS NOT NULL
		EXEC ('DROP TABLE #NEW_XOZ_OPER_JO')

	CREATE TABLE #NEW_XOZ_OPER_JO
		(
		[GROUP_LINK] int NOT NULL ,
		[XO_CODE] char(2) NOT NULL ,
		[JO_CODE] VARCHAR (20),
		GK tinyint DEFAULT (0)
		)

	-- Загрузка настроек ЖО на ХО --
	INSERT INTO #NEW_XOZ_OPER_JO ([GROUP_LINK], [XO_CODE], [JO_CODE], GK)
	SELECT XOG.LINK, '49' AS XO_CODE, '07        ' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '50' AS XO_CODE, '07        ' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '51' AS XO_CODE, '07        ' AS JO_CODE, 0 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '49' AS XO_CODE, '01        ' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '11'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '05' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '50' AS XO_CODE, '01        ' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '11'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '08' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, '08' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '03' AS XO_CODE, '06' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '08' AS JO_CODE, 1 AS GK
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	-- Загрузка настроек хоз.операций на ЖО --
	INSERT INTO dbo.XOZ_OPER_JURN
		(
		XOZ_LINK,
		JURN_LINK,
		GK
		)
	SELECT
		XO.LINK,
		JO.LINK,
		CASE
			WHEN EXISTS (SELECT * FROM dbo.XOZ_OPER_JURN TTT WHERE TTT.XOZ_LINK = XO.LINK AND TTT.GK = 1) THEN 0
			ELSE T1.GK
		END
	FROM #NEW_XOZ_OPER_JO T1
	INNER JOIN dbo.XOZ_OPER	XO ON
		(
		XO.GROUP_LINK = T1.GROUP_LINK
		AND XO.CODE = T1.XO_CODE
		)		
	INNER JOIN dbo.JOURNAL_OPERATION JO ON
		(
		JO.CODE = T1.JO_CODE
		)		
	WHERE NOT EXISTS
		(
		SELECT * FROM dbo.XOZ_OPER_JURN TTT
			WHERE TTT.XOZ_LINK = XO.LINK
				AND TTT.JURN_LINK = JO.LINK
		)


	-- Удаление таблицы для загрузки ХО-ЖО --
	DROP TABLE #NEW_XOZ_OPER_JO

	-- Установка флага завершения перехода --
	EXEC dbo.BS_SetWorkMode
		@WORK_MODE = @BUF_NAME,
	  	@WORK_STATUS =	12
END	

GO

WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO


GO
-- Корректные проводки по 98Н --
DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

IF dbo.BS_GetWorkMode (@BUF_NAME) = 12
BEGIN
	IF OBJECT_ID ('TEMPDB..#NEW_CORRECT_PROV') IS NOT NULL
		EXEC ('DROP TABLE #NEW_CORRECT_PROV')

	CREATE TABLE #NEW_CORRECT_PROV
		(
		[GROUP_LINK] int NOT NULL ,
		[XO_CODE] char(2) NOT NULL ,
		DT_ACCT	VARCHAR (20),
		KT_ACCT	VARCHAR (20),
		DT_SGU	VARCHAR (20),
		KT_SGU	VARCHAR (20)
		)

	-- Загрузка корректных проводок --
	INSERT INTO #NEW_CORRECT_PROV ([GROUP_LINK], [XO_CODE], DT_ACCT, KT_ACCT, DT_SGU, KT_SGU)
	SELECT XOG.LINK, '13' AS XO_CODE, '201.34' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '11'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '201.27' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.11' AS KT_ACCT, '226' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.21' AS KT_ACCT, '226' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.27' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '201.27' AS KT_ACCT, '226' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '12'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.12' AS KT_ACCT, '212' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.21' AS KT_ACCT, '221' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.22' AS KT_ACCT, '222' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.23' AS KT_ACCT, '223' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.24' AS KT_ACCT, '224' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.25' AS KT_ACCT, '225' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.26' AS KT_ACCT, '226' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '208.91' AS KT_ACCT, '290' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '13'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.75' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '302.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '206' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '14'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '205.82' AS DT_ACCT, '210.02' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '205.82' AS DT_ACCT, '210.02' AS KT_ACCT, '' AS DT_SGU, '180' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, '401.10' AS DT_ACCT, '205.82' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, '401.10' AS DT_ACCT, '205.82' AS KT_ACCT, '180' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '03' AS XO_CODE, '205.82' AS DT_ACCT, '401.10' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '03' AS XO_CODE, '205.82' AS DT_ACCT, '401.10' AS KT_ACCT, '' AS DT_SGU, '180' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '15'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '303.02' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '303.07' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '303.09' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '303.10' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '303.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, '401.60' AS DT_ACCT, '303.06' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '302.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.60' AS DT_ACCT, '302.91' AS KT_ACCT, '290' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '302.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '302.12' AS KT_ACCT, '212' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.11' AS KT_ACCT, '211' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.21' AS KT_ACCT, '221' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.22' AS KT_ACCT, '222' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.23' AS KT_ACCT, '223' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.25' AS KT_ACCT, '225' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.26' AS KT_ACCT, '226' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '302.91' AS KT_ACCT, '290' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '16'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.21' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.22' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.23' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.24' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.25' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.26' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.31' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.32' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.32' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.33' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.33' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.34' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.35' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.35' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.36' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.36' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.38' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.38' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.44' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.44' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.46' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '401.60' AS DT_ACCT, '105.46' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.15' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.15' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.24' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.25' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.26' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.34' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.35' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.35' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.36' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.36' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.44' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.44' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.45' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.45' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.46' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '101.46' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '14' AS XO_CODE, '401.60' AS DT_ACCT, '104' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '14' AS XO_CODE, '401.60' AS DT_ACCT, '104' AS KT_ACCT, '271' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '25' AS XO_CODE, '109' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '29' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '46' AS XO_CODE, '109.61' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '47' AS XO_CODE, '401.60' AS DT_ACCT, '106' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '17'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '109' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.20' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '01' AS XO_CODE, '401.60' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '02' AS XO_CODE, '106' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '18'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '201.35' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '21'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '241' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '242' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '251' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '252' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '101' AS KT_ACCT, '253' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '241' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '242' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '251' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '252' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '102' AS KT_ACCT, '253' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '241' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '242' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '251' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '252' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '103' AS KT_ACCT, '253' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '241' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '242' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '251' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '252' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '05' AS XO_CODE, '401.60' AS DT_ACCT, '105' AS KT_ACCT, '253' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '241' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '242' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '251' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '252' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '104' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '253' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.27' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '272' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '10' AS XO_CODE, '401.60' AS DT_ACCT, '105.37' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '211' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '212' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '213' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '221' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '222' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '223' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '224' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '225' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '226' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '241' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '242' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '251' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '252' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '253' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '261' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '262' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '263' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '271' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '272' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '273' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '130' AS DT_SGU, '290' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '211' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '212' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '213' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '221' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '222' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '223' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '224' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '225' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '226' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '241' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '242' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '251' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '252' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '253' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '261' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '262' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '263' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '271' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '272' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '273' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '16' AS XO_CODE, '401.10' AS DT_ACCT, '401.60' AS KT_ACCT, '172' AS DT_SGU, '290' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.24' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.24' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.34' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.34' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.44' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '106.44' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.61' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.61' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.71' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.71' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.81' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.81' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.91' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '17' AS XO_CODE, '109.91' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '22'

	UNION ALL

	SELECT XOG.LINK, '11' AS XO_CODE, '401.60' AS DT_ACCT, '304.04' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '11' AS XO_CODE, '401.60' AS DT_ACCT, '304.04' AS KT_ACCT, '272' AS DT_SGU, '340' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.41' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.41' AS KT_ACCT, '241' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.42' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.42' AS KT_ACCT, '242' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.51' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.51' AS KT_ACCT, '251' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.52' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.52' AS KT_ACCT, '252' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.53' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '19' AS XO_CODE, '401.60' AS DT_ACCT, '302.53' AS KT_ACCT, '253' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '23'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '207' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '207' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.11' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.12' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.13' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.13' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.14' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.14' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.21' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.23' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.24' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.31' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.33' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.33' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.42' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.42' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.43' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.43' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.44' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '401.60' AS DT_ACCT, '301.44' AS KT_ACCT, '273' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.11' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.12' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.13' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.13' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.14' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.14' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.21' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.23' AS KT_ACCT, '232' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.24' AS KT_ACCT, '232' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.31' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.33' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.33' AS KT_ACCT, '231' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.42' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.42' AS KT_ACCT, '232' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.43' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.43' AS KT_ACCT, '232' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.44' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '401.60' AS DT_ACCT, '301.44' AS KT_ACCT, '232' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.11' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.11' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.12' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.12' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.13' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.13' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.14' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.14' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.21' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.21' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.23' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.23' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.24' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.24' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.31' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.31' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.33' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.33' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.42' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.42' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.43' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.43' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.44' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '09' AS XO_CODE, '301.44' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '11' AS XO_CODE, '401.60' AS DT_ACCT, '304.05' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '11' AS XO_CODE, '401.60' AS DT_ACCT, '304.05' AS KT_ACCT, '290' AS DT_SGU, '290' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '24'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.61' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.61' AS KT_ACCT, '261' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.62' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.62' AS KT_ACCT, '262' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.63' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '401.60' AS DT_ACCT, '302.63' AS KT_ACCT, '263' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '26'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.32' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '208.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.32' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.33' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.75' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.11' AS DT_ACCT, '302.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.32' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '208.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.21' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.22' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.23' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.24' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.25' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.26' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.31' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.32' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.33' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.34' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.75' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '06' AS XO_CODE, '210.12' AS DT_ACCT, '302.91' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '210.11' AS DT_ACCT, '303.04' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '210.12' AS DT_ACCT, '303.04' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '303.04' AS DT_ACCT, '210.11' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '08' AS XO_CODE, '303.04' AS DT_ACCT, '210.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '11' AS XO_CODE, '401.60' AS DT_ACCT, '303.12' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '12' AS XO_CODE, '401.60' AS DT_ACCT, '303.13' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '13' AS XO_CODE, '401.60' AS DT_ACCT, '303.05' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '27'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '211' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '212' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '213' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '221' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '222' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '223' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '224' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '225' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '226' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '231' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '232' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '241' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '242' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '251' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '252' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '253' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '261' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '262' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '263' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '271' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '272' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '273' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '04' AS XO_CODE, '401.30' AS DT_ACCT, '401.60' AS KT_ACCT, '' AS DT_SGU, '290' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '98'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '1.401.60' AS DT_ACCT, '1.105.36' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '99'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '1.401.60' AS DT_ACCT, '1.105.36' AS KT_ACCT, '251' AS DT_SGU, '440' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '99'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '1.401.60' AS DT_ACCT, '1.105.46' AS KT_ACCT, '' AS DT_SGU, '' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '99'

	UNION ALL

	SELECT XOG.LINK, '07' AS XO_CODE, '1.401.60' AS DT_ACCT, '1.105.46' AS KT_ACCT, '251' AS DT_SGU, '440' AS KT_SGU
	FROM dbo.XOZ_OPER_GROUP XOG
	WHERE XOG.CODE = '99'


	-- Загрузка корректных проводок --
	INSERT INTO dbo.CORRECT_PROV
		(
		LINK_HOZ,
		LINK_DT,
		LINK_KT,
		DT_SGU,
		KT_SGU
		)
	SELECT 
		XO.LINK,
		D_SA.LINK,
		K_SA.LINK,
		D_SGU.LINK,
		K_SGU.LINK
	FROM #NEW_CORRECT_PROV T1
	INNER JOIN dbo.XOZ_OPER	XO ON
		(
		XO.GROUP_LINK = T1.GROUP_LINK
		AND XO.CODE = T1.XO_CODE
		)		
	INNER JOIN dbo.S_ACCOUNTS D_SA ON
		(
		D_SA.CODE = T1.DT_ACCT
		)		
	INNER JOIN dbo.S_ACCOUNTS K_SA ON
		(
		K_SA.CODE = T1.KT_ACCT
		)		
	LEFT JOIN dbo.KOSGU D_SGU ON
		(
		D_SGU.CODE = T1.DT_SGU
		)		
	LEFT JOIN dbo.KOSGU K_SGU ON
		(
		K_SGU.CODE = T1.KT_SGU
		)		
	WHERE NOT EXISTS
		(
		SELECT * FROM dbo.CORRECT_PROV TTT
			WHERE TTT.LINK_HOZ = XO.LINK
				AND TTT.LINK_DT = D_SA.LINK
				AND TTT.LINK_KT = K_SA.LINK
				AND ISNULL (TTT.DT_SGU, 0) = ISNULL (D_SGU.LINK, 0)
				AND ISNULL (TTT.KT_SGU, 0) = ISNULL (K_SGU.LINK, 0)
		)

	

	-- --
	DROP TABLE #NEW_CORRECT_PROV
	-- Переформирование корректных поводок. В буфере перечень ХО, для которых обновить --
	EXEC dbo.XD_CORRECT_PROV_FULL_BY_XO_BUF

	
	-- Установка флага завершения перехода --
	EXEC dbo.BS_SetWorkMode
		@WORK_MODE = @BUF_NAME,
	  	@WORK_STATUS =	13
END	

GO


WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO


GO
--TXT
--Добавление системной типовой операции
--Сгенерировано скриптом: EXECUTE dbo.[UNLOAD_SHABLON_DOCUMENTS_PROV] @NAME_OPER = 'Начисление НДС по полученным авансам (Дт 210.11 - Кт 303.04)'
DECLARE @G1_LINK_NEW INT,
	@G1_LINK_UP INT,
	@G1_ORDERS INT,

	@NASTR_LINK INT,
	@NASTR_OSN BIT,

	@G2_LINK_NEW INT,
	@G2_LINK_SELF INT,
	@G2_ECON_OPER INT, 
 
	@GAP_ACC INT,
	@GAP_KBK INT,
	@GAP_EKR INT,
	@GAP_DEP INT,
	@GAP_SUB INT,
	@GAP_EMP INT,
	@GAP_NOMEN INT,
	@GAP_INV INT,
	@GAP_KAU INT,

	@GAP_DEP_ACC INT,
	@GAP_TMC INT,
	@GAP_INDATE DATETIME,
	@GAP_AP1 INT,
	@GAP_AP2 INT,
	@GAP_AP3 INT,
	@GAP_SGU INT

SELECT TOP 1 @G1_LINK_UP =  LINK FROM G_PROV 
WHERE OBJECT = (SELECT LINK FROM S_OBJECTS WHERE CODE = 'SHABLON_DOCUMENTS_PROV')


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.20' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '105' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '27' AND ZABALANS = 1)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '17.09')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.20' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '105' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 2)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Передача МЗ сотрудникам в личное пользование'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Передача МЗ сотрудникам в личное пользование', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '09' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '17')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Передача МЗ сотрудникам в личное пользование', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.20' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '105' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


------------------------------------------------------------------

-- Формирование проводки 2
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '01' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '31')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Операция по забалансовым счетам', @G2_ECON_OPER,          2 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '27' AND ZABALANS = 1
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.06')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '210.12' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '302' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Суммы НДС, предъявленные поставщиками (Дт 210.12 - Кт 302)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Суммы НДС, предъявленные поставщиками (Дт 210.12 - Кт 302)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '06' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'НДС, предъявленный учреждению поставщиками', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '560'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.06')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '210.12' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '302' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'НДС, предъявленный поставщиком (Дт 210.12 - Кт 302)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'НДС, предъявленный поставщиком (Дт 210.12 - Кт 302)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '06' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'НДС, предъявленный поставщиком', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '560'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '208' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.06')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '210.12' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '208' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'НДС, предъявленный поставщиком (Дт 210.12 - Кт 208)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'НДС, предъявленный поставщиком (Дт 210.12 - Кт 208)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '06' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'НДС, предъявленный поставщиком', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '560'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '208' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.11' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.07')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '210.11' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '303.04' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Начисление НДС по полученным авансам (Дт 210.11 - Кт 303.04)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Начисление НДС по полученным авансам (Дт 210.11 - Кт 303.04)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '07' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Начисление НДС по полученных авансам', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.11' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '560'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '730'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.08')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '303.04' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '210.12' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Списание НДС по налоговому вычету (Дт 303.04 - Кт 210.12)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Списание НДС по налоговому вычету (Дт 303.04 - Кт 210.12)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '08' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Списание НДС по налоговому вычету', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '830'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '660'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.11' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '27.08')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '303.04' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '210.11' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Списание НДС по налоговому вычету (Дт 303.04 - Кт 210.11)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Списание НДС по налоговому вычету (Дт 303.04 - Кт 210.11)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '08' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '27')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Списание НДС по налоговому вычету', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '303.04' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '830'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.11' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '660'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '106.34' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '22.17')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '106.34' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '210.12' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Списание НДС в счет стоимости продукции (Дт 106.34 - Кт 210.12 )'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Списание НДС в счет стоимости продукции (Дт 106.34 - Кт 210.12 )', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '17' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '22')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Производство: Списание НДС в счет стоимости продукции', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '106.34' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '340'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '660'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '109' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '22.17')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '109' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '210.12' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Списание НДС в счет стоимости продукции (Дт 109 - Кт 210.12 )'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Списание НДС в счет стоимости продукции (Дт 109 - Кт 210.12 )', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '17' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '22')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Производство: Списание НДС в счет стоимости продукции', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '109' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '340'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '210.12' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = '660'

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '109' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '18.01')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '109' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '401.60' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Формирование резерва на оплату отпусков, з/п, др.расходы (Дт 109 - Кт 401.60)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Формирование резерва на оплату отпусков, з/п, др.расходы (Дт 109 - Кт 401.60)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '01' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '18')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Формирование резерва на оплату отпусков, з/п, др.расходы', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '109' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.20' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '18.01')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.20' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '401.60' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Формирование резерва на оплату отпусков, з/п, др.расходы (Дт 401.20 - Кт 401.60)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Формирование резерва на оплату отпусков, з/п, др.расходы (Дт 401.20 - Кт 401.60)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '01' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '18')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Формирование резерва на оплату отпусков, з/п, др.расходы', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.20' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '106' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '18.02')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '106' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '401.60' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Формирование резерва на восстановление последствий эксплуатации ОС'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Формирование резерва на восстановление последствий эксплуатации ОС', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '02' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '18')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Формирование резерва на восстановление последствий эксплуатации ОС', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '106' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '14.08')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.60' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '302' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Оказаны услуги за счет резерва (Дт 401.60 - Кт 302)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Оказаны услуги за счет резерва (Дт 401.60 - Кт 302)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '08' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '14')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Начисление расходов за счет резерва', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '303' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '16.01')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.60' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '303' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Начисление расходов по платежам в бюджеты за счет резерва (Дт 401.60 - Кт 303)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Начисление расходов по платежам в бюджеты за счет резерва (Дт 401.60 - Кт 303)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '01' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '16')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Начисление расходов по платежам в бюджеты за счет резерва', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '303' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '16.06')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.60' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '302' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Начисление оплаты труда и прочих выплат (Дт 401.60 - Кт 302)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Начисление оплаты труда и прочих выплат (Дт 401.60 - Кт 302)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '06' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '16')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Начисление оплаты труда и прочих выплат', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



----------------------

END -- IF EXISTS()


------
IF 1=1


--------------------------------------------------------------------------------------------
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0)
 AND EXISTS(SELECT * FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0)


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 and not exists(SELECT G1.LINK
	FROM dbo.G_PROV1 G1
	INNER JOIN dbo.G_PROV 	  G   ON G.LINK = G1.LINK_UP  
	INNER JOIN dbo.S_OBJECTS  SO  ON G.OBJECT = SO.LINK and SO.CODE = 'SHABLON_DOCUMENTS_PROV'  
	INNER JOIN dbo.G_PROV2    G2  ON G2.LINK_UP = G1.LINK AND G2.ORDERS = 1
		and  exists(select * from dbo.XD_XOZ_OPER XO where G2.ECON_OPER = XO.LINK AND XO.FULLCODE = '16.07')
	INNER JOIN dbo.G_PROV_AP  GA1 ON G2.LINK = GA1.LINK_UP AND GA1.DB_KR = 0
	INNER JOIN dbo.S_ACCOUNTS SA1 ON SA1.LINK =  GA1.ACCOUNT AND SA1.code = '401.60' AND SA1.ZABALANS = 0 
	INNER JOIN dbo.G_PROV_AP  GA2 ON G2.LINK = GA2.LINK_UP AND GA2.DB_KR = 1
	INNER JOIN dbo.S_ACCOUNTS SA2 ON SA2.LINK =  GA2.ACCOUNT and SA2.code = '302' AND SA2.ZABALANS = 0   
	WHERE (SELECT COUNT(*) FROM G_PROV2 WHERE LINK_UP = G1.LINK) = 1)


--------------------------

BEGIN -- IF EXISTS()



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Формирование типовой операции 'Начисления по услугам внештатников за счет резерва (Дт 401.60 - Кт 302)'
  SELECT @G1_ORDERS = MAX(ORDERS) FROM G_PROV1 WHERE LINK_UP = @G1_LINK_UP
  SET @G1_LINK_NEW = 0

  EXECUTE dbo.X_UPDATE_G_PROV1 @G1_LINK_NEW OUTPUT, @G1_LINK_UP, NULL, 'Начисления по услугам внештатников за счет резерва (Дт 401.60 - Кт 302)', @G1_ORDERS


------------------------------------------------------------------

-- Формирование проводки 1
  SET @G2_LINK_NEW = NULL


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SET @G2_LINK_SELF = NULL
  SELECT @G2_ECON_OPER = LINK FROM XOZ_OPER WHERE CODE = '07' AND GROUP_LINK = (select LINK from XOZ_OPER_GROUP where CODE = '16')
  EXECUTE dbo.X_UPDATE_G_PROV2 @G2_LINK_NEW OUTPUT, @G1_LINK_NEW, @G2_LINK_SELF,          0,          0,          0, 'Начисления по услугам внештатников', @G2_ECON_OPER,          1 


-------------------------------

-- Аналитика дебетового счета


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL	
		
  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '401.60' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 0, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


--------------------------------

-- Аналитика кредетового счета


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  -- Сброс старых значений --
  SELECT
	@GAP_ACC = NULL,
	@GAP_KBK = NULL,
	@GAP_EKR = NULL,

	@GAP_DEP = NULL,
	@GAP_SUB = NULL,
	@GAP_EMP = NULL,

	@GAP_NOMEN = NULL,
	@GAP_INV = NULL,
	@GAP_KAU = NULL,

	@GAP_DEP_ACC = NULL,
	@GAP_TMC = NULL,
	@GAP_SGU = NULL,

	@GAP_INDATE = NULL,

	@GAP_AP1 = NULL,
	@GAP_AP2 = NULL,
	@GAP_AP3 = NULL

  SELECT @GAP_ACC = LINK FROM S_ACCOUNTS WHERE CODE = '302' AND ZABALANS = 0
  SELECT @GAP_KBK = LINK FROM KL_KBK WHERE CODE = NULL AND TYPE = '0' 
  SELECT @GAP_EKR = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_DEP = LINK FROM DEPARTMENTS WHERE CODE = NULL
  SELECT @GAP_SUB = LINK FROM SUBDIV WHERE CODE = NULL
  SELECT @GAP_EMP = LINK FROM EMPL WHERE TAB = NULL

  SELECT @GAP_NOMEN = LINK FROM NOMENCLATURE WHERE CODE = NULL
  SELECT @GAP_INV = LINK FROM INVENTORY WHERE CODE = NULL
  SELECT @GAP_KAU = LINK FROM DICTION WHERE CODE = NULL

  SELECT @GAP_DEP_ACC = LINK FROM DEPARTMENT_ACCOUNTS WHERE CODE = NULL
  SELECT @GAP_TMC = LINK FROM DICTION WHERE CODE = NULL
  SELECT @GAP_SGU = LINK FROM KOSGU WHERE CODE = NULL

  SELECT @GAP_INDATE = CONVERT(DATETIME,NULL, 104)

  SELECT @GAP_AP1 = NULL
  SELECT @GAP_AP2 = NULL
  SELECT @GAP_AP3 = NULL


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  EXECUTE dbo.X_UPDATE_G_PROV_AP @G2_LINK_NEW, 1, @GAP_ACC, @GAP_KBK, @GAP_EKR, @GAP_DEP, @GAP_SUB, @GAP_EMP, @GAP_NOMEN, @GAP_INV, @GAP_KAU, @GAP_DEP_ACC, @GAP_TMC, @GAP_INDATE, @GAP_AP1, @GAP_AP2, @GAP_AP3, @GAP_SGU


-------------------------------------------------------

-- Сохранение связей документов с типовыми операциями


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------

END -- IF EXISTS()


------

GO

-- Установка флага завершения перехода --
DECLARE
	@BUF_NAME	VARCHAR (100)

SET @BUF_NAME = '157N_CHANGE_89N_2014'

EXEC dbo.BS_SetWorkMode
	@WORK_MODE = @BUF_NAME,
  	@WORK_STATUS =	1		

GO

WHILE @@TRANCOUNT > 0
	raiserror('@@TRANCOUNT>0!!!',11,1)
GO


GO
-- Добавление настроек документа ИНВЕНТАРИЗАЦИИЯ ПОСТАВЩИКИ\ПОКУПАТЕЛИ) --
DECLARE
	@OBJ_ID	INT

SET @OBJ_ID = dbo.GetObjLink ('DOCUMENTS_INVENTORY_DBKT')

IF NOT EXISTS (SELECT * FROM dbo.DOC_NASTR WHERE LINK = @OBJ_ID)
	INSERT INTO dbo.DOC_NASTR
		(
		LINK,
		PRINT_SGU,
		PRINT_KBK,
		AN_PERIOD,
		AN_ORG,
		AN_BEGIN,
		AN_SHABLON
		)
	SELECT
		@OBJ_ID,
		0,
		0,
		0,
		0,
		0,
		''
		
-- Добавление счетов --
INSERT INTO dbo.DOC_NASTR_S_ACCOUNTS
	(
	LINK_UP,
	ACCOUNT,
	DB_KR
	)
SELECT
	@OBJ_ID,
	SA.LINK,
	CASE
		WHEN SA.CODE LIKE '20[5-6]' THEN 0
		ELSE 1
	END
FROM dbo.S_ACCOUNTS SA
WHERE (SA.CODE LIKE '20[5-6]' OR SA.CODE = '302')
	AND NOT EXISTS (SELECT * FROM dbo.DOC_NASTR_S_ACCOUNTS DN_SA
					WHERE DN_SA.LINK_UP = @OBJ_ID
						AND DN_SA.ACCOUNT = SA.LINK
						AND (SA.CODE LIKE '20[5-6]' AND DN_SA.DB_KR = 0
							OR SA.CODE LIKE '302' AND DN_SA.DB_KR = 1)
					)
GROUP BY
	SA.LINK,
	SA.CODE

GO


GO
update EXPORT_MODELS set DATE_END   = '31.12.2014' where MODEL_VER = 'TXPP140701' AND CODE = 'PP'
DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = 'TXPP150101' AND CODE = 'PP'
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT 'PP','Платежное поручение','TXPP150101',0,'','XXXXXDNN.TTM','fb_file_name_doc','BB_EXPORT_PP','cModelVer','KOD_UBP','bb_import_PP()',NULL 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = 0,
		NAME   = 'Платежное поручение',
		NORM_DOC   = '',
		FILE_NAME_MASK   = 'XXXXXDNN.TTM',
		FILE_NAME_PROC   = 'fb_file_name_doc',
		PROC_EXP   = 'BB_EXPORT_PP',
		PROC_DOP_PARAM   = 'cModelVer',
		PROG_SAVE   = 'bb_import_PP()',
		DEP_NAME   = 'KOD_UBP',
		DATE_END   = NULL
	where LINK_MODEL = @varKSModelLink
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FK',1,0,'Маркер',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 1,
			ISONCE = 0,
			NAME   = 'Маркер',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер версии формата',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_VER','Номер версии формата','STRING',10,0,1,1,'NUM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование программного продукта, сформировавшего файл',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORMER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'FORMER','Наименование программного продукта, сформировавшего файл','STRING',50,0,0,1,'FORMER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Версия программного продукта',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'FORM_VER','Версия программного продукта','STRING',10,0,0,1,'FORM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'сылка на документ, утверждающий формат файла',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NORM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NORM_DOC','сылка на документ, утверждающий формат файла','STRING',250,0,0,0,'NORM_DOC','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FROM'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FROM',2,0,'Почтовая информация об отправителях файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 2,
			ISONCE = 0,
			NAME   = 'Почтовая информация об отправителях файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Уровень бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BUDG_LEVEL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'BUDG_LEVEL','Уровень бюджета','STRING',1,1,0,1,'BUDG_LEVEL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOD_UBP','Код клиента','STRING',5,1,1,1,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Наименование клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NAME_UBP','Наименование клиента','STRING',254,0,1,1,'NAME_UBP','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'TO'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'TO',3,0,'Почтовая информация о получателе файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 3,
			ISONCE = 0,
			NAME   = 'Почтовая информация о получателе файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_TOFK','Код ОрФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NAME_TOFK','Наименование ОрФК','STRING',2000,0,1,1,'NAME_TOFK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'PP'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'PP',4,0,'Пакет',0
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 4,
			ISONCE = 0,
			NAME   = 'Пакет',
			OBLIGATORY = 0
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Дата',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'DATE','Дата','DATE',0,0,1,1,'DATE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Количество документов',
		VAL_TYPE 	= 'NUMBER',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOL','Количество документов','NUMBER',5,1,1,1,'KOL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_TOTAL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Контрольная сумма',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM_TOTAL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_TOTAL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'SUM_TOTAL','Контрольная сумма','NUMBER2',0,0,1,1,'SUM_TOTAL','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'PPT'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'PPT',5,2,'Платежное поручение',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 5,
			ISONCE = 2,
			NAME   = 'Платежное поручение',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_PP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= '№ платежного поручения',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NOM_PP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_PP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NOM_PP','№ платежного поручения','STRING',10,0,1,1,'NOM_PP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_PP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Дата платежного поручения',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_PP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_PP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'DATE_PP','Дата платежного поручения','DATE',0,1,1,1,'DATE_PP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_PP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Сумма платежного поручения',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM_PP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_PP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'SUM_PP','Сумма платежного поручения','NUMBER2',0,1,1,1,'SUM_PP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Вид платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'VID_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'VID_PL','Вид платежа','STRING',1,1,1,1,'VID_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OPER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Вид операции.',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'VID_OPER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OPER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'VID_OPER','Вид операции.','STRING',2,1,1,1,'VID_OPER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'ИНН Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 12,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'INN_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'INN_PAY','ИНН Плательщика','STRING',12,0,1,1,'INN_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'КПП Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KPP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'KPP_PAY','КПП Плательщика','STRING',9,1,1,1,'KPP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'CNAME_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'Наименование Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'CNAME_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'CNAME_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'CNAME_PAY','Наименование Плательщика','STRING',160,0,1,1,'CNAME_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 10,
		NAME   		= 'Расчетный счет Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 10,'BS_PAY','Расчетный счет Плательщика','STRING',20,1,1,1,'BS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 11,
		NAME   		= 'БИК банка Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BIC_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 11,'BIC_PAY','БИК банка Плательщика','STRING',9,1,1,1,'BIC_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 12,
		NAME   		= 'Наименование банка Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_BIC_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 12,'NAME_BIC_PAY','Наименование банка Плательщика','STRING',160,0,1,1,'NAME_BIC_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_KS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 13,
		NAME   		= 'Коррсчет банка Плательщика в РКЦ',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BS_KS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_KS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 13,'BS_KS_PAY','Коррсчет банка Плательщика в РКЦ','STRING',20,1,1,0,'BS_KS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 14,
		NAME   		= 'ИНН получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 12,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'INN_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 14,'INN_RCP','ИНН получателя','STRING',12,0,0,0,'INN_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 15,
		NAME   		= 'КПП получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KPP_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 15,'KPP_RCP','КПП получателя','STRING',9,0,0,0,'KPP_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'CNAME_UBP_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 16,
		NAME   		= 'Наименование получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'CNAME_UBP_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'CNAME_UBP_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 16,'CNAME_UBP_RCP','Наименование получателя','STRING',160,0,1,1,'CNAME_UBP_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 17,
		NAME   		= 'Расчетный счет Получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BS_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 17,'BS_RCP','Расчетный счет Получателя','STRING',20,0,0,0,'BS_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 18,
		NAME   		= 'БИК банка Получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BIC_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 18,'BIC_RCP','БИК банка Получателя','STRING',9,1,1,1,'BIC_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 19,
		NAME   		= 'Наименование банка получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_BIC_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 19,'NAME_BIC_RCP','Наименование банка получателя','STRING',160,0,1,1,'NAME_BIC_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_KS_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 20,
		NAME   		= 'Корсчет банка получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BS_KS_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_KS_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 20,'BS_KS_RCP','Корсчет банка получателя','STRING',20,1,0,0,'BS_KS_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 21,
		NAME   		= 'Срок платежа',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 21,'DATE_PAY','Срок платежа','DATE',0,0,0,0,'DATE_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ORDER_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 22,
		NAME   		= 'Очередность платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'ORDER_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ORDER_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 22,'ORDER_PAY','Очередность платежа','STRING',1,1,1,1,'ORDER_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'UIN_CODE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 23,
		NAME   		= 'уин',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 25,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'UIN_CODE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'UIN_CODE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 23,'UIN_CODE','уин','STRING',25,0,0,0,'UIN_CODE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 24,
		NAME   		= 'Назначение платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 210,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'PURPOSE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 24,'PURPOSE','Назначение платежа','STRING',210,0,1,1,'PURPOSE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PAYSTATUS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 25,
		NAME   		= 'Статус составителя расчетного документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PAYSTATUS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PAYSTATUS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 25,'PAYSTATUS','Статус составителя расчетного документа','STRING',2,0,0,0,'PAYSTATUS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 26,
		NAME   		= 'Код бюджетной классификации',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 26,'KBK','Код бюджетной классификации','STRING',20,1,0,0,'KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OKATO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 27,
		NAME   		= 'Код ОКАТО',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OKATO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OKATO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 27,'OKATO','Код ОКАТО','STRING',11,0,0,0,'OKATO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OSNPLAT')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 28,
		NAME   		= 'Показатель основания платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OSNPLAT',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OSNPLAT'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 28,'OSNPLAT','Показатель основания платежа','STRING',2,0,0,0,'OSNPLAT','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAL_PER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 29,
		NAME   		= 'Показатель налогового периода',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAL_PER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAL_PER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 29,'NAL_PER','Показатель налогового периода','STRING',10,0,0,0,'NAL_PER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 30,
		NAME   		= 'Показатель номера документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NUM_DOK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 30,'NUM_DOK','Показатель номера документа','STRING',15,0,0,0,'NUM_DOK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 31,
		NAME   		= 'Показатель даты документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_DOK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 31,'DATE_DOK','Показатель даты документа','STRING',10,0,0,0,'DATE_DOK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 32,
		NAME   		= 'Тип платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 32,'TYPE_PL','Тип платежа','STRING',2,0,0,0,'TYPE_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 33,
		NAME   		= 'Глобальный уни-кальный идентификатор',
		VAL_TYPE 	= 'GUID',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GUID_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 33,'GUID_FK','Глобальный уни-кальный идентификатор','GUID',0,0,0,0,'GUID_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 34,
		NAME   		= 'Код ОрФК  клиента-плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 34,'KOD_TOFK_PAY','Код ОрФК  клиента-плательщика','STRING',4,1,1,1,'KOD_TOFK_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 35,
		NAME   		= 'Наименование ОрФК клиента- плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 35,'NAME_TOFK_PAY','Наименование ОрФК клиента- плательщика','STRING',2000,0,1,1,'NAME_TOFK_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 36,
		NAME   		= 'Код клиента - плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 36,'KOD_UBP_PAY','Код клиента - плательщика','STRING',5,1,1,1,'KOD_UBP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 37,
		NAME   		= 'Полное наименование клиента - Плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 37,'NAME_UBP_PAY','Полное наименование клиента - Плательщика','STRING',2000,0,1,1,'NAME_UBP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 38,
		NAME   		= 'Л/с клиента - плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'LS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 38,'LS_PAY','Л/с клиента - плательщика','STRING',11,1,0,0,'LS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 39,
		NAME   		= 'Л/с клиента - получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'LS_PAY_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 39,'LS_PAY_RCP','Л/с клиента - получателя','STRING',11,1,0,0,'LS_PAY_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PRINT_KPP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 40,
		NAME   		= 'Признак печати КПП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PRINT_KPP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PRINT_KPP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 40,'PRINT_KPP','Признак печати КПП','STRING',1,1,0,0,'PRINT_KPP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PRIZ')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 41,
		NAME   		= 'Признак наличия Расшифровки к платежному поручению',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'PRIZ',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PRIZ'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 41,'PRIZ','Признак наличия Расшифровки к платежному поручению','STRING',1,1,1,1,'PRIZ','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'PPST'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'PPST',6,2,'Строки платежного поручения по бюджетной классификации',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 6,
			ISONCE = 2,
			NAME   = 'Строки платежного поручения по бюджетной классификации',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код по КБК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KBK','Код по КБК','STRING',20,1,0,0,'KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Тип КБК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'TYPE_KBK','Тип КБК','STRING',2,1,0,0,'TYPE_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Код цели плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'ADD_KLASS','Код цели плательщика','STRING',20,0,0,0,'ADD_KLASS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Код цели получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'ADD_KLASS_RCP','Код цели получателя','STRING',20,0,0,0,'ADD_KLASS_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Сумма',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'SUM','Сумма','NUMBER2',0,1,1,1,'SUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DIR_SUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Направление пла-тежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DIR_SUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DIR_SUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'DIR_SUM','Направление пла-тежа','STRING',1,1,1,1,'DIR_SUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'MES_FIN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Месяц финансиро-вания',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'MES_FIN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'MES_FIN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'MES_FIN','Месяц финансиро-вания','STRING',2,1,0,0,'MES_FIN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'REZERV')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'Резервное поле',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 40,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'REZERV',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'REZERV'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'REZERV','Резервное поле','STRING',40,0,0,0,'REZERV','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_FIN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'Код источника финансирования',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KOD_FIN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_FIN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'KOD_FIN','Код источника финансирования','STRING',1,1,0,0,'KOD_FIN','',''
GO

GO
update EXPORT_MODELS set DATE_END   = '31.12.2014' where MODEL_VER = 'TXRN130101' AND CODE = 'RN'
DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = 'TXRN150101' AND CODE = 'RN'
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT 'RN','Расшифровка сумм неиспользованных средств','TXRN150101',0,'','XXXXXDNN.TTM','fb_file_name_doc','BB_EXPORT_RN','','KOD_UBP','',NULL 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = 0,
		NAME   = 'Расшифровка сумм неиспользованных средств',
		NORM_DOC   = '',
		FILE_NAME_MASK   = 'XXXXXDNN.TTM',
		FILE_NAME_PROC   = 'fb_file_name_doc',
		PROC_EXP   = 'BB_EXPORT_RN',
		PROC_DOP_PARAM   = '',
		PROG_SAVE   = '',
		DEP_NAME   = 'KOD_UBP',
		DATE_END   = NULL
	where LINK_MODEL = @varKSModelLink
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FK',1,0,'Маркер',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 1,
			ISONCE = 0,
			NAME   = 'Маркер',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер версии формата',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_VER','Номер версии формата','STRING',10,0,1,1,'NUM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование программного продукта, сформировавшего файл',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORMER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'FORMER','Наименование программного продукта, сформировавшего файл','STRING',50,0,0,1,'FORMER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Версия программного продукта',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'FORM_VER','Версия программного продукта','STRING',10,0,0,1,'FORM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'сылка на документ, утверждающий формат файла',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NORM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NORM_DOC','сылка на документ, утверждающий формат файла','STRING',250,0,0,0,'NORM_DOC','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FROM'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FROM',2,0,'Почтовая информация об отправителях файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 2,
			ISONCE = 0,
			NAME   = 'Почтовая информация об отправителях файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Уровень бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BUDG_LEVEL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'BUDG_LEVEL','Уровень бюджета','STRING',1,1,0,1,'BUDG_LEVEL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOD_UBP','Код УБП','STRING',5,1,1,1,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Наименование УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NAME_UBP','Наименование УБП','STRING',254,0,1,1,'NAME_UBP','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'TO'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'TO',3,0,'Почтовая информация о получателе файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 3,
			ISONCE = 0,
			NAME   = 'Почтовая информация о получателе файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_TOFK','Код ОрФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NAME_TOFK','Наименование ОрФК','STRING',2000,0,1,1,'NAME_TOFK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'RN'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'RN',4,2,'Общая инфор-мация',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 4,
			ISONCE = 2,
			NAME   = 'Общая инфор-мация',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Глобальный уникальный идентификатор',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 36,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GUID_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'GUID_FK','Глобальный уникальный идентификатор','STRING',36,0,0,0,'GUID_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_RN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Номер документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NOM_RN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_RN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NOM_RN','Номер документа','STRING',15,0,1,1,'NOM_RN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_RN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Дата документа',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_RN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_RN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'DATE_RN','Дата документа','DATE',0,1,1,1,'DATE_RN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Номер лицевого счета клиента.',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'LS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'LS_PAY','Номер лицевого счета клиента.','STRING',11,1,1,1,'LS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OPER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Вид операции',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'VID_OPER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OPER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'VID_OPER','Вид операции','STRING',1,1,1,1,'VID_OPER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Код ПБС по Сводному ре-естру',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'KOD_UBP','Код ПБС по Сводному ре-естру','STRING',5,1,0,0,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Наименование клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'NAME_UBP','Наименование клиента','STRING',2000,0,1,1,'NAME_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'ИНН',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'INN_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'INN_UBP','ИНН','STRING',10,1,0,1,'INN_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'КПП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KPP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'KPP','КПП','STRING',9,1,0,1,'KPP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 10,
		NAME   		= 'Код органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 10,'KOD_TOFK','Код органа ФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 11,
		NAME   		= 'Наименование органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 11,'NAME_TOFK','Наименование органа ФК','STRING',2000,0,1,1,'NAME_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 12,
		NAME   		= 'Код объекта ФАИП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 14,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'FAIP_CODE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 12,'FAIP_CODE','Код объекта ФАИП','STRING',14,1,0,0,'FAIP_CODE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'CARD_NUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 13,
		NAME   		= 'Номер банков-ской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'CARD_NUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'CARD_NUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 13,'CARD_NUM','Номер банков-ской карты','STRING',20,0,0,1,'CARD_NUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 14,
		NAME   		= 'Должность руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DOL_RUK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 14,'DOL_RUK','Должность руководителя (уполномоченного им лица)','STRING',100,0,0,1,'DOL_RUK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 15,
		NAME   		= 'ФИО руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_RUK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 15,'NAME_RUK','ФИО руководителя (уполномоченного им лица)','STRING',50,0,0,1,'NAME_RUK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 16,
		NAME   		= 'Должность главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DOL_BUH',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 16,'DOL_BUH','Должность главного бухгалтера (уполномоченного руководителем лица)','STRING',100,0,0,0,'DOL_BUH','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 17,
		NAME   		= 'ФИО главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_BUH',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 17,'NAME_BUH','ФИО главного бухгалтера (уполномоченного руководителем лица)','STRING',50,0,0,0,'NAME_BUH','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 18,
		NAME   		= 'Дата подписания заявки',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_POD',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 18,'DATE_POD','Дата подписания заявки','DATE',0,0,0,1,'DATE_POD','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_ITOG')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 19,
		NAME   		= 'Сумма денежных средств',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUMMA_ITOG',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_ITOG'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 19,'SUMMA_ITOG','Сумма денежных средств','NUMBER2',0,1,1,1,'SUMMA_ITOG','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_R2')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 20,
		NAME   		= 'Общая сумма',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUMMA_R2',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_R2'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 20,'SUMMA_R2','Общая сумма','NUMBER2',0,1,1,1,'SUMMA_R2','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'RNKBK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'RNKBK',5,2,'Расшифровка заявки',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 5,
			ISONCE = 2,
			NAME   = 'Расшифровка заявки',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'POR_NUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Порядковый номер',
		VAL_TYPE 	= 'NUMBER',
		VAL_LEN 	= 8,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'POR_NUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'POR_NUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'POR_NUM','Порядковый номер','NUMBER',8,0,0,1,'POR_NUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код по БК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KBK','Код по БК','STRING',20,1,1,0,'KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Тип КБК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'TYPE_KBK','Тип КБК','STRING',2,1,1,0,'TYPE_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Код цели субсидии',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'ADD_KLASS','Код цели субсидии','STRING',20,0,0,0,'ADD_KLASS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_V_SR')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Вид средств',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_V_SR',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_V_SR'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'NAME_V_SR','Вид средств','STRING',1,1,1,1,'NAME_V_SR','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Сумма в рублях',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'SUMMA',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'SUMMA','Сумма в рублях','NUMBER2',0,1,1,0,'SUMMA','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Примечание',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOTE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'NOTE','Примечание','STRING',2000,0,0,0,'NOTE','',''
GO

GO
update EXPORT_MODELS set DATE_END   = '31.12.2014' where MODEL_VER = 'TXVP141001' AND CODE = 'VP'
DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = 'TXVP150101' AND CODE = 'VP'
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT 'VP','Выписка из лицевого счета получателя бюджетных средств','TXVP150101',0,'','','fb_file_name_doc','BB_EXPORT_VP','','','bb_import_VP()',NULL 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = 0,
		NAME   = 'Выписка из лицевого счета получателя бюджетных средств',
		NORM_DOC   = '',
		FILE_NAME_MASK   = '',
		FILE_NAME_PROC   = 'fb_file_name_doc',
		PROC_EXP   = 'BB_EXPORT_VP',
		PROC_DOP_PARAM   = '',
		PROG_SAVE   = 'bb_import_VP()',
		DEP_NAME   = '',
		DATE_END   = NULL
	where LINK_MODEL = @varKSModelLink
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FK',1,0,'Маркер',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 1,
			ISONCE = 0,
			NAME   = 'Маркер',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер версии формата',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_VER','Номер версии формата','STRING',10,0,1,1,'NUM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование программного продукта, сформировавшего файл',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORMER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'FORMER','Наименование программного продукта, сформировавшего файл','STRING',50,0,0,1,'FORMER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Версия программного продукта',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'FORM_VER','Версия программного продукта','STRING',10,0,0,1,'FORM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'сылка на документ, утверждающий формат файла',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NORM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NORM_DOC','сылка на документ, утверждающий формат файла','STRING',250,0,0,0,'NORM_DOC','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FROM'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FROM',2,0,'Почтовая информация о получателе файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 2,
			ISONCE = 0,
			NAME   = 'Почтовая информация о получателе файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_TOFK','Код ОрФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NAME_TOFK','Наименование ОрФК','STRING',2000,0,1,1,'NAME_TOFK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'TO'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'TO',3,0,'Почтовая информация об отправителях файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 3,
			ISONCE = 0,
			NAME   = 'Почтовая информация об отправителях файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Уровень бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BUDG_LEVEL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'BUDG_LEVEL','Уровень бюджета','STRING',1,1,0,0,'BUDG_LEVEL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOD_UBP','Код УБП','STRING',5,1,1,1,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Наименование УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NAME_UBP','Наименование УБП','STRING',254,0,1,1,'NAME_UBP','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'VP'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'VP',4,0,'Общая информация',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 4,
			ISONCE = 0,
			NAME   = 'Общая информация',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Глобальный уникальный идентификатор',
		VAL_TYPE 	= 'GUID',
		VAL_LEN 	= 36,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'GUID_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'GUID_FK','Глобальный уникальный идентификатор','GUID',36,1,0,1,'GUID_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Номер лицевого счета клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'LS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'LS','Номер лицевого счета клиента','STRING',11,0,0,1,'LS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Дата',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'DATE','Дата','DATE',0,0,0,0,'DATE','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'VPPP'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'VPPP',5,2,'Информация из расчетных до-кументов',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 5,
			ISONCE = 2,
			NAME   = 'Информация из расчетных до-кументов',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер документа, подтверждающего проведение операции',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_DOC','Номер документа, подтверждающего проведение операции','STRING',15,0,1,1,'NUM_DOC','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Дата документа, подтверждающе-го проведение операции',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'DATE_DOC','Дата документа, подтверждающе-го проведение операции','DATE',0,1,1,1,'DATE_DOC','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Глобальный уни-кальный идентификатор',
		VAL_TYPE 	= 'GUID',
		VAL_LEN 	= 36,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'GUID',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'GUID','Глобальный уни-кальный идентификатор','GUID',36,1,0,1,'GUID','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOC_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Номер доку-мента получателя бюд-жетных средств',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NUM_DOC_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_DOC_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NUM_DOC_UBP','Номер доку-мента получателя бюд-жетных средств','STRING',20,0,0,0,'NUM_DOC_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOC_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Дата документа получателя бюд-жетных средств',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_DOC_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOC_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'DATE_DOC_UBP','Дата документа получателя бюд-жетных средств','DATE',0,0,0,0,'DATE_DOC_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Код объекта ФАИП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 14,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'FAIP_CODE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'FAIP_CODE','Код объекта ФАИП','STRING',14,1,0,0,'FAIP_CODE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Код цели (анали-тический код)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'ADD_KLASS','Код цели (анали-тический код)','STRING',20,0,0,0,'ADD_KLASS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_OUT')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'Выплаты',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM_OUT',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_OUT'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'SUM_OUT','Выплаты','NUMBER2',0,0,1,1,'SUM_OUT','',''
GO

GO
update EXPORT_MODELS set DATE_END   = '31.12.2014' where MODEL_VER = 'TXZN130701' AND CODE = 'ZN'
DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = 'TXZN150101' AND CODE = 'ZN'
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT 'ZN','Заявка на получение денежных средств, перечисляемых на карту','TXZN150101',0,'','XXXXXDNN.TTM','fb_file_name_doc','BB_EXPORT_ZN','','KOD_UBP','',NULL 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = 0,
		NAME   = 'Заявка на получение денежных средств, перечисляемых на карту',
		NORM_DOC   = '',
		FILE_NAME_MASK   = 'XXXXXDNN.TTM',
		FILE_NAME_PROC   = 'fb_file_name_doc',
		PROC_EXP   = 'BB_EXPORT_ZN',
		PROC_DOP_PARAM   = '',
		PROG_SAVE   = '',
		DEP_NAME   = 'KOD_UBP',
		DATE_END   = NULL
	where LINK_MODEL = @varKSModelLink
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FK',1,0,'Маркер',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 1,
			ISONCE = 0,
			NAME   = 'Маркер',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер версии формата',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_VER','Номер версии формата','STRING',10,0,1,1,'NUM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование программного продукта, сформировавшего файл',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORMER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'FORMER','Наименование программного продукта, сформировавшего файл','STRING',50,0,0,1,'FORMER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Версия программного продукта',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'FORM_VER','Версия программного продукта','STRING',10,0,0,1,'FORM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'сылка на документ, утверждающий формат файла',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NORM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NORM_DOC','сылка на документ, утверждающий формат файла','STRING',250,0,0,0,'NORM_DOC','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FROM'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FROM',2,0,'Почтовая информация об отправителях файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 2,
			ISONCE = 0,
			NAME   = 'Почтовая информация об отправителях файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Уровень бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BUDG_LEVEL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'BUDG_LEVEL','Уровень бюджета','STRING',1,1,0,1,'BUDG_LEVEL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOD_UBP','Код УБП','STRING',5,1,1,1,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Наименование УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NAME_UBP','Наименование УБП','STRING',254,0,1,1,'NAME_UBP','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'TO'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'TO',3,0,'Почтовая информация о получателе файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 3,
			ISONCE = 0,
			NAME   = 'Почтовая информация о получателе файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_TOFK','Код ОрФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NAME_TOFK','Наименование ОрФК','STRING',2000,0,1,1,'NAME_TOFK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'ZN'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'ZN',4,2,'Общая инфор-мация',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 4,
			ISONCE = 2,
			NAME   = 'Общая инфор-мация',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Глобальный уникальный идентификатор',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 36,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GUID_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'GUID_FK','Глобальный уникальный идентификатор','STRING',36,0,0,0,'GUID_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Номер заявки',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NOM_ZN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NOM_ZN','Номер заявки','STRING',15,0,1,1,'NOM_ZN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ZN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Дата заявки',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_ZN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ZN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'DATE_ZN','Дата заявки','DATE',0,1,1,1,'DATE_ZN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Код ПБС по Сводному ре-естру',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'KOD_UBP','Код ПБС по Сводному ре-естру','STRING',5,1,0,0,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Наименование клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'NAME_UBP','Наименование клиента','STRING',2000,0,1,1,'NAME_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Код органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'KOD_TOFK','Код органа ФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Наименование органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'NAME_TOFK','Наименование органа ФК','STRING',2000,0,1,1,'NAME_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'Номер лицевого счета клиента.',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'LS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'LS_PAY','Номер лицевого счета клиента.','STRING',11,1,1,1,'LS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_BO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'Номер обязательства',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 16,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOM_BO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_BO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'NOM_BO','Номер обязательства','STRING',16,1,0,0,'NOM_BO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 10,
		NAME   		= 'Код объекта по ФАИП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 14,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'FAIP_CODE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 10,'FAIP_CODE','Код объекта по ФАИП','STRING',14,1,0,0,'FAIP_CODE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 11,
		NAME   		= 'ИНН',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'INN_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 11,'INN_UBP','ИНН','STRING',10,1,0,1,'INN_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 12,
		NAME   		= 'КПП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KPP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 12,'KPP','КПП','STRING',9,1,0,1,'KPP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'CARD_NUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 13,
		NAME   		= 'Номер банков-ской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'CARD_NUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'CARD_NUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 13,'CARD_NUM','Номер банков-ской карты','STRING',20,0,0,1,'CARD_NUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_V_SR')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 14,
		NAME   		= 'Вид средств',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_V_SR',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_V_SR'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 14,'NAME_V_SR','Вид средств','STRING',1,1,0,1,'NAME_V_SR','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_ISP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 15,
		NAME   		= 'Должность вла-дельца банков-ской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DOL_ISP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_ISP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 15,'DOL_ISP','Должность вла-дельца банков-ской карты','STRING',100,0,0,1,'DOL_ISP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_F')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 16,
		NAME   		= 'Фамилия вла-дельца банков-ской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 40,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'ISP_F',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_F'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 16,'ISP_F','Фамилия вла-дельца банков-ской карты','STRING',40,0,0,1,'ISP_F','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_I')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 17,
		NAME   		= 'Имя владельца банковской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'ISP_I',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_I'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 17,'ISP_I','Имя владельца банковской карты','STRING',20,0,0,1,'ISP_I','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_O')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 18,
		NAME   		= 'Отчество вла-дельца банков-ской карты',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 30,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'ISP_O',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ISP_O'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 18,'ISP_O','Отчество вла-дельца банков-ской карты','STRING',30,0,0,1,'ISP_O','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 19,
		NAME   		= 'Должность руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DOL_RUK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 19,'DOL_RUK','Должность руководителя (уполномоченного им лица)','STRING',100,0,0,1,'DOL_RUK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 20,
		NAME   		= 'ФИО руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_RUK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 20,'NAME_RUK','ФИО руководителя (уполномоченного им лица)','STRING',50,0,0,1,'NAME_RUK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 21,
		NAME   		= 'Должность главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DOL_BUH',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 21,'DOL_BUH','Должность главного бухгалтера (уполномоченного руководителем лица)','STRING',100,0,0,0,'DOL_BUH','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 22,
		NAME   		= 'ФИО главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_BUH',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 22,'NAME_BUH','ФИО главного бухгалтера (уполномоченного руководителем лица)','STRING',50,0,0,0,'NAME_BUH','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 23,
		NAME   		= 'Дата подписания заявки',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_POD',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 23,'DATE_POD','Дата подписания заявки','DATE',0,0,0,1,'DATE_POD','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_ITOG')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 24,
		NAME   		= 'Сумма денежных средств',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUMMA_ITOG',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_ITOG'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 24,'SUMMA_ITOG','Сумма денежных средств','NUMBER2',0,1,1,1,'SUMMA_ITOG','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_R2')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 25,
		NAME   		= 'Общая сумма',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUMMA_R2',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMMA_R2'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 25,'SUMMA_R2','Общая сумма','NUMBER2',0,1,1,1,'SUMMA_R2','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'ZNKBK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'ZNKBK',5,2,'Расшифровка заявки',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 5,
			ISONCE = 2,
			NAME   = 'Расшифровка заявки',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'POR_NUM')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Порядковый номер',
		VAL_TYPE 	= 'NUMBER',
		VAL_LEN 	= 8,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'POR_NUM',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'POR_NUM'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'POR_NUM','Порядковый номер','NUMBER',8,0,0,1,'POR_NUM','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код по БК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KBK','Код по БК','STRING',20,1,1,0,'KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Тип КБК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'TYPE_KBK','Тип КБК','STRING',2,1,1,0,'TYPE_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Код цели субсидии',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'ADD_KLASS','Код цели субсидии','STRING',20,0,0,0,'ADD_KLASS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Назначение платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 210,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PURPOSE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'PURPOSE','Назначение платежа','STRING',210,0,0,0,'PURPOSE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMR_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Сумма в рублях',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'SUMR_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUMR_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'SUMR_KBK','Сумма в рублях','NUMBER2',0,1,1,0,'SUMR_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Примечание',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOTE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'NOTE','Примечание','STRING',2000,0,0,0,'NOTE','',''
GO

GO
update EXPORT_MODELS set DATE_END   = '31.12.2014' where MODEL_VER = 'TXZR140101' AND CODE = 'ZR'
DECLARE @varKSModelLink INT,
	@varKSBlockLink INT
SELECT @varKSModelLink = LINK_MODEL FROM dbo.EXPORT_MODELS WHERE MODEL_VER = 'TXZR150101' AND CODE = 'ZR'
IF @varKSModelLink is null
begin
	INSERT INTO EXPORT_MODELS(CODE, NAME, MODEL_VER, ISONCE, NORM_DOC, FILE_NAME_MASK, FILE_NAME_PROC, PROC_EXP, PROC_DOP_PARAM, DEP_NAME, PROG_SAVE, DATE_END)
	SELECT 'ZR','Заявка на кассовый расход','TXZR150101',0,'','XXXXXDNN.TTM','fb_file_name_doc','BB_EXPORT_ZKR','cModelVer','KOD_UBP','bb_import_zkr()',NULL 
	SET @varKSModelLink = @@IDENTITY
end
else
	update EXPORT_MODELS
	set 	ISONCE = 0,
		NAME   = 'Заявка на кассовый расход',
		NORM_DOC   = '',
		FILE_NAME_MASK   = 'XXXXXDNN.TTM',
		FILE_NAME_PROC   = 'fb_file_name_doc',
		PROC_EXP   = 'BB_EXPORT_ZKR',
		PROC_DOP_PARAM   = 'cModelVer',
		PROG_SAVE   = 'bb_import_zkr()',
		DEP_NAME   = 'KOD_UBP',
		DATE_END   = NULL
	where LINK_MODEL = @varKSModelLink
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FK'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FK',1,0,'Маркер',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 1,
			ISONCE = 0,
			NAME   = 'Маркер',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Номер версии формата',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NUM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NUM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'NUM_VER','Номер версии формата','STRING',10,0,1,1,'NUM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование программного продукта, сформировавшего файл',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORMER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORMER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'FORMER','Наименование программного продукта, сформировавшего файл','STRING',50,0,0,1,'FORMER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Версия программного продукта',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'FORM_VER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FORM_VER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'FORM_VER','Версия программного продукта','STRING',10,0,0,1,'FORM_VER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'сылка на документ, утверждающий формат файла',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NORM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NORM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'NORM_DOC','сылка на документ, утверждающий формат файла','STRING',250,0,0,0,'NORM_DOC','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'FROM'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'FROM',2,0,'Почтовая информация об отправителях файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 2,
			ISONCE = 0,
			NAME   = 'Почтовая информация об отправителях файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Уровень бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'BUDG_LEVEL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BUDG_LEVEL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'BUDG_LEVEL','Уровень бюджета','STRING',1,1,0,1,'BUDG_LEVEL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Код УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'KOD_UBP','Код УБП','STRING',5,1,1,1,'KOD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Наименование УБП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NAME_UBP','Наименование УБП','STRING',254,0,1,1,'NAME_UBP','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'TO'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'TO',3,0,'Почтовая информация о получателе файла',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 3,
			ISONCE = 0,
			NAME   = 'Почтовая информация о получателе файла',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Код ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_TOFK','Код ОрФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Наименование ОрФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'NAME_TOFK','Наименование ОрФК','STRING',2000,0,1,1,'NAME_TOFK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'ZR'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'ZR',4,2,'Общая информация',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 4,
			ISONCE = 2,
			NAME   = 'Общая информация',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Глобальный уникальный идентификатор',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 36,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GUID_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'GUID_FK','Глобальный уникальный идентификатор','STRING',36,0,0,0,'GUID_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Тип заявки',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'TYPE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'TYPE','Тип заявки','STRING',1,1,1,1,'TYPE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZR')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Номер заявки',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NOM_ZR',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZR'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NOM_ZR','Номер заявки','STRING',15,0,1,1,'NOM_ZR','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ZR')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Дата заявки',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_ZR',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ZR'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'DATE_ZR','Дата заявки','DATE',0,1,1,1,'DATE_ZR','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Код клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 5,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KOD_UBP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_UBP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'KOD_UBP_PAY','Код клиента','STRING',5,0,0,0,'KOD_UBP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Наименование клиентаклиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_UBP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'NAME_UBP_PAY','Наименование клиентаклиента','STRING',2000,0,1,1,'NAME_UBP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_UBP_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Номер лицевого счета клиента.',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'LS_UBP_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_UBP_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'LS_UBP_PAY','Номер лицевого счета клиента.','STRING',11,1,1,1,'LS_UBP_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'ИНН клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'INN_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'INN_UBP','ИНН клиента','STRING',10,1,0,0,'INN_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'КПП клиента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KPP_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'KPP_UBP','КПП клиента','STRING',9,1,0,0,'KPP_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GLAVA_GRS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 10,
		NAME   		= 'Глава по БК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 3,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GLAVA_GRS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GLAVA_GRS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 10,'GLAVA_GRS','Глава по БК','STRING',3,1,0,0,'GLAVA_GRS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_GRS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 11,
		NAME   		= 'Наименование ГРБС (ГАИФДБ)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_UBP_GRS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_UBP_GRS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 11,'NAME_UBP_GRS','Наименование ГРБС (ГАИФДБ)','STRING',2000,0,1,0,'NAME_UBP_GRS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUD')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 12,
		NAME   		= 'Наименование бюджета',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 512,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_BUD',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUD'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 12,'NAME_BUD','Наименование бюджета','STRING',512,0,0,0,'NAME_BUD','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_FO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 13,
		NAME   		= 'Наименование финансового органа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_FO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_FO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 13,'NAME_FO','Наименование финансового органа','STRING',2000,0,1,0,'NAME_FO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OKPO_FO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 14,
		NAME   		= 'Код по ОКПО',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 8,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OKPO_FO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OKPO_FO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 14,'OKPO_FO','Код по ОКПО','STRING',8,1,0,0,'OKPO_FO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 15,
		NAME   		= 'Код органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 4,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 15,'KOD_TOFK','Код органа ФК','STRING',4,1,1,1,'KOD_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 16,
		NAME   		= 'Наименование органа ФК',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2000,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_TOFK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_TOFK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 16,'NAME_TOFK','Наименование органа ФК','STRING',2000,0,1,1,'NAME_TOFK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ISP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 17,
		NAME   		= 'Предельная дата исполнения',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_ISP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_ISP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 17,'DATE_ISP','Предельная дата исполнения','DATE',0,1,1,0,'DATE_ISP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_SV')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 18,
		NAME   		= 'Идентификатор документа "Све-дения о принятом бюджетном обя-зательстве", предоставленного в ОрФК',
		VAL_TYPE 	= 'GUID',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'GUID_SV',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'GUID_SV'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 18,'GUID_SV','Идентификатор документа "Све-дения о принятом бюджетном обя-зательстве", предоставленного в ОрФК','GUID',0,0,0,0,'GUID_SV','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_BO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 19,
		NAME   		= 'Номер обязательства',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 16,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOM_BO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_BO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 19,'NOM_BO','Номер обязательства','STRING',16,1,0,0,'NOM_BO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_ISP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 20,
		NAME   		= 'Код приоритета исполнения',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KOD_ISP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_ISP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 20,'KOD_ISP','Код приоритета исполнения','STRING',1,1,0,0,'KOD_ISP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PR_ISP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 21,
		NAME   		= 'Приоритет исполнения',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 250,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PR_ISP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PR_ISP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 21,'PR_ISP','Приоритет исполнения','STRING',250,0,0,0,'PR_ISP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 22,
		NAME   		= 'Код объекта по ФАИП',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 14,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'FAIP_CODE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'FAIP_CODE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 22,'FAIP_CODE','Код объекта по ФАИП','STRING',14,1,0,0,'FAIP_CODE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_V')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 23,
		NAME   		= 'Сумма документа в валюте выплаты',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM_V',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_V'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 23,'SUM_V','Сумма документа в валюте выплаты','NUMBER2',0,1,0,1,'SUM_V','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_V')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 24,
		NAME   		= 'Код валюты по ОКВ',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 3,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_V',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_V'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 24,'KOD_V','Код валюты по ОКВ','STRING',3,1,0,1,'KOD_V','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_DOC')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 25,
		NAME   		= 'Сумма документа',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'SUM_DOC',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_DOC'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 25,'SUM_DOC','Сумма документа','NUMBER2',0,1,1,0,'SUM_DOC','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_AP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 26,
		NAME   		= 'Признак авансового платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'TYPE_AP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_AP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 26,'TYPE_AP','Признак авансового платежа','STRING',1,1,0,1,'TYPE_AP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ORDER_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 27,
		NAME   		= 'Очередность платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'ORDER_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ORDER_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 27,'ORDER_PL','Очередность платежа','STRING',1,1,1,1,'ORDER_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 28,
		NAME   		= 'Вид платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'VID_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 28,'VID_PL','Вид платежа','STRING',1,1,1,1,'VID_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 29,
		NAME   		= 'Назначение платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 210,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'PURPOSE',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 29,'PURPOSE','Назначение платежа','STRING',210,0,1,1,'PURPOSE','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 30,
		NAME   		= 'Наименование / ФИО контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 30,'NAME_RCP','Наименование / ФИО контрагента','STRING',160,0,1,1,'NAME_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 31,
		NAME   		= 'ИНН контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 12,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'INN_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'INN_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 31,'INN_RCP','ИНН контрагента','STRING',12,0,1,1,'INN_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 32,
		NAME   		= 'КПП контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 1,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KPP_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KPP_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 32,'KPP_RCP','КПП контрагента','STRING',9,0,1,1,'KPP_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_UBP_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 33,
		NAME   		= 'Лицевой счет контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'LS_UBP_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'LS_UBP_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 33,'LS_UBP_RCP','Лицевой счет контрагента','STRING',11,1,0,0,'LS_UBP_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 34,
		NAME   		= 'Банковский счет контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 34,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BS_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BS_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 34,'BS_RCP','Банковский счет контрагента','STRING',34,0,0,0,'BS_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 35,
		NAME   		= 'Наименование банка контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 160,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_BIC_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BIC_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 35,'NAME_BIC_RCP','Наименование банка контрагента','STRING',160,0,0,1,'NAME_BIC_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 36,
		NAME   		= 'БИК банка контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 9,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'BIC_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'BIC_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 36,'BIC_RCP','БИК банка контрагента','STRING',9,1,0,0,'BIC_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KS_BIC_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 37,
		NAME   		= 'Корсчет банка контрагента',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 34,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KS_BIC_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KS_BIC_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 37,'KS_BIC_RCP','Корсчет банка контрагента','STRING',34,0,0,0,'KS_BIC_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PAYSTATUS')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 38,
		NAME   		= 'Статус налогоплательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PAYSTATUS',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PAYSTATUS'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 38,'PAYSTATUS','Статус налогоплательщика','STRING',2,1,0,0,'PAYSTATUS','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KDOH')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 39,
		NAME   		= 'Код бюджетной классификации',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KDOH',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KDOH'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 39,'KDOH','Код бюджетной классификации','STRING',20,1,0,0,'KDOH','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OKATO')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 40,
		NAME   		= 'Код ОКАТО',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 11,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OKATO',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OKATO'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 40,'OKATO','Код ОКАТО','STRING',11,0,0,0,'OKATO','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 41,
		NAME   		= 'Показатель основания платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OSN_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 41,'OSN_PL','Показатель основания платежа','STRING',2,0,0,0,'OSN_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAL_PER')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 42,
		NAME   		= 'Показатель налогового периода',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAL_PER',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAL_PER'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 42,'NAL_PER','Показатель налогового периода','STRING',10,0,0,0,'NAL_PER','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_DOK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 43,
		NAME   		= 'Показатель номера документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOM_DOK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_DOK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 43,'NOM_DOK','Показатель номера документа','STRING',15,0,0,0,'NOM_DOK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 44,
		NAME   		= 'Показатель даты документа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 10,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_DOK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_DOK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 44,'DATE_DOK','Показатель даты документа','STRING',10,0,0,0,'DATE_DOK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_PL')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 45,
		NAME   		= 'Тип платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_PL',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_PL'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 45,'TYPE_PL','Тип платежа','STRING',2,0,0,0,'TYPE_PL','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 46,
		NAME   		= 'Должность руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DOL_RUK_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_RUK_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 46,'DOL_RUK_UBP','Должность руководителя (уполномоченного им лица)','STRING',100,0,0,0,'DOL_RUK_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 47,
		NAME   		= 'ФИО руководителя (уполномоченного им лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NAME_RUK_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_RUK_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 47,'NAME_RUK_UBP','ФИО руководителя (уполномоченного им лица)','STRING',50,0,0,1,'NAME_RUK_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 48,
		NAME   		= 'Должность главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DOL_BUH_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_BUH_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 48,'DOL_BUH_UBP','Должность главного бухгалтера (уполномоченного руководителем лица)','STRING',100,0,0,0,'DOL_BUH_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 49,
		NAME   		= 'ФИО главного бухгалтера (уполномоченного руководителем лица)',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_BUH_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_BUH_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 49,'NAME_BUH_UBP','ФИО главного бухгалтера (уполномоченного руководителем лица)','STRING',50,0,0,0,'NAME_BUH_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD_UBP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 50,
		NAME   		= 'Дата подписания заявки',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'DATE_POD_UBP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_POD_UBP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 50,'DATE_POD_UBP','Дата подписания заявки','DATE',0,0,0,1,'DATE_POD_UBP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZR_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 51,
		NAME   		= 'Отметка ОрФК о постановке на учет / Номер заявки',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 15,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOM_ZR_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_ZR_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 51,'NOM_ZR_FK','Отметка ОрФК о постановке на учет / Номер заявки','STRING',15,0,0,0,'NOM_ZR_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 52,
		NAME   		= 'Отметка ОрФК о постановке на учет / Дата постановки на учет',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 52,'DATE_FK','Отметка ОрФК о постановке на учет / Дата постановки на учет','DATE',0,1,0,0,'DATE_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_ISP_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 53,
		NAME   		= 'Отметка ОрФК о постановке на учет / Должность ответственного исполнителя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 100,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DOL_ISP_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DOL_ISP_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 53,'DOL_ISP_FK','Отметка ОрФК о постановке на учет / Должность ответственного исполнителя','STRING',100,0,0,0,'DOL_ISP_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_ISP_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 54,
		NAME   		= 'Отметка ОрФК о постановке на учет / ФИО ответственного исполнителя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NAME_ISP_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NAME_ISP_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 54,'NAME_ISP_FK','Отметка ОрФК о постановке на учет / ФИО ответственного исполнителя','STRING',50,0,0,0,'NAME_ISP_FK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TEL_ISP_FK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 55,
		NAME   		= 'Отметка ОрФК о постановке на учет / Телефон ответственного исполнителя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TEL_ISP_FK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TEL_ISP_FK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 55,'TEL_ISP_FK','Отметка ОрФК о постановке на учет / Телефон ответственного исполнителя','STRING',50,0,0,0,'TEL_ISP_FK','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'ZROSN'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'ZROSN',5,2,'Реквизиты документов-оснований',0
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 5,
			ISONCE = 2,
			NAME   = 'Реквизиты документов-оснований',
			OBLIGATORY = 0
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN_PLAT')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Признак основания платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OSN_PLAT',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN_PLAT'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'OSN_PLAT','Признак основания платежа','STRING',1,0,0,0,'OSN_PLAT','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OSN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Вид документа-основания',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 50,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'VID_OSN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'VID_OSN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'VID_OSN','Вид документа-основания','STRING',50,0,0,1,'VID_OSN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_OSN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Номер документа-основания',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 45,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'NOM_OSN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOM_OSN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'NOM_OSN','Номер документа-основания','STRING',45,0,0,1,'NOM_OSN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_OSN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Дата документа-основания',
		VAL_TYPE 	= 'DATE',
		VAL_LEN 	= NULL,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'DATE_OSN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'DATE_OSN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'DATE_OSN','Дата документа-основания','DATE',NULL,0,0,0,'DATE_OSN','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Предмет документа-основания',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 512,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'OSN',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'OSN'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'OSN','Предмет документа-основания','STRING',512,0,0,0,'OSN','',''
set @varKSBlockLink = NULL
select 	@varKSBlockLink = LINK_BLOCK from dbo.EXPORT_BLOCKS where LINK_MODEL = @varKSModelLink and CODE = 'ZRST'
if @varKSBlockLink is null
begin
	INSERT INTO EXPORT_BLOCKS(LINK_MODEL,CODE, ORDERS, ISONCE, NAME, OBLIGATORY)
	SELECT @varKSModelLink,'ZRST',6,2,'Строки заявки на кассовый расход по бюджетной классификации',1
	SET @varKSBlockLink = @@IDENTITY
end
else
	update EXPORT_BLOCKS
	set 	ORDERS = 6,
			ISONCE = 2,
			NAME   = 'Строки заявки на кассовый расход по бюджетной классификации',
			OBLIGATORY = 1
	where LINK_BLOCK = @varKSBlockLink
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_IST_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 1,
		NAME   		= 'Источник средств',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 1,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'KOD_IST_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KOD_IST_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 1,'KOD_IST_KBK','Источник средств','STRING',1,1,0,1,'KOD_IST_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 2,
		NAME   		= 'Тип КБК плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_KBK_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 2,'TYPE_KBK_PAY','Тип КБК плательщика','STRING',2,1,1,0,'TYPE_KBK_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 3,
		NAME   		= 'Код по БК плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 3,'KBK_PAY','Код по БК плательщика','STRING',20,1,1,0,'KBK_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 4,
		NAME   		= 'Тип КБК получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 2,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'TYPE_KBK_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'TYPE_KBK_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 4,'TYPE_KBK_RCP','Тип КБК получателя','STRING',2,1,0,0,'TYPE_KBK_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 5,
		NAME   		= 'Код по БК получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'KBK_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'KBK_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 5,'KBK_RCP','Код по БК получателя','STRING',20,1,0,0,'KBK_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_PAY')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 6,
		NAME   		= 'Код цели субсидии / субвенции плательщика',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS_PAY',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_PAY'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 6,'ADD_KLASS_PAY','Код цели субсидии / субвенции плательщика','STRING',20,0,0,0,'ADD_KLASS_PAY','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_RCP')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 7,
		NAME   		= 'Код цели субсидии / субвенции получателя',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 20,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'ADD_KLASS_RCP',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'ADD_KLASS_RCP'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 7,'ADD_KLASS_RCP','Код цели субсидии / субвенции получателя','STRING',20,0,0,0,'ADD_KLASS_RCP','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_V_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 8,
		NAME   		= 'Сумма в валюте заявки',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 0,
		OBLIGATORY	= 1,
		ALIAS_CODE	= 'SUM_V_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_V_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 8,'SUM_V_KBK','Сумма в валюте заявки','NUMBER2',0,1,0,1,'SUM_V_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_R_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 9,
		NAME   		= 'Сумма в рублях',
		VAL_TYPE 	= 'NUMBER2',
		VAL_LEN 	= 0,
		VAL_LEN_EQ	= 1,
		NEED_CHECK	= 1,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'SUM_R_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'SUM_R_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 9,'SUM_R_KBK','Сумма в рублях','NUMBER2',0,1,1,0,'SUM_R_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 10,
		NAME   		= 'Назначение платежа',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 210,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'PURPOSE_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'PURPOSE_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 10,'PURPOSE_KBK','Назначение платежа','STRING',210,0,0,0,'PURPOSE_KBK','',''
if exists(select * from EXPORT_FIELDS where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE_KBK')
	UPDATE EXPORT_FIELDS
	SET 	ORDERS 		= 11,
		NAME   		= 'Примечание',
		VAL_TYPE 	= 'STRING',
		VAL_LEN 	= 254,
		VAL_LEN_EQ	= 0,
		NEED_CHECK	= 0,
		OBLIGATORY	= 0,
		ALIAS_CODE	= 'NOTE_KBK',
		CHECK_PROC	= '',
		VAL_LIST	= ''
	where LINK_BLOCK = @varKSBlockLink and CODE = 'NOTE_KBK'
else		
	INSERT INTO EXPORT_FIELDS (LINK_BLOCK, ORDERS, CODE, NAME, VAL_TYPE, VAL_LEN, VAL_LEN_EQ, NEED_CHECK, OBLIGATORY, ALIAS_CODE, CHECK_PROC, VAL_LIST)
	SELECT @varKSBlockLink, 11,'NOTE_KBK','Примечание','STRING',254,0,0,0,'NOTE_KBK','',''
GO

GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC', 'Размещение госзаказа', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC', NAME = 'Размещение госзаказа', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_GZ_DOC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_NUMBER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_NUMBER', '№ договора', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_NUMBER', NAME = '№ договора', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_NUMBER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DATE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DATE', 'Учетная дата', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DATE', NAME = 'Учетная дата', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DATE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DATE_PROV')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DATE_PROV', 'Дата утверждения', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DATE_PROV', NAME = 'Дата утверждения', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DATE_PROV'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_SUMMA', 'Сумма договора', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_SUMMA', NAME = 'Сумма договора', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DATE_BEG')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DATE_BEG', 'Дата начала договора', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DATE_BEG', NAME = 'Дата начала договора', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DATE_BEG'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DATE_END')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DATE_END', 'Дата окончания договора', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DATE_END', NAME = 'Дата окончания договора', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DATE_END'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DEP_NAME', 'Наименование учреждения', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DEP_NAME', NAME = 'Наименование учреждения', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_MAINTENANCE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_MAINTENANCE', 'Примечание', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_MAINTENANCE', NAME = 'Примечание', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_MAINTENANCE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CONDITIONS_PAY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CONDITIONS_PAY', 'Условия оплаты', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CONDITIONS_PAY', NAME = 'Условия оплаты', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CONDITIONS_PAY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TYPE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TYPE', 'Вид закупок', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TYPE', NAME = 'Вид закупок', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TYPE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_NAME', 'Вид закупок', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_NAME', NAME = 'Вид закупок', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DEP2_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DEP2_CODE', 'Код организации', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DEP2_CODE', NAME = 'Код организации', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DEP2_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DEP2_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DEP2_NAME', 'Наименование организации', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DEP2_NAME', NAME = 'Наименование организации', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DEP2_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DEP_TYPE2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DEP_TYPE2', 'Тип организации', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DEP_TYPE2', NAME = 'Тип организации', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DEP_TYPE2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE', 'Таблица закупок', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE', NAME = 'Таблица закупок', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_REC_NO')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_REC_NO', 'Номер', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_REC_NO', NAME = 'Номер', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_REC_NO'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_KBK_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_KBK_CODE', 'Код ВКР', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_KBK_CODE', NAME = 'Код ВКР', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_KBK_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_KBK_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_KBK_NAME', 'Наименование ВКР', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_KBK_NAME', NAME = 'Наименование ВКР', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_KBK_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_EKR_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'Код ЭКР', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_EKR_CODE', NAME = 'Код ЭКР', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_EKR_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_EKR_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_EKR_NAME', 'Наименование ЭКР', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_EKR_NAME', NAME = 'Наименование ЭКР', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_EKR_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TAB_DOP_CL_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'Код доп. классификации', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TAB_DOP_CL_CODE', NAME = 'Код доп. классификации', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TAB_DOP_CL_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DOP_CLASSIF_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'Наименование доп. классификации', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DOP_CLASSIF_NAME', NAME = 'Наименование доп. классификации', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DOP_CLASSIF_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_OKDP_CODE', 'Код ОКДП', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'Наименование', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', NAME = 'Наименование', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_COST', 'Цена', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_COST', NAME = 'Цена', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'Наименование Ед. изм.', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_UM_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'Количество', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_QUANTITY', NAME = 'Количество', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_SUMMA', 'Сумма', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_SUMMA', NAME = 'Сумма', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_OKPD_CODE', 'Код ОКПД', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_OKPD_NAM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'Наименование', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', NAME = 'Наименование', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_OKPD_NAM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_UM1_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'Наименование Ед. изм.', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_UM1_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_UM1_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'TITLE', 'Размещение госзаказа'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'INIT_OBJECT_METHOD', 'FB_SPISOK_FINANS("BB_GZ_DOC")'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'REMOVE_OBJECT_METHOD', 'I_DELETE_RECORDS(m.oForm.Alias, "BB_GZ_DOC", "BV_DELETE_DOCUMENTS", 4, .F., .F.)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BB_SAVE_GZ_DOC'', m.cAlias,"NUMBER, SQLNULL(DATE), SQLNULL(DATE_PROV), SUMMA, COMMENT, SQLNULL(DEP_LINK), SQLNULL(ACC_LINK), SQLNULL(DATE_BEG), SQLNULL(DATE_END), CON_PAY, TYPE,SQLNULL(DEP_GZ_LINK)", "BB_GZ_DOC")

'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'EDIT_OBJECT_METHOD', 'gz_brow("bb_gz_doc")'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_LIST_ZB(m.Obj_Code)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DOCUMENT_LIST(m.Obj_Code)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'HELP_TOPIC', '73'
GO
EXEC X_SET_PROP 'BB_GZ_DOC', 'OPERATION_MASK', '24'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'TITLE', '№ договора'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'CONTROLSOURCE', 'm.cAlias + ".NUMBER"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'TYPE_FIELD_DICT', 'CHAR(25)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NUMBER"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NUMBER', 'CONTROL_NAME_EDIT', 'TxtNum2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'TITLE', 'Дата'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'VISIBLE', '6'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'CONTROLSOURCE', 'm.cAlias+".DATE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DATE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE', 'CONTROL_NAME_EDIT', 'TxtProv1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'TITLE', 'Дата утверждения'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'VISIBLE', '6'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'CONTROLSOURCE', 'm.cAlias+".DATE_PROV"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DATE_PROV"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_PROV', 'CONTROL_NAME_EDIT', 'txtProv3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'TITLE', 'Сумма договора'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(13,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA_F'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_SUMMA', 'CONTROL_NAME_EDIT', 'ATxtN4'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'TITLE', 'Срок действия договора'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'CONTROLSOURCE', 'm.cAlias+".DATE_BEG"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'SHORT_CODE_OBJ', 'DATE_BEG'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DATE_BEG"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_BEG', 'CONTROL_NAME_EDIT', 'Aseldate13'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'TITLE', 'Дата окончания'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'CONTROLSOURCE', 'm.cAlias+".DATE_END"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'TYPE_FIELD_DICT', 'DATETIME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'SHORT_CODE_OBJ', 'DATE_END'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DATE_END"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DATE_END', 'CONTROL_NAME_EDIT', 'Aseldate15'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'TITLE', 'Учреждение'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'VISIBLE', '7'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'TITLE', 'Примечание'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'CONTROLSOURCE', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'TYPE_FIELD_DICT', 'VARCHAR(7500)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'SHORT_CODE_OBJ', 'COMENT'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_MAINTENANCE', 'CONTROL_NAME_EDIT', 'Aeditbox10'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'TITLE', 'Условия оплаты'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'CONTROLSOURCE', 'm.cAlias + ".CON_PAY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'STORAGE', 'VALUE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'TYPE_FIELD_DICT', 'TINYINT'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'SHORT_CODE_OBJ', 'CON_PAY'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CON_PAY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CONDITIONS_PAY', 'CONTROL_NAME_EDIT', 'ACmb4'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'TITLE', 'Вид закупок'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'CONTROLSOURCE', 'm.cAlias + ".TYPE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'TYPE_FIELD_DICT', 'TINYINT'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'SHORT_CODE_OBJ', 'TYPE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYPE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TYPE', 'CONTROL_NAME_EDIT', 'aCmbType2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'TITLE', 'Вид закупок'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'CONTROLSOURCE', 'm.cAlias + ".TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_NAME', 'SHORT_CODE_OBJ', 'TYPE_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'TITLE', 'Код организации'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'EDIT_OBJECT_METHOD', 'XD_VIBOR_GROUPED_01("DICTIONARY_DEPARTMENT", oForm.Alias, "LINK,CODE,NAME,DEP_TYPE2_NAME", "DEP_GZ_LINK, DEP_GZ_CODE, DEP_GZ_NAME,DEP_GZ_TYPE2_NAME", "", "", "", .T., 1, oForm, oObj,"",.F.,"DEPARTMENT_GROUPS")'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'CONTROLSOURCE', 'm.cAlias + ".DEP_GZ_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'TYPE_FIELD_DICT', 'char(21)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'SHORT_CODE_OBJ', 'DEP_GZ_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_GZ_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_CODE', 'CONTROL_NAME_EDIT', 'aSel_Spr7'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DEP_GZ_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'STORAGE', 'DEPARTMENTS'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'SHORT_CODE_OBJ', 'DEP_GZ_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_GZ_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP2_NAME', 'CONTROL_NAME_EDIT', 'aTxtN7'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'TITLE', 'Тип организации'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'CONTROLSOURCE', 'm.cAlias + ".DEP_GZ_TYPE2_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'SHORT_CODE_OBJ', 'DEP_GZ_TYPE2_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_GZ_TYPE2_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DEP_TYPE2', 'CONTROL_NAME_EDIT', 'aTxtDepType'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SAVE_OBJECT_METHOD', 'x_save(''BB_UPDATE_GZ_DOC_TABLE'', m.cAlias, ''LINK_UP, RECORD_NO,KBK, EKR, SQLNULL(DOP_CL), SQLNULL(OKDP),SQLNULL(OKPD),QUANTITY, COST,SUMMA'', ''BB_GZ_DOC_TABLE'')'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SELECT_RECORDS_METHOD', 'SQL.EXEC(''SELECT 0 as CHECKED, 0 as UPD, 0 as DEL, * FROM dbo.BB_GZ_DOC_TABLE WHERE LINK_UP = '' + str(m.nLink), m.cAlias) > 0'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SERVER_TABLE_NAME', 'GZ_TABLE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'TITLE', '№'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'CONTROLSOURCE', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'TYPE_FIELD_DICT', 'NUMERIC(10)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'SHORT_CODE_OBJ', 'RECORD_NO'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'INPUT_MASK', '999999999'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'TITLE', 'ВКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 ("bi_diction_kbk", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "KBK, KBK_CODE, KBK_NAME", "", "", "type=1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'CONTROLSOURCE', 'm.cAlias + ".KBK_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'STORAGE', 'KL_KBK'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'TYPE_FIELD_DICT', 'char(21)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'SHORT_CODE_OBJ', 'KBK_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".KBK_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'TITLE', 'Расш. ВКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'CONTROLSOURCE', 'm.cAlias + ".KBK_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'STORAGE', 'KL_KBK'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'SHORT_CODE_OBJ', 'KBK_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".KBK_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'TITLE', 'ЭКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 ("DICTIONARY_ITEM", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "EKR, EKR_CODE, EKR_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'CONTROLSOURCE', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'TYPE_FIELD_DICT', 'char(6)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'SHORT_CODE_OBJ', 'EKR_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'TITLE', 'Расш. ЭКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'CONTROLSOURCE', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'STORAGE', 'KOCGU'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'SHORT_CODE_OBJ', 'EKR_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'TITLE', 'Доп. классиф-ия'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BD_DOP_CLASSIF", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "DOP_CL, DOP_CL_CODE, DOP_CL_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'CONTROLSOURCE', 'm.cAlias + ".DOP_CL_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'STORAGE', 'DOP_CLASSIF'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'TYPE_FIELD_DICT', 'varchar(10)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'SHORT_CODE_OBJ', 'DOP_CL_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOP_CL_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'TITLE', 'Доп. классификация'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DOP_CL_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'STORAGE', 'DOP_CLASSIF'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'TYPE_FIELD_DICT', 'varchar(150)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'SHORT_CODE_OBJ', 'DOP_CL_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOP_CL_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'TITLE', 'Цена'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'CONTROLSOURCE', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'SHORT_CODE_OBJ', 'COST'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'SHORT_CODE_OBJ', 'UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'TITLE', 'Количество'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'SHORT_CODE_OBJ', 'QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM1_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'SHORT_CODE_OBJ', 'UM1_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM1_NAME"'
GO

GO
/****** Объект: Таблица закупок******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_DOC_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_DOC_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_DOC_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_DOC_TABLE')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_DOC_TABLE'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_DOC_TABLE')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE', 'Таблица закупок', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE', NAME = 'Таблица закупок', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_REC_NO')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_REC_NO', 'Номер', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_REC_NO', NAME = 'Номер', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_REC_NO'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_KBK_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_KBK_CODE', 'Код ВКР', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_KBK_CODE', NAME = 'Код ВКР', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_KBK_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_KBK_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_KBK_NAME', 'Наименование ВКР', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_KBK_NAME', NAME = 'Наименование ВКР', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_KBK_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_EKR_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'Код ЭКР', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_EKR_CODE', NAME = 'Код ЭКР', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_EKR_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_EKR_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_EKR_NAME', 'Наименование ЭКР', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_EKR_NAME', NAME = 'Наименование ЭКР', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_EKR_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TAB_DOP_CL_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'Код доп. классификации', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TAB_DOP_CL_CODE', NAME = 'Код доп. классификации', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TAB_DOP_CL_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_DOP_CLASSIF_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'Наименование доп. классификации', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_DOP_CLASSIF_NAME', NAME = 'Наименование доп. классификации', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_DOP_CLASSIF_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_OKDP_CODE', 'Код ОКДП', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'Наименование', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', NAME = 'Наименование', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_COST', 'Цена', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_COST', NAME = 'Цена', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'Наименование Ед. изм.', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_UM_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'Количество', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_QUANTITY', NAME = 'Количество', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_SUMMA', 'Сумма', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_SUMMA', NAME = 'Сумма', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_TABLE_OKPD_CODE', 'Код ОКПД', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_TABLE_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_TABLE_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_OKPD_NAM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'Наименование', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', NAME = 'Наименование', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_OKPD_NAM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_CON_TABLE_UM1_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'Наименование Ед. изм.', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_DOC_CON_TABLE_UM1_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_DOC_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_DOC_CON_TABLE_UM1_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SAVE_OBJECT_METHOD', 'x_save(''BB_UPDATE_GZ_DOC_TABLE'', m.cAlias, ''LINK_UP, RECORD_NO,KBK, EKR, SQLNULL(DOP_CL), SQLNULL(OKDP),SQLNULL(OKPD),QUANTITY, COST,SUMMA'', ''BB_GZ_DOC_TABLE'')'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SELECT_RECORDS_METHOD', 'SQL.EXEC(''SELECT 0 as CHECKED, 0 as UPD, 0 as DEL, * FROM dbo.BB_GZ_DOC_TABLE WHERE LINK_UP = '' + str(m.nLink), m.cAlias) > 0'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE', 'SERVER_TABLE_NAME', 'GZ_TABLE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_CHECKED', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'TITLE', '№'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'CONTROLSOURCE', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'TYPE_FIELD_DICT', 'NUMERIC(10)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'SHORT_CODE_OBJ', 'RECORD_NO'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_REC_NO', 'INPUT_MASK', '999999999'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'TITLE', 'ВКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 ("bi_diction_kbk", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "KBK, KBK_CODE, KBK_NAME", "", "", "type=1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'CONTROLSOURCE', 'm.cAlias + ".KBK_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'STORAGE', 'KL_KBK'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'TYPE_FIELD_DICT', 'char(21)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'SHORT_CODE_OBJ', 'KBK_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".KBK_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'TITLE', 'Расш. ВКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'CONTROLSOURCE', 'm.cAlias + ".KBK_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'STORAGE', 'KL_KBK'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'SHORT_CODE_OBJ', 'KBK_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_KBK_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".KBK_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'TITLE', 'ЭКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 ("DICTIONARY_ITEM", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "EKR, EKR_CODE, EKR_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'CONTROLSOURCE', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'TYPE_FIELD_DICT', 'char(6)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'SHORT_CODE_OBJ', 'EKR_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_EKR_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'TITLE', 'Расш. ЭКР'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'CONTROLSOURCE', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'STORAGE', 'KOCGU'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'SHORT_CODE_OBJ', 'EKR_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_EKR_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'TITLE', 'Доп. классиф-ия'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BD_DOP_CLASSIF", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "DOP_CL, DOP_CL_CODE, DOP_CL_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'CONTROLSOURCE', 'm.cAlias + ".DOP_CL_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'STORAGE', 'DOP_CLASSIF'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'TYPE_FIELD_DICT', 'varchar(10)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'SHORT_CODE_OBJ', 'DOP_CL_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TAB_DOP_CL_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOP_CL_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'TITLE', 'Доп. классификация'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DOP_CL_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'STORAGE', 'DOP_CLASSIF'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'TYPE_FIELD_DICT', 'varchar(150)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'SHORT_CODE_OBJ', 'DOP_CL_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_DOP_CLASSIF_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOP_CL_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'TITLE', 'Цена'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'CONTROLSOURCE', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'SHORT_CODE_OBJ', 'COST'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'SHORT_CODE_OBJ', 'UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'TITLE', 'Количество'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'SHORT_CODE_OBJ', 'QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM1_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_TABLE_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_OKPD_NAM', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'SHORT_CODE_OBJ', 'UM1_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_DOC_CON_TABLE_UM1_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM1_NAME"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_GZ_DOC_TABLE', 'Смета-КС', 63,0
GO


GO
/****** Объект: Таблица плана******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_PLAN_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_PLAN_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_PLAN_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_GZ_PLAN_TABLE')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_PLAN_TABLE'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_PLAN_TABLE')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE', 'Таблица плана', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE', NAME = 'Таблица плана', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_NUM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_NUM', '№ заказа', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_NUM', NAME = '№ заказа', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_NUM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'Код ОКДП', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'Наименование', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_OKDP_NAME', NAME = 'Наименование', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_UM_NAME', 'Наименование Ед. изм.', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_UM_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'Код ОКПД', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'Наименование', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_OKPD_NAME', NAME = 'Наименование', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_UM1_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_UM1_NAME', 'Наименование Ед. изм.', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_UM1_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_UM1_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_QUANTITY', 'Количество', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_QUANTITY', NAME = 'Количество', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_SUMMA', 'Сумма', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_SUMMA', NAME = 'Сумма', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_SUMMA_FIN')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'Объем финансирования', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_SUMMA_FIN', NAME = 'Объем финансирования', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_SUMMA_FIN'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_SUMMA_FB')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'Объем финансирования, бюджет', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_SUMMA_FB', NAME = 'Объем финансирования, бюджет', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_SUMMA_FB'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE_SUMMA_FV')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'Объем финансирования, внебюджет', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_PLAN_TABLE_SUMMA_FV', NAME = 'Объем финансирования, внебюджет', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_PLAN_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_PLAN_TABLE_SUMMA_FV'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE', 'SAVE_OBJECT_METHOD', 'x_save(''BB_UPDATE_GZ_PLAN_TABLE'', m.cAlias, ''LINK_UP, SQLNULL(OKDP),SQLNULL(OKPD),QUANTITY,SUMMA,SUMMA_FB,SUMMA_FV'', ''BB_GZ_PLAN_TABLE'')'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE', 'SELECT_RECORDS_METHOD', 'SQL.EXEC(''SELECT 0 as CHECKED, 0 as UPD, 0 as DEL, * FROM dbo.BB_GZ_PLAN_TABLE WHERE LINK_UP = '' + str(m.nLink), m.cAlias) > 0'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE', 'SERVER_TABLE_NAME', 'GZ_PLAN_TABLE'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_CHECKED', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_CHECKED', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_CHECKED', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'TITLE', '№ заказа'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'CONTROLSOURCE', 'm.cAlias + ".INDNUMBER"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'SHORT_CODE_OBJ', 'INDNUMBER'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_NUM', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".INDNUMBER"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'SHORT_CODE_OBJ', 'UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM1_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_OKPD_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'SHORT_CODE_OBJ', 'UM1_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_UM1_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'TITLE', 'Количество'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'SHORT_CODE_OBJ', 'QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'TITLE', 'Объем финансирования'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA_FIN"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'SHORT_CODE_OBJ', 'SUMMA_FIN'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FIN', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA_FIN"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'TITLE', 'Объем финансирования, бюджет'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'EDIT_OBJECT_METHOD', 'oForm.CalcFin()'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA_FB"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'SHORT_CODE_OBJ', 'SUMMA_FB'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FB', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA_FB"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'TITLE', 'Объем финансирования, внебюджет'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'EDIT_OBJECT_METHOD', 'oForm.CalcFin()'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA_FV"'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'SHORT_CODE_OBJ', 'SUMMA_FV'
GO
EXEC X_SET_PROP 'BB_GZ_PLAN_TABLE_SUMMA_FV', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA_FV"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_GZ_PLAN_TABLE', 'Смета-КС', 63,0
GO


GO
/****** Объект: Реестр госзакупок******/

if exists ( select * from DBO.S_NAVIGATOR where object = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_REESTR') and  name = 'Ресстр госзакупок')
	update DBO.S_NAVIGATOR
	set name = 'Реестр госзакупок'
	where object = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_GZ_REESTR') and  name = 'Ресстр госзакупок'
GO


IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR', 'Реестр госзакупок', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR', NAME = 'Реестр госзакупок', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='XDOCUMENT_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_GZ_REESTR'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_TYPE_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_TYPE_NAME', 'Вид строки', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_TYPE_NAME', NAME = 'Вид строки', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_TYPE_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_CONTRACT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_CONTRACT', 'Договор', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_CONTRACT', NAME = 'Договор', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_CONTRACT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_CON_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_CON_SUMMA', 'Сумма договора', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_CON_SUMMA', NAME = 'Сумма договора', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_CON_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_DOC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_DOC', 'Документ', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_DOC', NAME = 'Документ', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_DOC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_PROV')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_PROV', 'Проводка', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_PROV', NAME = 'Проводка', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_PROV'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_PROV_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_PROV_SUMMA', 'Сумма проводки', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_PROV_SUMMA', NAME = 'Сумма проводки', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_PROV_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_DEP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_DEP_NAME', 'Наименование учреждения', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_DEP_NAME', NAME = 'Наименование учреждения', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_DEP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_DEP_NAME_P')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_DEP_NAME_P', 'Наименование поставщика', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_DEP_NAME_P', NAME = 'Наименование поставщика', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_DEP_NAME_P'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_DEP_TYPE2_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'Тип поставщика', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_DEP_TYPE2_NAME', NAME = 'Тип поставщика', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_DEP_TYPE2_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_CONDITIONS_PAY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_CONDITIONS_PAY', 'Условия оплаты', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_CONDITIONS_PAY', NAME = 'Условия оплаты', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_CONDITIONS_PAY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_CON_TYPE_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_CON_TYPE_NAME', 'Вид торгов', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_CON_TYPE_NAME', NAME = 'Вид торгов', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_CON_TYPE_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_NOMEN_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_NOMEN_CODE', 'Номенклатурный №', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_NOMEN_CODE', NAME = 'Номенклатурный №', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_NOMEN_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_NOMEN_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_NOMEN_NAME', 'Наименование', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_NOMEN_NAME', NAME = 'Наименование', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_NOMEN_NAME'
GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_OKDP_CODE', 'Код ОКДП', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_OKDP_NAME', 'Наименование', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_OKDP_NAME', NAME = 'Наименование', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_OKDP_NAME'
GO


IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_OKPD_CODE', 'Код ОКПД', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_OKPD_NAME', 'Наименование', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_OKPD_NAME', NAME = 'Наименование', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T', 'Таблица закупок', 18, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T', NAME = 'Таблица закупок', ORDERS = '18', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_NOMEN_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_NOMEN_CODE', 'Номенклатурный №', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_NOMEN_CODE', NAME = 'Номенклатурный №', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_NOMEN_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_NOMEN_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_NOMEN_NAME', 'Наименование', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_NOMEN_NAME', NAME = 'Наименование', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_NOMEN_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKDP_CODE', 'Код ОКДП', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKDP_NAME', 'Наименование', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKDP_NAME', NAME = 'Наименование', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_N_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_N_COST', 'Цена по номенклатуре', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_N_COST', NAME = 'Цена по номенклатуре', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_N_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_N_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_N_UM_NAME', 'Наименование Ед. изм.  по номенклатуре', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_N_UM_NAME', NAME = 'Наименование Ед. изм.  по номенклатуре', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_N_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_N_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_N_QUANTITY', 'Количество по номенклатуре', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_N_QUANTITY', NAME = 'Количество по номенклатуре', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_N_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_SUMMA', 'Сумма', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_SUMMA', NAME = 'Сумма', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKDP_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKDP_COST', 'Цена по ОКДП', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKDP_COST', NAME = 'Цена по ОКДП', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKDP_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OK_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OK_UM_NAME', 'Наименование Ед. изм.  по ОКДП', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OK_UM_NAME', NAME = 'Наименование Ед. изм.  по ОКДП', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OK_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKDP_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'Количество  по ОКДП', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKDP_QUANTITY', NAME = 'Количество  по ОКДП', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKDP_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_TYPE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_TYPE', 'Вид строки', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_TYPE', NAME = 'Вид строки', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_TYPE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_TYPE_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_TYPE_NAME', 'Вид строки', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_TYPE_NAME', NAME = 'Вид строки', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_TYPE_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKPD_CODE', 'Код ОКПД', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKPD_NAME', 'Наименование', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKPD_NAME', NAME = 'Наименование', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKPD_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKPD_COST', 'Цена по ОКПД', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKPD_COST', NAME = 'Цена по ОКПД', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKPD_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKPD_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'Наименование Ед. изм.  по ОКПД', 18, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKPD_UM_NAME', NAME = 'Наименование Ед. изм.  по ОКПД', ORDERS = '18', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKPD_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T_OKPD_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'Количество  по ОКПД', 19, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_GZ_REESTR_T_OKPD_QUANTITY', NAME = 'Количество  по ОКПД', ORDERS = '19', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_GZ_REESTR_T'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_GZ_REESTR_T_OKPD_QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'TITLE', 'Реестр госзакупок'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'INIT_OBJECT_METHOD', 'bb_gz_reestr(m.obj_code)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'REMOVE_OBJECT_METHOD', 'I_DELETE_RECORDS(m.oForm.Alias, "BB_GZ_REESTR", "BV_DELETE_DOCUMENTS", 4, .F., .F.)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'SAVE_OBJECT_METHOD', 'X_SAVE("BB_SAVE_GZ_REESTR", m.cAlias,"NUMBER, SQLNULL(DATE), SQLNULL(DATE_PROV), SUMMA, COMMENT,SQLNULL(DEP_LINK),  SQLNULL(ACC_LINK), SQLNULL(CON_LINK),  SQLNULL(PROV_LINK)","BB_GZ_REESTR")

'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'EDIT_OBJECT_METHOD', 'gz_brow("bb_gz_reestr_edit")'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'SELECT_RECORDS_METHOD', 'X_SELECT_DOCUMENT_LIST_ZB(m.Obj_Code)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DOCUMENT_LIST("BB_GZ_REESTR_EDIT")'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'HELP_TOPIC', '54'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR', 'OPERATION_MASK', '24'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'TITLE', 'Вид строки'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'CONTROLSOURCE', 'm.cAlias + ".TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'SHORT_CODE_OBJ', 'TYPE_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_TYPE_NAME', 'ASPTYPE', 'aCmbType9'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'TITLE', 'Договор'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'CONTROLSOURCE', 'm.cAlias + ".CONTRACT"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'SHORT_CODE_OBJ', 'CONTRACT'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CONTRACT"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONTRACT', 'CONTROL_NAME_EDIT', 'aSelCon5'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'TITLE', 'На сумму'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".CON_SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'SHORT_CODE_OBJ', 'CON_SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CON_SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_SUMMA', 'CONTROL_NAME_EDIT', 'ATxtSumCon11'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'TITLE', 'Документ'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'CONTROLSOURCE', 'm.cAlias + ".DOC"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'SHORT_CODE_OBJ', 'DOC'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DOC"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DOC', 'CONTROL_NAME_EDIT', 'aTxtDoc6'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'TITLE', 'Проводка'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'CONTROLSOURCE', 'm.cAlias + ".PROV"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'SHORT_CODE_OBJ', 'PROV'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".PROV"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV', 'CONTROL_NAME_EDIT', 'aSelProv7'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'TITLE', 'На сумму'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".PROV_SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'SHORT_CODE_OBJ', 'PROV_SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".PROV_SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_PROV_SUMMA', 'CONTROL_NAME_EDIT', 'ATxtSumProv12'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME', 'TITLE', 'Учреждение'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME', 'VISIBLE', '7'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME', 'SHORT_CODE_OBJ', 'DEP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'TITLE', 'Поставщик'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'CONTROLSOURCE', 'm.cAlias + ".DEP_GZ_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'SHORT_CODE_OBJ', 'DEP_GZ_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_GZ_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_NAME_P', 'CONTROL_NAME_EDIT', 'ATxtDepName8'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'TITLE', 'Тип учреждения'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'VISIBLE', '7'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'CONTROLSOURCE', 'm.cAlias + ".DEP_GZ_TYPE2_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'SHORT_CODE_OBJ', 'DEP_GZ_TYPE2_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DEP_GZ_TYPE2_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_DEP_TYPE2_NAME', 'CONTROL_NAME_EDIT', 'ATxtDepType'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'TITLE', 'Условия оплаты'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'CONTROLSOURCE', 'm.cAlias + ".CON_PAY_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'SHORT_CODE_OBJ', 'CON_PAY'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CON_PAY_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CONDITIONS_PAY', 'CONTROL_NAME_EDIT', 'aTxtConPay13'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'TITLE', 'Вид торгов'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'CONTROLSOURCE', 'm.cAlias + ".CON_TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'SHORT_CODE_OBJ', 'CON_TYPE_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CON_TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_CON_TYPE_NAME', 'CONTROL_NAME_EDIT', 'aTxtType9'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_CODE', 'TITLE', 'Номенклатурный №'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_CODE', 'CONTROLSOURCE', 'm.cAlias + ".NOMEN_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_CODE', 'SHORT_CODE_OBJ', 'NOMEN_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NOMEN_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_NAME', 'CONTROLSOURCE', 'm.cAlias + ".NOMEN_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_NAME', 'SHORT_CODE_OBJ', 'NOMEN_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_NOMEN_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NOMEN_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_NAME', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_OKPD_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T', 'SAVE_OBJECT_METHOD', 'x_save("BB_UPDATE_GZ_REESTR_TABLE", m.cAlias, ''LINK_UP, SQLNULL(NOMENCLATURE), TYPE, N_QUANTITY, N_COST,SUMMA'', ''BB_GZ_REESTR_T'')'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T', 'SELECT_RECORDS_METHOD', 'SQL.EXEC(''SELECT 0 as CHECKED, 0 as UPD, 0 as DEL, * FROM dbo.BB_GZ_REESTR_TABLE WHERE LINK_UP = '' + str(m.nLink), m.cAlias) > 0'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T', 'SERVER_TABLE_NAME', 'GZ_REESTR_DOP'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_CHECKED', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_CHECKED', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_CHECKED', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'TITLE', 'Номенклатурный №'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'CONTROLSOURCE', 'm.cAlias + ".NOMEN_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'SHORT_CODE_OBJ', 'NOMEN_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NOMEN_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_CODE', 'CONTROL_NAME_EDIT', 'aSel_Nomen1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'CONTROLSOURCE', 'm.cAlias + ".NOMEN_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'SHORT_CODE_OBJ', 'NOMEN'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NOMEN_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_NOMEN_NAME', 'CONTROL_NAME_EDIT', 'aTxtNomenName'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_CODE', 'CONTROL_NAME_EDIT', 'aTxtOKDPCode5'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'TITLE', 'Наименование ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_NAME', 'CONTROL_NAME_EDIT', 'aTxtOKDPName'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'TITLE', 'Цена по номенклатуре'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'CONTROLSOURCE', 'm.cAlias + ".N_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'SHORT_CODE_OBJ', 'N_COST'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".N_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'TITLE', 'Ед. изм.  по номенклатуре'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".N_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'SHORT_CODE_OBJ', 'N_UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".N_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'TITLE', 'Количество  по номенклатуре'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".N_QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'SHORT_CODE_OBJ', 'N_QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_N_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".N_QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'TITLE', 'Цена  по ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'SHORT_CODE_OBJ', 'OKDP_COST'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'TITLE', 'Ед. изм.  по ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'SHORT_CODE_OBJ', 'OKDP_UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OK_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'TITLE', 'Количество  по ОКДП'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'SHORT_CODE_OBJ', 'OKDP_QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKDP_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'TITLE', 'Вид строки'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'CONTROLSOURCE', 'm.cAlias + ".TYPE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'SHORT_CODE_OBJ', 'TYPE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYPE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE', 'CONTROL_NAME_EDIT', 'aCmbType9'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'TITLE', 'Вид строки'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'CONTROLSOURCE', 'm.cAlias + ".TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'SHORT_CODE_OBJ', 'TYPE_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TYPE_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_TYPE_NAME', 'ASPTYPE', 'aCmbType9'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_CODE', 'CONTROL_NAME_EDIT', 'aTxtOKPDCode5'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'TITLE', 'Наименование ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_NAME', 'CONTROL_NAME_EDIT', 'aTxtOKPDName'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'TITLE', 'Цена  по ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'SHORT_CODE_OBJ', 'OKPD_COST'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_COST"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'TITLE', 'Ед. изм.  по ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'SHORT_CODE_OBJ', 'OKPD_UM_NAME'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_UM_NAME"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'TITLE', 'Количество  по ОКПД'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_QUANTITY"'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'SHORT_CODE_OBJ', 'OKPD_QUANTITY'
GO
EXEC X_SET_PROP 'BB_GZ_REESTR_T_OKPD_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_QUANTITY"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_GZ_REESTR', 'Смета-КС', 63,0
GO

GO
/****** Объект: Соответствие номенклатуры и ОКДП******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKDP')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKDP')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKDP')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKDP')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKDP'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKDP')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMENCLATURE_OKDP', 'Соответствие номенклатуры и ОКДП', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_MAT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),1,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMENCLATURE_OKDP', NAME = 'Соответствие номенклатуры и ОКДП', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_MAT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_NOMENCLATURE_OKDP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_MARKER', 'МАРКЕР', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_MARKER', NAME = 'МАРКЕР', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_CODE_GRP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_CODE_GRP', 'Код группы', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_CODE_GRP', NAME = 'Код группы', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_CODE_GRP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_NAME_GRP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_NAME_GRP', 'Наименование группы', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_NAME_GRP', NAME = 'Наименование группы', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_NAME_GRP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_CODE', 'Код', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_CODE', NAME = 'Код', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_NAME', 'Наименование', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_NAME', NAME = 'Наименование', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_CODE_OKDP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_CODE_OKDP', 'Код по ОКДП', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_CODE_OKDP', NAME = 'Код по ОКДП', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_CODE_OKDP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_NAME_OKDP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_NAME_OKDP', 'Наименование по ОКДП', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_NAME_OKDP', NAME = 'Наименование по ОКДП', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_NAME_OKDP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKDP_COEFF')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKDP_COEFF', 'Коэффициент перевода из ОКДП', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKDP_COEFF', NAME = 'Коэффициент перевода из ОКДП', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKDP'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKDP_COEFF'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'TITLE', 'Соответствие номенклатуры и ОКДП'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'INIT_OBJECT_METHOD', 'bb_nomenclature_okdp()'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BV_SAVE_NOMENCLATURE'', m.cAlias,"LINK_GRP, SQLNULL(CODE), SQLNULL(NAME), SQLNULL(SERIES), LINK_UM, IS_EXTRA, SQLNULL(LINK_OKDP), NULL,COEFF" ,"BV_NOMENCLATURE")'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'SELECT_RECORDS_METHOD', 'X_SELECT_DICTIONS(''BV_NOMENCLATURE'')'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DICTIONS(''BV_NOMENCLATURE'')'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'OPEN_CODE', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'SERVER_TABLE_NAME', 'OKDP'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'HELP_TOPIC', 'Соответствие номенклатуры и ОКДП'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKDP', 'OPERATION_MASK', '8'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_MARKER', 'VISIBLE', '9'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_MARKER', 'CONTROLSOURCE', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_MARKER', 'SHORT_CODE_OBJ', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'TITLE', 'Код группы'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'CONTROLSOURCE', 'm.cAlias + ".CODE_GRP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'CONTROL_TYPE', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'STORAGE', 'GROUP_INV'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'TYPE_FIELD_DICT', 'CHAR(7)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'SHORT_CODE_OBJ', 'CODE_GRP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_GRP', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'TITLE', 'Наименование группы'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'CONTROLSOURCE', 'm.cAlias + ".NAME_GRP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'STORAGE', 'GROUP_INV'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'TYPE_FIELD_DICT', 'VARCHAR(50)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'SHORT_CODE_OBJ', 'NAME_GRP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_GRP', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'TITLE', 'Номенклатурный номер'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'TYPE_FIELD_DICT', 'CHAR(10)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'SHORT_CODE_OBJ', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias+".NAME"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'SHORT_CODE_OBJ', 'NAME'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'TITLE', 'Код по ОКДП'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'ORDER_NUMBER', '5'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP",oForm.bChildSpisok1.bGrid1.RecordSource,"LINK, CODE, NAME", "LINK_OKDP,CODE_OKDP,NAME_OKDP", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'CONTROLSOURCE', 'm.cAlias+".CODE_OKDP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'STORAGE', 'OKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'SHORT_CODE_OBJ', 'CODE_OKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE_OKDP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_CODE_OKDP', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'TITLE', 'Наименование по ОКДП'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'CONTROLSOURCE', 'm.cAlias+".NAME_OKDP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'STORAGE', 'OKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'SHORT_CODE_OBJ', 'NAME_OKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_OKDP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'CONTROL_NAME_EDIT', 'pgfNomen.Page1.aTxtOKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_NAME_OKDP', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'TITLE', 'Коэфф.'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'CONTROLSOURCE', 'm.cAlias+".COEFF"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'TYPE_FIELD_DICT', 'NUMERIC(19,6)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'SHORT_CODE_OBJ', 'COEFF'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKDP_COEFF', 'CONTROLSOURCE_EDIT', 'm.cAlias+".COEFF"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_NOMENCLATURE_OKDP', 'Смета-КС', 63,0
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Соответствие номенклатуры и ОКДП"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKDP')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'BB_NOMENCLATURE_OKDP'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'BB_NOMENCLATURE_OKDP', 'Соответствие номенклатуры и ОКДП', @ORD, NULL, 1, @LINK_SELF, 'JPROV', @OBJECT, @LINK_VAR, 3
GO



/****** Объект: Соответствие номенклатуры и ОКПД******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_NOMENCLATURE_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMENCLATURE_OKPD', 'Соответствие номенклатуры и ОКПД', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_MAT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),1,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMENCLATURE_OKPD', NAME = 'Соответствие номенклатуры и ОКПД', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_MAT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_NOMENCLATURE_OKPD'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_MARKER')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_MARKER', 'МАРКЕР', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_MARKER', NAME = 'МАРКЕР', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_MARKER'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_CODE_GRP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_CODE_GRP', 'Код группы', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_CODE_GRP', NAME = 'Код группы', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_CODE_GRP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_NAME_GRP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_NAME_GRP', 'Наименование группы', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_NAME_GRP', NAME = 'Наименование группы', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_NAME_GRP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_CODE', 'Код', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_CODE', NAME = 'Код', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_NAME', 'Наименование', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_NAME', NAME = 'Наименование', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_CODE_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_CODE_OKPD', 'Код по ОКПД', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_CODE_OKPD', NAME = 'Код по ОКПД', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_CODE_OKPD'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_NAME_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_NAME_OKPD', 'Наименование по ОКПД', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_NAME_OKPD', NAME = 'Наименование по ОКПД', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_NAME_OKPD'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_NOMEN_OKPD_COEFF')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_NOMEN_OKPD_COEFF', 'Коэффициент перевода из ОКПД', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_NOMEN_OKPD_COEFF', NAME = 'Коэффициент перевода из ОКПД', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_NOMENCLATURE_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_NOMEN_OKPD_COEFF'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'TITLE', 'Соответствие номенклатуры и ОКПД'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'INIT_OBJECT_METHOD', 'bb_nomenclature_okdp()'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BV_SAVE_NOMENCLATURE'', m.cAlias,"LINK_GRP, SQLNULL(CODE), SQLNULL(NAME), SQLNULL(SERIES), LINK_UM, IS_EXTRA, NULL, SQLNULL(LINK_OKPD), 1, COEFF_OKPD" ,"BV_NOMENCLATURE")'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'SELECT_RECORDS_METHOD', 'X_SELECT_DICTIONS(''BV_NOMENCLATURE'')'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DICTIONS(''BV_NOMENCLATURE'')'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'OPEN_CODE', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'SERVER_TABLE_NAME', 'OKPD'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'HELP_TOPIC', 'Соответствие номенклатуры и ОКПД'
GO
EXEC X_SET_PROP 'BB_NOMENCLATURE_OKPD', 'OPERATION_MASK', '8'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_MARKER', 'VISIBLE', '9'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_MARKER', 'CONTROLSOURCE', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_MARKER', 'SHORT_CODE_OBJ', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'TITLE', 'Код группы'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'CONTROLSOURCE', 'm.cAlias + ".CODE_GRP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'CONTROL_TYPE', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'STORAGE', 'GROUP_INV'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'TYPE_FIELD_DICT', 'CHAR(7)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'SHORT_CODE_OBJ', 'CODE_GRP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_GRP', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'TITLE', 'Наименование группы'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'CONTROLSOURCE', 'm.cAlias + ".NAME_GRP"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'STORAGE', 'GROUP_INV'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'TYPE_FIELD_DICT', 'VARCHAR(50)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'SHORT_CODE_OBJ', 'NAME_GRP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_GRP', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'TITLE', 'Номенклатурный номер'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'TYPE_FIELD_DICT', 'CHAR(10)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'SHORT_CODE_OBJ', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias+".NAME"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'SHORT_CODE_OBJ', 'NAME'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME', 'CHECK_WHEN', ''
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'TITLE', 'Код по ОКПД'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'ORDER_NUMBER', '5'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD",oForm.bChildSpisok1.bGrid1.RecordSource,"LINK, CODE, NAME", "LINK_OKPD,CODE_OKPD,NAME_OKPD", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'VISIBLE', '3'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'CONTROLSOURCE', 'm.cAlias+".CODE_OKPD"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'STORAGE', 'OKPD'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'TYPE_FIELD_DICT', 'VARCHAR(12)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'SHORT_CODE_OBJ', 'CODE_OKPD'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE_OKPD"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_CODE_OKPD', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'TITLE', 'Наименование по ОКПД'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'CONTROLSOURCE', 'm.cAlias+".NAME_OKPD"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'STORAGE', 'OKPD'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'SHORT_CODE_OBJ', 'NAME_OKPD'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_OKPD"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'CONTROL_NAME_EDIT', 'pgfNomen.Page1.aTxtOKDP'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_NAME_OKPD', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'TITLE', 'Коэфф.'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'CONTROLSOURCE', 'm.cAlias+".COEFF_OKPD"'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'TYPE_FIELD_DICT', 'NUMERIC(19,6)'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'SHORT_CODE_OBJ', 'COEFF_OKPD'
GO
EXEC X_SET_PROP 'BB_NOMEN_OKPD_COEFF', 'CONTROLSOURCE_EDIT', 'm.cAlias+".COEFF_OKPD"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_NOMENCLATURE_OKPD', 'Смета-КС', 63,0
GO




/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Соответствие номенклатуры и ОКПД"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_NOMENCLATURE_OKPD')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'BB_NOMENCLATURE_OKPD'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'BB_NOMENCLATURE_OKPD', 'Соответствие номенклатуры и ОКПД', @ORD, NULL, 1, @LINK_SELF, 'JPROV', @OBJECT, @LINK_VAR, 3
GO




IF EXISTS (SELECT * FROM  DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT') AND code  = 'PIT_DICT')
	UPDATE DBO.S_NAVIGATOR 
		SET ORDERS = 16 
	WHERE  LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT') AND code  = 'PIT_DICT'
IF 	EXISTS (SELECT * FROM  DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT') AND code  = 'BB_NOMENCLATURE_OKPD')
	UPDATE DBO.S_NAVIGATOR 
		SET ORDERS = 15 
	WHERE  LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'TMC_DICT') AND code  = 'BB_NOMENCLATURE_OKPD'	

GO
	
GO
/****** Объект: Продукция -Услуги и работы (ОКПД)******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD', 'Продукция -Услуги и работы (ОКПД)', 19, (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASSIF_CATALOG'), (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD', NAME = 'Продукция -Услуги и работы (ОКПД)', ORDERS = '19', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASSIF_CATALOG'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_OKPD'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_CODE', 'Код', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_CODE', NAME = 'Код', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_NAME', 'Наименование', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_NAME', NAME = 'Наименование', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_NAME_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_NAME_TABLE', 'Наименование', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_NAME_TABLE', NAME = 'Наименование', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_NAME_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_CODE_UM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_CODE_UM', 'Код единицы измерения', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_CODE_UM', NAME = 'Код единицы измерения', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_CODE_UM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_NAME_UM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_NAME_UM', 'Наименование единицы измерения', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_NAME_UM', NAME = 'Наименование единицы измерения', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_NAME_UM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_USED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_USED', 'Используется в учете', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_USED', NAME = 'Используется в учете', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_OKPD_USED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_OKPD_UPDATE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_OKPD_UPDATE', 'ОКПД - Загрузка\Обновление', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_OKPD_UPDATE', NAME = 'ОКПД - Загрузка\Обновление', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_OKPD_UPDATE'
GO
EXEC X_SET_PROP 'BB_OKPD', 'TITLE', 'Продукция - Услуги и работы (ОКПД)'
GO
EXEC X_SET_PROP 'BB_OKPD', 'INIT_OBJECT_METHOD', 'bb_tree_okdp(m.Obj_Code)'
GO
EXEC X_SET_PROP 'BB_OKPD', 'REMOVE_OBJECT_METHOD', 'BB_OKPD_DELETE(m.oForm.Alias)'
GO
EXEC X_SET_PROP 'BB_OKPD', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BB_OKPD_SAVE'',m.cAlias,"CODE,NAME_TABLE,SQLNULL(LINK_SELF), UM,USED","BB_OKPD")'
GO
EXEC X_SET_PROP 'BB_OKPD', 'EDIT_OBJECT_METHOD', 'BDIC_BROW(''bb_tree_okdp_edit'')'
GO
EXEC X_SET_PROP 'BB_OKPD', 'SELECT_RECORDS_METHOD', 'X_SELECT_SUBTREE("BB_OKPD")
'
GO
EXEC X_SET_PROP 'BB_OKPD', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DICTIONS(''BB_OKPD'')'
GO
EXEC X_SET_PROP 'BB_OKPD', 'OPEN_CODE', 'CODE'
GO
EXEC X_SET_PROP 'BB_OKPD', 'SERVER_TABLE_NAME', 'OKPD'
GO
EXEC X_SET_PROP 'BB_OKPD', 'HELP_TOPIC', '6'
GO
EXEC X_SET_PROP 'BB_OKPD', 'FIELD_LINK_SELF', 'LINK_SELF'
GO
EXEC X_SET_PROP 'BB_OKPD', 'FIELD_ORDER', 'NAME'
GO
EXEC X_SET_PROP 'BB_OKPD', 'OPERATION_MASK', '15'
GO
EXEC X_SET_PROP 'BB_OKPD', 'SELECT_RECORDS_METHOD_SQL', 'select [checked]=0, link,code, name from XD_XOZ_OPER_GROUP'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'VISIBLE', '25'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'CONTROLSOURCE', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'ROWSOURCE', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'SHORT_CODE_OBJ', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'ASPTYPE', 'checkbox'
GO
EXEC X_SET_PROP 'BB_OKPD_CHECKED', 'FIELD_DATA', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'TITLE', 'Код'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'VISIBLE', '31'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(2)'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'SHORT_CODE_OBJ', 'CODE'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'CONTROL_NAME', 'Atxt1'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'CONTROL_NAME_EDIT', 'Atxt1'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'ATTRIBUTES', ' style="Z-INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 56px"
Width="377px"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'LABEL_ATTRIBUTES', ' style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 56px"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE', 'FIELD_DATA', 'CODE'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias+".NAME"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(150)'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'SHORT_CODE_OBJ', 'NAME'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'ATTRIBUTES', ' style="Z-INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 56px"
Width="377px"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'LABEL_ATTRIBUTES', ' style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 56px"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME', 'FIELD_DATA', 'NAME'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'VISIBLE', '31'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'CONTROLSOURCE', 'm.cAlias+".NAME_TABLE"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'TYPE_FIELD_DICT', 'VARCHAR(150)'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'SHORT_CODE_OBJ', 'NAME_TABLE'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_TABLE"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'CONTROL_NAME', 'Atxt2'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'CONTROL_NAME_EDIT', 'Atxt2'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'REFERENCE_TO_FIELD', 'NAME_TABLE'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'ATTRIBUTES', ' style="Z-INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 56px"
Width="377px"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'LABEL_ATTRIBUTES', ' style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 56px"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_TABLE', 'FIELD_DATA', 'NAME_TABLE'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'TITLE', 'Eд-ца изм.'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'ORDER_NUMBER', '5'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("DICTIONARY_DIGIT",oForm.ALIAS,"LINK, CODE, NAME", "UM,CODE_UM,NAME_UM", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'CONTROLSOURCE', 'm.cAlias+".CODE_UM"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'SHORT_CODE_OBJ', 'CODE_UM'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE_UM"'
GO
EXEC X_SET_PROP 'BB_OKPD_CODE_UM', 'CONTROL_NAME_EDIT', 'aSelUM3'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'TITLE', 'Единица измерения'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'CONTROLSOURCE', 'm.cAlias+".NAME_UM"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'TYPE_FIELD_DICT', 'VARCHAR(20)'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'SHORT_CODE_OBJ', 'NAME_UM'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_UM"'
GO
EXEC X_SET_PROP 'BB_OKPD_NAME_UM', 'CONTROL_NAME_EDIT', 'aTxtUM4'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'TITLE', 'Используется в учете'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'CONTROLSOURCE', 'm.cAlias+".USED"'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'TYPE_FIELD_DICT', 'bit'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'SHORT_CODE_OBJ', 'USED'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'CONTROLSOURCE_EDIT', 'm.cAlias+".USED"'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'CONTROL_NAME', 'AChkUsed'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'CONTROL_NAME_EDIT', 'AChkUsed'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'REFERENCE_TO_FIELD', 'USED'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_OKPD_USED', 'FIELD_DATA', 'USED'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'TITLE', 'ОКПД - Загрузка\Обновление'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'INIT_OBJECT_METHOD', 'bb_okpd_update(m.Obj_Code)'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'SELECT_RECORDS_METHOD', 'bb_okpd_update_selectrecord()'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'SELECT_RECORDS_METHOD_EDIT', ''
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'OPEN_CODE', 'CODE'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'SERVER_TABLE_NAME', ''
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'HELP_TOPIC', 'Продукция(Услуги,Работы)'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'FIELD_LINK_SELF', 'LINK_SELF'
GO
EXEC X_SET_PROP 'BB_OKPD_UPDATE', 'FIELD_ORDER', 'NAME'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_OKPD', 'Зарплата-КС', 5,0
GO
EXEC DBO.W_SPERM_WRITE 'BB_OKPD', 'Свод-КС', 5,0
GO
EXEC DBO.W_SPERM_WRITE 'BB_OKPD', 'Смета-КС', 63,0
GO
EXEC DBO.W_SPERM_WRITE 'BB_OKPD', 'Кадры-КС (чтение)', 5,26
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Продукция-услуги и работы (ОКПД)"*************/ 
 
if exists (select * from DBO.S_NAVIGATOR WHERE CODE = '4510' and  NAME = 'Продукция-услуги и работы (ОКПД)')
	delete from DBO.S_NAVIGATOR where CODE = '4510' and  NAME = 'Продукция-услуги и работы (ОКПД)'
 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'BUDJ_CLASS')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_OKPD')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'BUDJ_CLASS'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_BB_OKPD'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_BB_OKPD', 'Продукция-услуги и работы (ОКПД)', @ORD, NULL, 1, @LINK_SELF, 'DICTIONARY', @OBJECT, @LINK_VAR, 3
GO


GO
/****** Объект: ОКПД используемые******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BB_USED_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_USED_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_USED_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BB_USED_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BB_USED_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BB_USED_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD', 'ОКПД используемые', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD', NAME = 'ОКПД используемые', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='GZ'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='WEB_DICTIONARY_CLASS'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='BB_USED_OKPD'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_CODE', 'Код', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_CODE', NAME = 'Код', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_NAME', 'Наименование', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_NAME', NAME = 'Наименование', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_CODE_UM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_CODE_UM', 'Код единицы измерения', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_CODE_UM', NAME = 'Код единицы измерения', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_CODE_UM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_NAME_UM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_NAME_UM', 'Наименование единицы измерения', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_NAME_UM', NAME = 'Наименование единицы измерения', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_NAME_UM'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BB_USED_OKPD_USED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BB_USED_OKPD_USED', 'Используется в учете', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BB_USED_OKPD_USED', NAME = 'Используется в учете', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BB_USED_OKPD'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BB_USED_OKPD_USED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'TITLE', 'ОКПД используемые'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'REMOVE_OBJECT_METHOD', 'BB_OKPD_DELETE(m.oForm.Alias)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'SAVE_OBJECT_METHOD', 'X_SAVE(''BB_OKPD_SAVE'',m.cAlias,"CODE,NAME_TABLE,SQLNULL(LINK_SELF), UM,USED","BB_OKPD")'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'EDIT_OBJECT_METHOD', 'BDIC_BROW(''bb_tree_okdp_edit'')'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'SELECT_RECORDS_METHOD', 'X_SELECT_DICTIONS(''BB_USED_OKPD'')
'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'OPEN_CODE', 'CODE'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'SERVER_TABLE_NAME', 'OKPD'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'HELP_TOPIC', '6'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'FIELD_LINK_SELF', 'LINK_SELF'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'FIELD_ORDER', 'NAME'
GO
EXEC X_SET_PROP 'BB_USED_OKPD', 'OPERATION_MASK', '15'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'VISIBLE', '25'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'CONTROLSOURCE', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'ROWSOURCE', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'SHORT_CODE_OBJ', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CHECKED"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'ASPTYPE', 'checkbox'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CHECKED', 'FIELD_DATA', 'CHECKED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'TITLE', 'Код'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'VISIBLE', '31'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'TYPE_FIELD_DICT', 'VARCHAR(2)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'SHORT_CODE_OBJ', 'CODE'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'CONTROL_NAME', 'Atxt1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'CONTROL_NAME_EDIT', 'Atxt1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'ATTRIBUTES', ' style="Z-INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 56px"
Width="377px"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'LABEL_ATTRIBUTES', ' style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 56px"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE', 'FIELD_DATA', 'CODE'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias+".NAME"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'TYPE_FIELD_DICT', 'VARCHAR(150)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'SHORT_CODE_OBJ', 'NAME'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'ATTRIBUTES', ' style="Z-INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 56px"
Width="377px"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'LABEL_ATTRIBUTES', ' style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 56px"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'FIELD_DATA', 'NAME'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'TITLE', 'Eд-ца изм.'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'ORDER_NUMBER', '5'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("DICTIONARY_DIGIT",oForm.ALIAS,"LINK, CODE, NAME", "UM,CODE_UM,NAME_UM", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'CONTROLSOURCE', 'm.cAlias+".CODE_UM"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'SHORT_CODE_OBJ', 'CODE_UM'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE_UM"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_CODE_UM', 'CONTROL_NAME_EDIT', 'aSelUM3'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'TITLE', 'Единица измерения'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'CONTROLSOURCE', 'm.cAlias+".NAME_UM"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'TYPE_FIELD_DICT', 'VARCHAR(20)'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'SHORT_CODE_OBJ', 'NAME_UM'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_UM"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_NAME_UM', 'CONTROL_NAME_EDIT', 'aTxtUM4'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'TITLE', 'Используется в учете'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'CONTROLSOURCE', 'm.cAlias+".USED"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'TYPE_FIELD_DICT', 'bit'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'SHORT_CODE_OBJ', 'USED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'CONTROLSOURCE_EDIT', 'm.cAlias+".USED"'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'CONTROL_NAME', 'AChkUsed'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'CONTROL_NAME_EDIT', 'AChkUsed'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'QUICKSEARCH', '1'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'REFERENCE_TO_FIELD', 'USED'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'BB_USED_OKPD_USED', 'FIELD_DATA', 'USED'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'BB_USED_OKPD', 'Смета-КС', 63,0
GO


GO
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****** Объект: Номенклатура******/
--- Изменение 'SAVE_OBJECT_METHOD'
EXEC X_SET_PROP 'BV_NOMENCLATURE', 'SAVE_OBJECT_METHOD', 'X_SAVE("BV_SAVE_NOMENCLATURE", m.cAlias,"LINK_GRP, SQLNULL(CODE), SQLNULL(NAME), SQLNULL(SERIES), SQLNULL(LINK_UM), IS_EXTRA, SQLNULL(LINK_OKDP),SQLNULL(LINK_OKPD), COEFF, COEFF_OKPD, PRICE_TYPE, ISUSED" ,"BV_NOMENCLATURE")'
GO


--- Добавление полей в справочник "Номенклатура"
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****** Объект: Код по ОКПД******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_CODE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_CODE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_CODE_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_CODE_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_CODE_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_CODE_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BV_NOMEN_CODE_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BV_NOMEN_CODE_OKPD', 'Код по ОКПД', 21, (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BV_NOMEN_CODE_OKPD', NAME = 'Код по ОКПД', ORDERS = '21', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BV_NOMEN_CODE_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'TITLE', 'Код по ОКПД'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'ORDER_NUMBER', '5'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD",oForm.ALIAS,"LINK, CODE, NAME", "LINK_OKPD,CODE_OKPD,NAME_OKPD", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'VISIBLE', '7'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'CONTROLSOURCE', 'm.cAlias+".CODE_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'CONTROL_TYPE', '8'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'STORAGE', 'OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'TYPE_FIELD_DICT', 'VARCHAR(10)'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'SHORT_CODE_OBJ', 'CODE_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CODE_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'CONTROL_NAME_EDIT', 'pgfNomen.Page1.aSelOKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'BV_NOMEN_CODE_OKPD', 'FIELD_IN_SEARCH', '1'
GO


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****** Объект: Наименование по ОКПД******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_NAME_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_NAME_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_NAME_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_NAME_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_NAME_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_NAME_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BV_NOMEN_NAME_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BV_NOMEN_NAME_OKPD', 'Наименование по ОКПД', 22, (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BV_NOMEN_NAME_OKPD', NAME = 'Наименование по ОКПД', ORDERS = '22', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BV_NOMEN_NAME_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'TITLE', 'Наименование по ОКПД'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'CONTROLSOURCE', 'm.cAlias+".NAME_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'STORAGE', 'OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'SHORT_CODE_OBJ', 'NAME_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'CONTROLSOURCE_EDIT', 'm.cAlias+".NAME_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'CONTROL_NAME_EDIT', 'pgfNomen.Page1.aTxtOKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'BV_NOMEN_NAME_OKPD', 'FIELD_IN_SEARCH', '1'
GO


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****** Объект: Коэффициент перевода из ОКПД******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_COEFF_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_COEFF_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_COEFF_OKPD')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'BV_NOMEN_COEFF_OKPD')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_COEFF_OKPD'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'BV_NOMEN_COEFF_OKPD')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='BV_NOMEN_COEFF_OKPD')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'BV_NOMEN_COEFF_OKPD', 'Коэффициент перевода из ОКПД', 23, (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'BV_NOMEN_COEFF_OKPD', NAME = 'Коэффициент перевода из ОКПД', ORDERS = '23', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BV_NOMENCLATURE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='BV_NOMEN_COEFF_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'TITLE', 'Коэффициент перевода из ОКПД'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'VISIBLE', '6'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'CONTROLSOURCE', 'm.cAlias+".COEFF_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'TYPE_FIELD_DICT', 'NUMERIC(19,6)'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'SHORT_CODE_OBJ', 'COEFF_OKPD'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'CONTROLSOURCE_EDIT', 'm.cAlias+".COEFF_OKPD"'
GO
EXEC X_SET_PROP 'BV_NOMEN_COEFF_OKPD', 'CONTROL_NAME_EDIT', 'pgfNomen.Page1.aTxtCOEFF_OKPD'
GO

------------ 
GO
/****** Объект: Замена расчетного периода БЛ******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'CHANGE_PERIOD_VAC')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'CHANGE_PERIOD_VAC')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'CHANGE_PERIOD_VAC')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'CHANGE_PERIOD_VAC', 'Замена расчетного периода БЛ', 38, (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DICT_SALARY'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_DEDUCT'),1,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'CHANGE_PERIOD_VAC', NAME = 'Замена расчетного периода БЛ', ORDERS = '38', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CATALOG_DICT_SALARY'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_DEDUCT'), MANAGED = 1, INHERITED = 1
	WHERE CODE ='CHANGE_PERIOD_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_MARKER_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_MARKER_PER_VAC', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_MARKER_PER_VAC', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_MARKER_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_REF_EMPL_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_REF_EMPL_PER_VAC', 'Ссылка на сотрудника', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_REF_EMPL_PER_VAC', NAME = 'Ссылка на сотрудника', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_REF_EMPL_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_TAB_NUM_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_TAB_NUM_PER_VAC', 'Табельный номер', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_TAB_NUM_PER_VAC', NAME = 'Табельный номер', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_TAB_NUM_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_NAME_EMPL_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_NAME_EMPL_PER_VAC', 'ФИО', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_NAME_EMPL_PER_VAC', NAME = 'ФИО', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_NAME_EMPL_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_DATE1_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_DATE1_PER_VAC', 'Дата начала срока действия', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_DATE1_PER_VAC', NAME = 'Дата начала срока действия', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_DATE1_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_DATE2_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_DATE2_PER_VAC', 'Дата окончания срока действия', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_DATE2_PER_VAC', NAME = 'Дата окончания срока действия', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_DATE2_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_YEAR1_R_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_YEAR1_R_PER_VAC', '1 год', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_YEAR1_R_PER_VAC', NAME = '1 год', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_YEAR1_R_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_YEAR2_R_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_YEAR2_R_PER_VAC', '2 год', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_YEAR2_R_PER_VAC', NAME = '2 год', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_YEAR2_R_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_NOTE_PER_VAC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_NOTE_PER_VAC', 'Основание', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_NOTE_PER_VAC', NAME = 'Основание', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_NOTE_PER_VAC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='CHANGE_PER_VAC_NAME_DEP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'CHANGE_PER_VAC_NAME_DEP', 'Организация', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'CHANGE_PER_VAC_NAME_DEP', NAME = 'Организация', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='CHANGE_PERIOD_VAC'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='CHANGE_PER_VAC_NAME_DEP'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'TITLE', 'Замена расчетного периода БЛ'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'INIT_OBJECT_METHOD', 'X_SPISOK("CHANGE_PERIOD_VAC")'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'REMOVE_OBJECT_METHOD', 'I_DELETE_RECORDS(m.oForm.Alias, "CHANGE_PERIOD_VAC", "SAL_DELETE_CHANGE_PERIOD_VAC", 4, .F., .F.)'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'SAVE_OBJECT_METHOD', 'sd_vac_change_period_save(oForm)'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'EDIT_OBJECT_METHOD', 'salary_brow(''sd_change_period_vac'')'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'SELECT_RECORDS_METHOD', 'SA_SELECT_DICTIONS_ZB(''CHANGE_PERIOD_VAC'')'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'SELECT_RECORDS_METHOD_EDIT', 'X_SELECT_DICTIONS(''CHANGE_PERIOD_VAC'')'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'OPEN_CODE', 'LINK'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'SERVER_TABLE_NAME', 'VAC_PERIOD_CHANGE'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'HELP_TOPIC', '8'
GO
EXEC X_SET_PROP 'CHANGE_PERIOD_VAC', 'OPERATION_MASK', '24'
GO
EXEC X_SET_PROP 'COLUMN_MARKER_PER_VAC', 'VISIBLE', '9'
GO
EXEC X_SET_PROP 'COLUMN_MARKER_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".CHECKED"'
GO
EXEC X_SET_PROP 'COLUMN_MARKER_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".CHECKED"'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'TITLE', 'Ссылка на сотрудника'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".REF_EMPL"'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'TYPE_FIELD_DICT', 'INT'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'SHORT_CODE_OBJ', 'REF_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".REF_EMPL"'
GO
EXEC X_SET_PROP 'COLUMN_REF_EMPL_PER_VAC', 'REFERENCE_TO_FIELD', 'REF_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'TITLE', 'Таб. №'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 (''KU_EMPL_PLACING'', oForm.ALIAS, ''LINK, TAB, NAME_EMPL'', ''LINK_EMPL, TAB_NUM,NAME_EMPL'', '''','''', "DEP_LINK = " + STR(EVAL(oForm.Alias + ".DEP_LINK")), .T., 1, oForm, oObj, "")'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".TAB_NUM"'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'TYPE_FIELD_DICT', 'VARCHAR(100)'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'SHORT_CODE_OBJ', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".TAB_NUM"'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'CONTROL_NAME_EDIT', 'ASEL_SPR1'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_TAB_NUM_PER_VAC', 'COMMENTARY', 'Табельный номер'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'TITLE', 'ФИО'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".NAME_EMPL"'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'STORAGE', 'dictionary_faces'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'TYPE_FIELD_DICT', 'VARCHAR(100)'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'SHORT_CODE_OBJ', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NAME_EMPL"'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'CONTROL_NAME_EDIT', 'Atextbox1'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'REFERENCE_TO_FIELD', 'NAME_EMPL'
GO
EXEC X_SET_PROP 'COLUMN_NAME_EMPL_PER_VAC', 'COMMENTARY', 'ФИО'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'TITLE', 'Дата начала'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".DATE1"'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'TYPE_FIELD_DICT', 'datetime'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'SHORT_CODE_OBJ', 'DATE1'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DATE1"'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'CONTROL_NAME', 'ASelDate1'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'CONTROL_NAME_EDIT', 'ASelDate1'
GO
EXEC X_SET_PROP 'COLUMN_DATE1_PER_VAC', 'COMMENTARY', 'Дата начала срока действия'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'TITLE', 'Дата окончания'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".DATE2"'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'TYPE_FIELD_DICT', 'datetime'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'SHORT_CODE_OBJ', 'DATE2'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".DATE2"'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'CONTROL_NAME', 'ASelDate2'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'CONTROL_NAME_EDIT', 'ASelDate2'
GO
EXEC X_SET_PROP 'COLUMN_DATE2_PER_VAC', 'COMMENTARY', 'Дата окончания срока действия'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'TITLE', '1 год'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".YEAR1"'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'TYPE_FIELD_DICT', 'datetime'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'SHORT_CODE_OBJ', 'YEAR1'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".YEAR1"'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'CONTROL_NAME', 'Aspinner1'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'CONTROL_NAME_EDIT', 'Aspinner1'
GO
EXEC X_SET_PROP 'COLUMN_YEAR1_R_PER_VAC', 'COMMENTARY', '1 год расчетного периода'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'TITLE', '2 год'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".YEAR2"'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'TYPE_FIELD_DICT', 'datetime'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'SHORT_CODE_OBJ', 'YEAR2'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".YEAR2"'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'CONTROL_NAME', 'Aspinner2'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'CONTROL_NAME_EDIT', 'Aspinner2'
GO
EXEC X_SET_PROP 'COLUMN_YEAR2_R_PER_VAC', 'COMMENTARY', '2 год расчетного периода'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'TITLE', 'Основание'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'CONTROLSOURCE', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'STORAGE', 'DICTION_APP'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'TYPE_FIELD_DICT', 'VARCHAR(254)'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'SHORT_CODE_OBJ', 'COMMENT'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COMMENT"'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'CONTROL_NAME_EDIT', 'Edit1'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'REFERENCE_TO_FIELD', 'COMMENT'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'COLUMN_NOTE_PER_VAC', 'FIELD_DATA', 'COMMENT'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'TITLE', 'Организация'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'EDIT_OBJECT_METHOD', 'N_VIBOR_01 (''DICTIONARY_DEPARTMENT'', oForm.ALIAS, ''LINK, NAME'', ''DEP_LINK, NAME_DEP'', '''','''', "(TYPE=4 OR ZB=1) AND dbo.xu_GetAccessByDep (LINK) > 0 ", .T., 1, oForm, oObj, "")'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'CONTROLSOURCE', 'm.cAlias + ".NAME_DEP"'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'CONTROL_TYPE', '2'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'FIELD_IN_ALIAS', '3'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'TYPE_FIELD_DICT', 'VARCHAR(50)'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".NAME_DEP"'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'CONTROL_NAME_EDIT', 'cnt_dep.asel_spr01'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'COMMENTARY', 'Наименование организации'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'ATTRIBUTES', 'style="Z-INDEX: 107; LEFT: 240px; POSITION: absolute; TOP: 48px""
Width="392px"
ReadOnly="True"'
GO
EXEC X_SET_PROP 'CHANGE_PER_VAC_NAME_DEP', 'FIELD_DATA', 'name_empl'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'CHANGE_PERIOD_VAC', 'Кадры-КС', 63,0
GO
EXEC DBO.W_SPERM_WRITE 'CHANGE_PERIOD_VAC', 'Зарплата-КС', 63,0
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Замена расчетного периода БЛ"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = '4227')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'CHANGE_PERIOD_VAC')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = '4227'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_CHANGE_PERIOD_VAC'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_CHANGE_PERIOD_VAC', 'Замена расчетного периода БЛ', @ORD, NULL, 1, @LINK_SELF, 'DOCUMENT', @OBJECT, @LINK_VAR, 3
GO


GO

IF NOT EXISTS (SELECT * FROM CHARACTERISTICS WHERE CODE = 'AUTO_SHARE_TAXPAYER' AND NAME = 'Доля налогоплательщика в праве на транспортное средство') 
	BEGIN
		declare @p1 FLOAT 
		set @p1=0
		exec BV_SAVE_CHARACTERS_DIC @p1 output,'AUTO_SHARE_TAXPAYER ','Доля налогоплательщика в праве на транспортное средство',3,21,0,'1/1',1 
	
		DECLARE @intLINK_GROUP INT 
		SET @intLINK_GROUP = 0
		DECLARE #CUR1 CURSOR FOR
			SELECT link  FROM BV_DICTIONARY_GROUP_ACTIVE WHERE NAME LIKE 'Транспортные средства%'  AND link NOT IN ( select LINK_GROUP from GROUP_CHARS WHERE link_char = @p1)
		OPEN #CUR1
		FETCH #CUR1 INTO @intLINK_GROUP
		WHILE @@FETCH_STATUS = 0
		BEGIN
			declare @p2 float
			set @p2=0
			exec BV_SAVE_GROUP_ACTIVE_CHARS_TABLE @p2 output,@p1,@intLINK_GROUP,0
		
			FETCH #CUR1
				INTO @intLINK_GROUP
		END
		CLOSE #CUR1
		DEALLOCATE #CUR1
	
	END
	
	
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='COLUMN_CORR_NAME_JURN_BO')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'COLUMN_CORR_NAME_JURN_BO', 'Корреспондент(договор)', 25, (SELECT LINK FROM S_OBJECTS WHERE CODE='BD_JURN_BO'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'COLUMN_CORR_NAME_JURN_BO', NAME = 'Корреспондент(договор)', ORDERS = '25', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='BD_JURN_BO'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='COLUMN_CORR_NAME_JURN_BO'
GO
EXEC X_SET_PROP 'COLUMN_CORR_NAME_JURN_BO', 'TITLE', 'Корреспондент(договор)'
GO
EXEC X_SET_PROP 'COLUMN_CORR_NAME_JURN_BO', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'COLUMN_CORR_NAME_JURN_BO', 'CONTROLSOURCE', 'm.cAlias+".CORR_NAME"'
GO
EXEC X_SET_PROP 'COLUMN_CORR_NAME_JURN_BO', 'CONTROLSOURCE_EDIT', 'm.cAlias+".CORR_NAME"'
GO

GO
if not exists (select * from DICTIONARY_PLACE_ND_IMU where code = '260')
begin 
	declare @p1 float
	set @p1=0
	exec X_SAVE_DICTIONARY_PLACE_ND_IMU @p1 output,'260','По месту нахождения (учета)'
end
GO
/****** Объект: Номер водительского удостоверения******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'DRIVER_DOC_NUM')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'DRIVER_DOC_NUM')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'DRIVER_DOC_NUM')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'DRIVER_DOC_NUM')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'DRIVER_DOC_NUM'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'DRIVER_DOC_NUM')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='DRIVER_DOC_NUM')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'DRIVER_DOC_NUM', 'Номер водительского удостоверения', 22, (SELECT LINK FROM S_OBJECTS WHERE CODE='KU_PERSON'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'DRIVER_DOC_NUM', NAME = 'Номер водительского удостоверения', ORDERS = '22', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='KU_PERSON'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='DRIVER_DOC_NUM'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'TITLE', 'Вод. удостоверение'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'VISIBLE', '2'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'CONTROLSOURCE', 'm.cAlias+".DRIVER_DOC_NUM"'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'TYPE_FIELD_DICT', 'VARCHAR(12)'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'CONTROLSOURCE_EDIT', 'm.cAlias+".DRIVER_DOC_NUM"'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'CONTROL_NAME_EDIT', 'pageframe.page5.atxt17'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'REFERENCE_TO_FIELD', 'VALUE'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'ASPTYPE', 'TextBox'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'ATTRIBUTES', 'style="Z-INDEX: 104; LEFT: 152px; POSITION: absolute; TOP: 312px""
Width="224px"'
GO
EXEC X_SET_PROP 'DRIVER_DOC_NUM', 'LABEL_ATTRIBUTES', 'style="Z-INDEX: 130; LEFT: 16px; POSITION: absolute; TOP: 312px"'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/


GO
/****** Объект: Резидент******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'FACE_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'FACE_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'FACE_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'FACE_RESIDENT')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'FACE_RESIDENT'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'FACE_RESIDENT')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FACE_RESIDENT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FACE_RESIDENT', 'Резидент', 34, (SELECT LINK FROM S_OBJECTS WHERE CODE='KU_EMPL_PLACING'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FACE_RESIDENT', NAME = 'Резидент', ORDERS = '34', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='KU_EMPL_PLACING'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FACE_RESIDENT'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'TITLE', 'Резидент'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'CONTROLSOURCE', 'm.cAlias+".RESIDENT_N"'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'ROWSOURCE', '"Нерезидент (временно проживающий),Резидент,Нерезидент (постоянно проживающий)"'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'TYPE_FIELD_DICT', 'NUMERIC(1,0)'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'SHORT_CODE_OBJ', 'RESIDENT'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'CONTROLSOURCE_EDIT', 'm.cAlias+".RESIDENT"'
GO
EXEC X_SET_PROP 'FACE_RESIDENT', 'CONTROL_NAME_EDIT', 'Acombobox18'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/


GO
-- Отчет "Бюджетная смета"
-- Сгенерировано скриптом scriptObjectVar 'FB_BUDG_SMETA_REPORT'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'FB_BUDG_SMETA_REPORT'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'FB_BUDG_SMETA_REPORT'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Бюджетная смета',NULL, 
	(Select link from object_var where code = 'SQL_REPORT_CATALOG_FINANS'),
	'FB_BUDG_SMETA_REPORT',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'INIT_OBJECT_METHOD')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'INIT_OBJECT_METHOD'),
	VALUE= 'm_print_query(nLink_Var)'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'VISIBLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'VISIBLE'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_DATETIME'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FOOTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_PAGES'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDFROM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDFROM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDINTO')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDINTO'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDSELECT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDSELECT'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDWHERE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDWHERE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AFTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AFTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'EXEC dbo.FB_BUDG_SMETA_REPORT @dDateW1, @nOption1 , @cVal1, @nOtborLink1,@cVal2, @nOtborLink2,@cVal3, @nOtborLink3'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DATETIME'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DISTINCT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DISTINCT'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FREEZEPANES'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PAGES'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#FB_BUDG_SMETA_REPORT'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(@nOption1 = 1,"FB_BUDG_SMETA.XLT",IIF(@nOption1 > 1,"FB_BUDG_SMETA_CHANGE.XLT",""))'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #FB_BUDG_SMETA_REPORT
	@dDateW1 datetime	/* Дата отчета */,
	@nOption1 int	/* Тип отчета */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор КБК */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KBK''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор ЭКР */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_EKR''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal3 char(1), @nOtborLink3 int	/* Отбор по доп. классификации */
	SELECT @nOtborLink3 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_DOP_CLASSIF''))
	SELECT @cVal3 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink3 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

EXEC dbo.FB_BUDG_SMETA_REPORT @dDateW1, @nOption1 , @cVal1, @nOtborLink1,@cVal2, @nOtborLink2,@cVal3, @nOtborLink3

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SYSTEM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SYSTEM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTAL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTAL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALROW')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALROW'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AP_LIST')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AP_LIST'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_CODE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_CODE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DATE_TYPE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DATE_TYPE'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'SQUERY_NO_SHOW')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'SQUERY_NO_SHOW'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ALTERNATIVE_PRINT_METHOD')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ALTERNATIVE_PRINT_METHOD'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT') and  PROPERTY = (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'FB_BUDG_SMETA_REPORT'),
	PROPERTY= (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR'),
	VALUE= '0'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_FILTER' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_FILTER'),
		'Стандартный фильтр для запроса',0, 
		(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT'),
		'FB_BUDG_SMETA_REPORT_FILTER',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_DOP_CLASSIF'),
					'Отбор по доп. классификации',3, 
					(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_FILTER'),
					'FB_BUDG_SMETA_REPORT_OTBOR_DCL',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'BD_DOP_CLASSIF'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_DCL'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_EKR'),
					'Отбор ЭКР',2, 
					(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_FILTER'),
					'FB_BUDG_SMETA_REPORT_OTBOR_EKR',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICTIONARY_ITEM'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_EKR'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_KBK'),
					'Отбор КБК',1, 
					(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_FILTER'),
					'FB_BUDG_SMETA_REPORT_OTBOR_KBK',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'BI_DICTION_KBK'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_OTBOR_KBK'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_NASTR' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',4, 
		(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT'),
		'FB_BUDG_SMETA_REPORT_NASTR',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_DATE' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX_WD'),
					'Дата отчета',5, 
					(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_NASTR'),
					'FB_BUDG_SMETA_REPORT_DATE',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Дата отчета'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDateW1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'10.12.2013'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'02.03.2012'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'15.12.2011'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетная дата'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'29.09.2013'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_DATE'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'FB_BUDG_SMETA_REPORT_TYPE' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_OPTIONGROUP'),
					'Тип отчета',6, 
					(Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_NASTR'),
					'FB_BUDG_SMETA_REPORT_TYPE',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Тип отчета'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'OPTIONGROUP'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Основные документы, С учетом изменений, Только изменения '
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nOption1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Только изменения'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Только изменения'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'FB_BUDG_SMETA_REPORT_TYPE'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Группа настроек    ***/
GO
/***   Группа настроек    ***/
GO
/***   Группа настроек    ***/
GO
/***   Группа настроек    ***/
GO


GO
/****** Объект: Таблица договоров******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'FINANS_CONTRACT_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'FINANS_CONTRACT_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'FINANS_CONTRACT_TABLE')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'FINANS_CONTRACT_TABLE')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'FINANS_CONTRACT_TABLE'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'FINANS_CONTRACT_TABLE')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FINANS_CONTRACT_TABLE', 'Таблица договоров', 36, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT'), (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FINANS_CONTRACT_TABLE', NAME = 'Таблица договоров', ORDERS = '36', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='CLASS_GRID_GROUP'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FINANS_CONTRACT_TABLE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_CHECKED')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_CHECKED', 'Маркер', 1, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_CHECKED', NAME = 'Маркер', ORDERS = '1', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_CHECKED'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_REC_NO')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_REC_NO', 'Учетный номер', 2, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_REC_NO', NAME = 'Учетный номер', ORDERS = '2', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_REC_NO'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_REC_CH_NO')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_REC_CH_NO', 'Изм. учет. номер', 3, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_REC_CH_NO', NAME = 'Изм. учет. номер', ORDERS = '3', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_REC_CH_NO'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_VKR_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_VKR_LINK', 'Ссылка на ВКР', 4, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_VKR_LINK', NAME = 'Ссылка на ВКР', ORDERS = '4', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_VKR_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_VKR_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_VKR_CODE', 'Код ВКР', 5, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_VKR_CODE', NAME = 'Код ВКР', ORDERS = '5', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_VKR_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_VKR_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_VKR_NAME', 'Наименование ВКР', 6, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_VKR_NAME', NAME = 'Наименование ВКР', ORDERS = '6', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_VKR_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_EKR_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_EKR_LINK', 'Ссылка на КЭК', 7, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_EKR_LINK', NAME = 'Ссылка на КЭК', ORDERS = '7', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_EKR_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_EKR_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_EKR_CODE', 'Код КЭК', 8, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_EKR_CODE', NAME = 'Код КЭК', ORDERS = '8', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_EKR_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_EKR_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_EKR_NAME', 'Наименование КЭК', 9, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_EKR_NAME', NAME = 'Наименование КЭК', ORDERS = '9', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_EKR_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_DOP_CLASSIF_LINK')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_DOP_CLASSIF_LINK', 'Ссылка на доп. классификацию', 10, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_DOP_CLASSIF_LINK', NAME = 'Ссылка на доп. классификацию', ORDERS = '10', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_DOP_CLASSIF_LINK'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_DOP_CLASSIF_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_DOP_CLASSIF_CODE', 'Код доп. классификации', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_DOP_CLASSIF_CODE', NAME = 'Код доп. классификации', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_DOP_CLASSIF_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_DOP_CLASSIF_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_DOP_CLASSIF_NAME', 'Наименование доп. классификации', 12, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_DOP_CLASSIF_NAME', NAME = 'Наименование доп. классификации', ORDERS = '12', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_DOP_CLASSIF_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_OKDP_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_OKDP_CODE', 'Код ОКДП', 13, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_OKDP_CODE', NAME = 'Код ОКДП', ORDERS = '13', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_OKDP_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_OKDP_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_OKDP_NAME', 'Наименование', 14, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_OKDP_NAME', NAME = 'Наименование', ORDERS = '14', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_OKDP_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_UM_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_UM_NAME', 'Наименование Ед. изм.', 15, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_UM_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '15', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_UM_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_OKPD_CODE')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_OKPD_CODE', 'Код ОКПД', 16, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_OKPD_CODE', NAME = 'Код ОКПД', ORDERS = '16', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_OKPD_CODE'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_OKPD_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_OKPD_NAME', 'Наименование', 17, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_OKPD_NAME', NAME = 'Наименование', ORDERS = '17', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_OKPD_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_UM1_NAME')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_UM1_NAME', 'Наименование Ед. изм.', 18, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_UM1_NAME', NAME = 'Наименование Ед. изм.', ORDERS = '18', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_UM1_NAME'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_COST')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_COST', 'Цена', 19, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_COST', NAME = 'Цена', ORDERS = '19', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_COST'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_QUANTITY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_QUANTITY', 'Количество', 20, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_QUANTITY', NAME = 'Количество', ORDERS = '20', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_QUANTITY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_SUMMA')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_SUMMA', 'Сумма', 21, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_SUMMA', NAME = 'Сумма', ORDERS = '21', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_SUMMA'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_ITOG')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_ITOG', 'За год', 22, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_ITOG', NAME = 'За год', ORDERS = '22', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_ITOG'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_JAN')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_JAN', 'Январь', 23, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_JAN', NAME = 'Январь', ORDERS = '23', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_JAN'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_FEB')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_FEB', 'Февраль', 24, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_FEB', NAME = 'Февраль', ORDERS = '24', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_FEB'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_MAR')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_MAR', 'Март', 25, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_MAR', NAME = 'Март', ORDERS = '25', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_MAR'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_APR')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_APR', 'Апрель', 26, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_APR', NAME = 'Апрель', ORDERS = '26', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_APR'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_MAY')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_MAY', 'Май', 27, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_MAY', NAME = 'Май', ORDERS = '27', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_MAY'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_JUN')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_JUN', 'Июнь', 28, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_JUN', NAME = 'Июнь', ORDERS = '28', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_JUN'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_JUL')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_JUL', 'Июль', 29, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_JUL', NAME = 'Июль', ORDERS = '29', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_JUL'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_AUG')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_AUG', 'Август', 30, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_AUG', NAME = 'Август', ORDERS = '30', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_AUG'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_SEP')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_SEP', 'Сентябрь', 31, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_SEP', NAME = 'Сентябрь', ORDERS = '31', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_SEP'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_OCT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_OCT', 'Октябрь', 32, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_OCT', NAME = 'Октябрь', ORDERS = '32', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_OCT'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_NOV')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_NOV', 'Ноябрь', 33, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_NOV', NAME = 'Ноябрь', ORDERS = '33', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_NOV'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_DEC')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_DEC', 'Декабрь', 34, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_DEC', NAME = 'Декабрь', ORDERS = '34', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_DEC'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_Y2')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_Y2', '1 год ПП', 35, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_Y2', NAME = '1 год ПП', ORDERS = '35', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_Y2'
GO
IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='FIN_CON_TABLE_Y3')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'FIN_CON_TABLE_Y3', '2 год ПП', 36, (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,1
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'FIN_CON_TABLE_Y3', NAME = '2 год ПП', ORDERS = '36', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='FINANS_CONTRACT_TABLE'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='FIN_CON_TABLE_Y3'
GO
EXEC X_SET_PROP 'FINANS_CONTRACT_TABLE', 'SAVE_OBJECT_METHOD', 'ftable_contract_save(m.oForm.Alias)'
GO
EXEC X_SET_PROP 'FINANS_CONTRACT_TABLE', 'SELECT_RECORDS_METHOD', 'ftable_contract_select(m.cAlias, m.nLink, ''FINANS_CONTRACT_TABLE'')'
GO
EXEC X_SET_PROP 'FINANS_CONTRACT_TABLE', 'SERVER_TABLE_NAME', 'FINANSE_CONTRACT'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_CHECKED', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_CHECKED', 'CONTROLSOURCE', 'm.cAlias+''.CHECKED'''
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_CHECKED', 'FIELD_IN_ALIAS', '0'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'TITLE', 'Учетный номер'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'CONTROLSOURCE', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'TYPE_FIELD_DICT', 'NUMERIC(9)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'SHORT_CODE_OBJ', 'RECORD_NO'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".RECORD_NO"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_NO', 'INPUT_MASK', '9999999999'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'TITLE', 'Изм. учет. №'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'VISIBLE', '5'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'CONTROLSOURCE', 'm.cAlias + ".REC_CH_NO"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'TYPE_FIELD_DICT', 'NUMERIC(9)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'SHORT_CODE_OBJ', 'REC_CH_NO'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".REC_CH_NO"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_REC_CH_NO', 'INPUT_MASK', '9999999999'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_LINK', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_LINK', 'REFERENCE_TO_DICT', 'bi_diction_vkr'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_LINK', 'SHORT_CODE_OBJ', 'VKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'TITLE', 'ВКР'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("bi_diction_kbk", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "VKR, VKR_CODE, VKR_NAME", "", "", "type=1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'CONTROLSOURCE', 'm.cAlias + ".VKR_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'REFERENCE_TO_DICT', 'FIN_CON_TABLE_VKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'SHORT_CODE_OBJ', 'VKR_CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".VKR_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'TITLE', 'Расш. ВКР'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'CONTROLSOURCE', 'm.cAlias + ".VKR_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'REFERENCE_TO_DICT', 'FIN_CON_TABLE_VKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'SHORT_CODE_OBJ', 'VKR_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".VKR_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_VKR_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_LINK', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_LINK', 'REFERENCE_TO_DICT', 'DICTIONARY_ITEM'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_LINK', 'SHORT_CODE_OBJ', 'EKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'TITLE', 'ЭКР'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("DICTIONARY_ITEM", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "EKR, EKR_CODE, EKR_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'CONTROLSOURCE', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'REFERENCE_TO_DICT', 'FIN_CON_TABLE_EKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'TYPE_FIELD_DICT', 'char(6)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'SHORT_CODE_OBJ', 'EKR_CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'TITLE', 'Расш. ЭКР'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'CONTROLSOURCE', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'REFERENCE_TO_DICT', 'FIN_CON_TABLE_EKR_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'TYPE_FIELD_DICT', 'varchar(100)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'SHORT_CODE_OBJ', 'EKR_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".EKR_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_EKR_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_LINK', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_LINK', 'REFERENCE_TO_DICT', 'BD_DOP_CLASSIF'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_LINK', 'SHORT_CODE_OBJ', 'D_CL_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_LINK', 'REFERENCE_TO_FIELD', 'LINK'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'TITLE', 'Доп. классиф-ия'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BD_DOP_CLASSIF", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "D_CL_LINK, D_CL_CODE, D_CL_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'CONTROLSOURCE', 'm.cAlias + ".D_CL_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'REFERENCE_TO_DICT', 'FIN_CON_DOP_CLASSIF_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'TYPE_FIELD_DICT', 'varchar(10)'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'SHORT_CODE_OBJ', 'D_CL_CODE'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".D_CL_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_CODE', 'REFERENCE_TO_FIELD', 'CODE'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'TITLE', 'Доп. классификация'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'CONTROLSOURCE', 'm.cAlias + ".D_CL_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'REFERENCE_TO_DICT', 'FIN_CON_DOP_CLASSIF_LINK'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'TYPE_FIELD_DICT', 'varchar(150)'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'SHORT_CODE_OBJ', 'D_CL_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".D_CL_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_DOP_CLASSIF_NAME', 'REFERENCE_TO_FIELD', 'NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'TITLE', 'Код ОКДП'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKDP, OKDP_CODE, OKDP_NAME,UM_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'SHORT_CODE_OBJ', 'OKDP_CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKDP", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "OKDP, OKDP_CODE, OKDP_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'SHORT_CODE_OBJ', 'OKDP_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKDP_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKDP_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'SHORT_CODE_OBJ', 'UM_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'TITLE', 'Код ОКПД'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME_TABLE,NAME_UM", "OKPD, OKPD_CODE, OKPD_NAME,UM1_NAME", "", "", "CHILDRENS = 1", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'SHORT_CODE_OBJ', 'OKPD_CODE'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_CODE', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_CODE"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'TITLE', 'Наименование'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'EDIT_OBJECT_METHOD', 'A_VIBOR_01 ("BB_OKPD", oObj.Parent.Parent.RECORDSOURCE, "LINK,CODE,NAME", "OKPD, OKPD_CODE, OKPD_NAME", "", "", "", .T., 1, oForm, oObj)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'CONTROLSOURCE', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'TYPE_FIELD_DICT', 'char(5)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'SHORT_CODE_OBJ', 'OKPD_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OKPD_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".OKPD_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'TITLE', 'Ед. изм.'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'CONTROLSOURCE', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'STORAGE', 'DICTION'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'TYPE_FIELD_DICT', 'varchar(20)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'SHORT_CODE_OBJ', 'UM1_NAME'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_UM1_NAME', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".UM1_NAME"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'TITLE', 'Цена'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj,.t.)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'CONTROLSOURCE', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'SHORT_CODE_OBJ', 'COST'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_COST', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".COST"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'TITLE', 'Количество'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj,.t.)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'CONTROLSOURCE', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'SHORT_CODE_OBJ', 'QUANTITY'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_QUANTITY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".QUANTITY"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'TITLE', 'Сумма'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'EDIT_OBJECT_METHOD', 'bb_calc_summ(oObj,.t.)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'CONTROLSOURCE', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'SHORT_CODE_OBJ', 'SUMMA'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SUMMA', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".SUMMA"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'TITLE', 'За год'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'CONTROLSOURCE', 'm.cAlias + ".ITOG"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'SHORT_CODE_OBJ', 'ITOG'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_ITOG', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".ITOG"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'TITLE', 'Январь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'CONTROLSOURCE', 'm.cAlias + ".P1"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'SHORT_CODE_OBJ', 'P1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JAN', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P1"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'TITLE', 'Февраль'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'CONTROLSOURCE', 'm.cAlias + ".P2"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'SHORT_CODE_OBJ', 'P2'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_FEB', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P2"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'TITLE', 'Март'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'CONTROLSOURCE', 'm.cAlias + ".P3"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'SHORT_CODE_OBJ', 'P3'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAR', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P3"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'TITLE', 'Апрель'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'CONTROLSOURCE', 'm.cAlias + ".P4"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'SHORT_CODE_OBJ', 'P4'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_APR', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P4"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'TITLE', 'Май'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'CONTROLSOURCE', 'm.cAlias + ".P5"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'SHORT_CODE_OBJ', 'P5'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_MAY', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P5"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'TITLE', 'Июнь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'CONTROLSOURCE', 'm.cAlias + ".P6"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'SHORT_CODE_OBJ', 'P6'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUN', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P6"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'TITLE', 'Июль'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'CONTROLSOURCE', 'm.cAlias + ".P7"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'SHORT_CODE_OBJ', 'P7'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_JUL', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P7"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'TITLE', 'Август'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'CONTROLSOURCE', 'm.cAlias + ".P8"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'SHORT_CODE_OBJ', 'P8'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_AUG', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P8"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'TITLE', 'Сентябрь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'CONTROLSOURCE', 'm.cAlias + ".P9"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'SHORT_CODE_OBJ', 'P9'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_SEP', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P9"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'TITLE', 'Октябрь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'CONTROLSOURCE', 'm.cAlias + ".P10"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'SHORT_CODE_OBJ', 'P10'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_OCT', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P10"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'TITLE', 'Ноябрь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'CONTROLSOURCE', 'm.cAlias + ".P11"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'SHORT_CODE_OBJ', 'P11'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_NOV', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P11"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'TITLE', 'Декабрь'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'VISIBLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'CONTROLSOURCE', 'm.cAlias + ".P12"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'SHORT_CODE_OBJ', 'P12'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_DEC', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".P12"'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'TITLE', '1 год ПП'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'VISIBLE', '0'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'CONTROLSOURCE', 'm.cAlias + ".Y2 "'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'EDITABLE', '0'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'SHORT_CODE_OBJ', 'Y2'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y2', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".Y2 "'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'TITLE', '2 год ПП'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'VISIBLE', '0'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'CONTROLSOURCE', 'm.cAlias + ".Y3 "'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'EDITABLE', '0'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'TYPE_FIELD_DICT', 'NUMERIC(19,2)'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'SHORT_CODE_OBJ', 'Y3'
GO
EXEC X_SET_PROP 'FIN_CON_TABLE_Y3', 'CONTROLSOURCE_EDIT', 'm.cAlias + ".Y3 "'
GO

/**************** УСТАНОВКА ДОСТУПА К ОБЪЕКТУ *************/
EXEC DBO.W_SPERM_WRITE 'FINANS_CONTRACT_TABLE', 'Смета-КС', 63,0
GO
EXEC DBO.W_SPERM_WRITE 'FINANS_CONTRACT_TABLE', 'Свод-КС', 5,0
GO


GO
EXEC dbo.[RO_KBK_CASHE_UPDATE] @vcCodeForm = 'ИСТОЧНИКИ_2011'
GO
-- Отчет "Сведения о государственных гражданских служащих (р.1)"
-- Сгенерировано скриптом scriptObjectVar 'REP_SVED_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_SVED_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_SVED_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о государственных гражданских служащих (р.1)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_SVED_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec SVED_GOS_SLUSH @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_SVED_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_SVED_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_SVED_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec SVED_GOS_SLUSH @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_SVED_GOS_SLUSH'),
		'REP_SVED_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_SVED_GOS_SLUSH_GROUP'),
					'REP_SVED_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'

						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_SVED_GOS_SLUSH_GROUP'),
					'REP_SVED_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'

GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Постановление №389-РГ"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_TREE_ROOT')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_TREE_ROOT'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'),0)

IF COALESCE(@LINK_SELF,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'KADRY_POST_389', 'Постановление №389-РГ', @ORD, NULL, 1, @LINK_SELF, 'FOLDER', NULL, @LINK_VAR, 3
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о государственных гражданских служащих (р.1)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_SVED_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_SVED_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_SVED_GOS_SLUSH', 'Сведения о государственных гражданских служащих (р.1)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO


GO

-- Отчет "Сведения о временно отсутствующих гос. гражд. служащих (р.2)"
-- Сгенерировано скриптом scriptObjectVar 'REP_TMP_OTS_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_TMP_OTS_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о временно отсутствующих гос. гражд. служащих (р.2)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_TMP_OTS_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_TMP_OTS_GS @dDate1, @dDate2'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_TMP_OTS_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_TMP_OTS_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_TMP_OTS_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_TMP_OTS_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH'),
		'REP_TMP_OTS_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_GROUP'),
					'REP_TMP_OTS_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_GROUP'),
					'REP_TMP_OTS_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о временно отсутствующих гос. гражд. служащих (р.2)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_TMP_OTS_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_TMP_OTS_GOS_SLUSH', 'Сведения о временно отсутствующих гос. гражд. служащих (р.2)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO

-- Отчет "Сведения о замещении должностей гос. гражд. службы (р.3)"
-- Сгенерировано скриптом scriptObjectVar 'REP_REPL_KADR_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_REPL_KADR_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о замещении должностей гос. гражд. службы (р.3)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_REPL_KADR_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_REPL_KADR_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_REPL_KADR_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_REPL_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_REPL_KADR_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_REPL_KADR_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH'),
		'REP_REPL_KADR_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_GROUP'),
					'REP_REPL_KADR_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_GROUP'),
					'REP_REPL_KADR_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о замещении должностей гос. гражд. службы (р.3)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_REPL_KADR_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_REPL_KADR_GOS_SLUSH', 'Сведения о замещении должностей гос. гражд. службы (р.3)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO

-- Отчет "Список уволенных за отчетный период (р.4)"
-- Сгенерировано скриптом scriptObjectVar 'REP_UVOL_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_UVOL_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_UVOL_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Список уволенных за отчетный период (р.4)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_UVOL_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_UVOL_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_UVOL_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_UVOL_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_UVOL_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_UVOL_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH'),
		'REP_UVOL_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_GROUP'),
					'REP_UVOL_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_GROUP'),
					'REP_UVOL_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Список уволенных за отчетный период (р.4)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_UVOL_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_UVOL_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_UVOL_GOS_SLUSH', 'Список уволенных за отчетный период (р.4)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

-- Отчет "Информация о вакантных должностях гражд. службы (р.5)"
-- Сгенерировано скриптом scriptObjectVar 'REP_VAC_POST_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_VAC_POST_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_VAC_POST_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Информация о вакантных должностях гражд. службы (р.5)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_VAC_POST_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_VAC_POST_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_VAC_POST_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_VAC_POST_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_VAC_POST_GOS_SLUSH
	@dDate1 datetime	/* Расчетная дата */
AS
BEGIN

exec REP_VAC_POST_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH'),
		'REP_VAC_POST_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Расчетная дата',2, 
					(Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_GROUP'),
					'REP_VAC_POST_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Текущая дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Информация о вакантных должностях гражд. службы (р.5)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_VAC_POST_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_VAC_POST_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_VAC_POST_GOS_SLUSH', 'Информация о вакантных должностях гражд. службы (р.5)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO


-- Отчет "Результаты аттестации гражданских служащих (р.6)"
-- Сгенерировано скриптом scriptObjectVar 'REP_ATT_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_ATT_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_ATT_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Результаты аттестации гражданских служащих (р.6)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_ATT_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_RES_ATT_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_ATT_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_RES_ATT_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_ATT_GOS_SLUSH
	@dDate1 datetime	/* Расчетная дата */
AS
BEGIN

exec REP_RES_ATT_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_ATT_GOS_SLUSH'),
		'REP_ATT_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Расчетная дата',2, 
					(Select link from object_var where code = 'REP_ATT_GOS_SLUSH_GROUP'),
					'REP_ATT_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Результаты аттестации гражданских служащих (р.6)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_ATT_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_ATT_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_ATT_GOS_SLUSH', 'Результаты аттестации гражданских служащих (р.6)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO

-- Отчет "Аналитическая таблица по гос. гражд. служащим  (р.7)"
-- Сгенерировано скриптом scriptObjectVar 'REP_ANALIT_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_ANALIT_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_ANALIT_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Аналитическая таблица по гос. гражд. служащим  (р.7)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_ANALIT_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_ANALIT_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_ANALIT_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_ANALIT_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_ANALIT_GOS_SLUSH
	@dDate1 datetime	/* Дата отчета */
AS
BEGIN

exec REP_ANALIT_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH'),
		'REP_ANALIT_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH_N1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Дата отчета',2, 
					(Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_GROUP'),
					'REP_ANALIT_GOS_SLUSH_N1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Дата отчета'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Аналитическая таблица по гос. гражд. служащим  (р.7)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_ANALIT_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_ANALIT_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_ANALIT_GOS_SLUSH', 'Аналитическая таблица по гос. гражд. служащим  (р.7)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO


GO

-- Отчет "Реестр госуд.гражд.служащих (р.8)"
-- Сгенерировано скриптом scriptObjectVar 'REP_REESTR_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_REESTR_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_REESTR_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Реестр госуд.гражд.служащих (р.8)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_REESTR_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_REESTR_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_REESTR_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKERMULTISHEET.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_REESTR_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_REESTR_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_REESTR_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepReestrGS.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH'),
		'REP_REESTR_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_GROUP'),
					'REP_REESTR_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2014'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_GROUP'),
					'REP_REESTR_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Реестр госуд.гражд.служащих (р.8)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_REESTR_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_REESTR_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_REESTR_GOS_SLUSH', 'Реестр госуд.гражд.служащих (р.8)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
--- ОТЧЕТ: ВЕДОМОСТЬ АМОРТИЗАЦИИ (SQL_REP_BOOK_AMORT) --- 
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL1'
GO
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_SQL'), 'Ведомость амортизации', NULL, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REPORT_CATALOG_ASSETS'), 'SQL_REP_BOOK_AMORT', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_FILTER'), 'Стандартный фильтр для запроса', 0, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT'), 'SQL_REP_BOOK_AMORT_FIL1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_NASTRS'), 'Группа настроек', 3, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT'), 'SQL_REP_BOOK_AMORT_NAS1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KBK'), 'Отбор КБК', 2, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL1'), 'SQL_REP_BOOK_AMORT_FIL12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_ACCT_NMA_NPA'), 'Отбор субсчетов ОС, НМА, НПА', 1, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_FIL1'), 'SQL_REP_BOOK_AMORT_FIL11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_MONTHBOX'), 'Расчетный месяц', 4, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_YEARBOX'), 'Расчетный год', 5, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS13')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Включить ОС, по которым не начислялась амортизация', 6, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS13', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS14')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Сводный отчет (ЦБ)', 9, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS14', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS15')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Группировать по КБК', 8, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS15', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS16')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Включить только ОС, по которым начислялась амортизация за указанный период', 7, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_NAS1'), 'SQL_REP_BOOK_AMORT_NAS16', NULL, NULL, 1
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'INIT_OBJECT_METHOD', 'm_print_query(nLink_Var)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'CHECK_VALUE_IN_TABLE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'AFTER_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'BEFORE_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_CENTER_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_FOOTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_LEFT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'NASTR_XL_RIGHT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_ADDFROM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_ADDINTO', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_ADDSELECT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_ADDWHERE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_AFTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_BEFORE', 'EXEC	dbo.BK_REPORT_BOOK_AMORT1
	@nMonth1		/* Расчетный месяц */,
	@cYear1		/* Год */,
	@cVal1,	@nOtborLink1		/* Отбор субсчетов  "Основные средства" */,
	DEFAULT, DEFAULT, DEFAULT,
	@nCheck1,	/* Включить ОС, по которым не начислялась амортизация */
	@nCheck2,	/* Сводный отчет (ЦБ) */
	@cVal2, @nOtborLink2,	/* Отбор КБК */
	@nCheck3	/* Группировать по КБК */,
	@nCheck4	/* Включить только ОС, по которым начислялась амортизация за указанный */', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_DISTINCT', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_FOOTER', '="Исполнитель                               " & User_FIO
                                 подпись', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_HEADER', '=User_Name', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_PROCEDURE', '#REP_BOOK_AMORT', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_REPMAKER', 'KIRREPMAKER.XLS', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_REPORT', 'IIF(.T.,"AMORT_BOOK.XLT","")', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_REPORT_PATH', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_SQL', 'CREATE PROCEDURE #REP_BOOK_AMORT
	@nMonth1 int	/* Расчетный месяц */,
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCheck1 int	/* Включить ОС, по которым не начислялась амортизация */,
	@nCheck4 int	/* Включить только ОС, по которым начислялась амортизация за указанный период */,
	@nCheck3 int	/* Группировать по КБК */,
	@nCheck2 int	/* Сводный отчет (ЦБ) */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор субсчетов ОС, НМА, НПА */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_ACCT_NMA_NPA''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор КБК */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KBK''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

EXEC	dbo.BK_REPORT_BOOK_AMORT1
	@nMonth1		/* Расчетный месяц */,
	@cYear1		/* Год */,
	@cVal1,	@nOtborLink1		/* Отбор субсчетов  "Основные средства" */,
	DEFAULT, DEFAULT, DEFAULT,
	@nCheck1,	/* Включить ОС, по которым не начислялась амортизация */
	@nCheck2,	/* Сводный отчет (ЦБ) */
	@cVal2, @nOtborLink2,	/* Отбор КБК */
	@nCheck3	/* Группировать по КБК */,
	@nCheck4	/* Включить только ОС, по которым начислялась амортизация за указанный */

END', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_SYSTEM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_TOP', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_TOTAL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_TOTALCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_TOTALROW', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_AP_LIST', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'EOD_PROTOCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'AFTER_REPORT_PROG', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_ADD_MODULE', 'KirRepCommon.bas', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'QUERY_DATE_TYPE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'SQUERY_NO_SHOW', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT', 'REPORT_EXTERNAL_GENERATOR', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL1', 'QUERY_NASTR_NOTE', 'Стандартный фильтр для отчета', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL1', 'QUERY_VARIANT_ID', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS1', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_OTBOR_DICTIONARY_CODE', 'BI_DICTION_KBK', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL12', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICT_SUBACCOUNTS_OS_NMA_NPA', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_FIL11', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_CAPTION', 'Расчетный месяц', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_CONTROL', 'MONTHBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_SOURCE', 'Текущий месяц,Расчетный месяц', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_SQLPARAM', '@nMonth1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_VALUE', 'Текущий месяц', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS11', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'FORMAT', '9999', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_CAPTION', 'Расчетный год', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_CONTROL', 'MASKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_SOURCE', 'Текущий год,Расчетный год', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_SQLPARAM', '@cYear1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_SQLTYPE', 'VARCHAR(4)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_VALUE', 'Расчетный год', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS12', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_CAPTION', 'Включить ОС, по которым не начислялась амортизация', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_SQLPARAM', '@nCheck1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS13', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_CAPTION', 'Сводный отчет (ЦБ)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_NUMPARAM', '2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_SQLPARAM', '@nCheck2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS14', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_CAPTION', 'Группировать по КБК', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_NUMPARAM', '3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_SQLPARAM', '@nCheck3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS15', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_CAPTION', 'Включить только ОС, по которым начислялась амортизация за указанный период', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_NUMPARAM', '4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_SQLPARAM', '@nCheck4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_NAS16', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO


GO
--- ОТЧЕТ: ВЕДОМОСТЬ АМОРТИЗАЦИИ ЗА ПЕРИОД (SQL_REP_BOOK_AMORT_PER) --- 
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL1'
GO
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_SQL'), 'Ведомость амортизации за период', NULL, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REPORT_CATALOG_ASSETS'), 'SQL_REP_BOOK_AMORT_PER', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_FILTER'), 'Стандартный фильтр для запроса', 0, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER'), 'SQL_REP_BOOK_AMORT_PER_FIL1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_NASTRS'), 'Группа настроек', 3, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER'), 'SQL_REP_BOOK_AMORT_PER_NAS1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KBK'), 'Отбор КБК', 2, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL1'), 'SQL_REP_BOOK_AMORT_PER_FIL12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_ACCT_NMA_NPA'), 'Отбор субсчетов ОС, НМА, НПА', 1, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_FIL1'), 'SQL_REP_BOOK_AMORT_PER_FIL11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PB'), 'Начало расч. периода', 4, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PE'), 'Конец расч. периода', 5, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS13')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Включить ОС, по которым не начислялась амортизация', 6, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS13', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS14')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Сводный отчет (ЦБ)', 9, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS14', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS15')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Группировать по КБК', 8, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS15', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS16')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Включить только ОС, по которым начислялась амортизация за указанный период', 7, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_BOOK_AMORT_PER_NAS1'), 'SQL_REP_BOOK_AMORT_PER_NAS16', NULL, NULL, 1
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'INIT_OBJECT_METHOD', 'm_print_query(nLink_Var)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'CHECK_VALUE_IN_TABLE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'AFTER_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'BEFORE_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_CENTER_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_FOOTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_LEFT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'NASTR_XL_RIGHT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_ADDFROM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_ADDINTO', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_ADDSELECT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_ADDWHERE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_AFTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_BEFORE', 'EXEC	BK_REPORT_BOOK_AMORT1
	0	/* Расчетный месяц */,
	''''		/* Год */,
	@cVal1,	@nOtborLink1		/* Отбор субсчетов  "Основные средства" */,
	@dDateB1	/* Начало расч. периода */,
	@dDateE1	/* Конец расч. периода */,
	1,
	@nCheck1,	/* Включить ОС, по которым не начислялась амортизация */
	@nCheck2,	/* Сводный отчет (ЦБ) */
	@cVal2, @nOtborLink2,	/* Отбор КБК */
	@nCheck3	/* Группировать по КБК */,
	@nCheck4	/* Включить только ОС, по которым начислялась амортизация за указанный */
', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_DISTINCT', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_FOOTER', '="Исполнитель                               " & User_FIO
                                 подпись', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_HEADER', '=User_Name', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_PROCEDURE', '#REP_BOOK_AMORT_PER', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_REPMAKER', 'KIRREPMAKER.XLS', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_REPORT', 'IIF(.T.,"AMORT_BOOK.XLT","")', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_REPORT_PATH', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_SQL', 'CREATE PROCEDURE #REP_BOOK_AMORT_PER
	@dDateB1 datetime	/* Начало расч. периода */,
	@dDateE1 datetime	/* Конец расч. периода */,
	@nCheck1 int	/* Включить ОС, по которым не начислялась амортизация */,
	@nCheck4 int	/* Включить только ОС, по которым начислялась амортизация за указанный период */,
	@nCheck3 int	/* Группировать по КБК */,
	@nCheck2 int	/* Сводный отчет (ЦБ) */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор субсчетов ОС, НМА, НПА */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_ACCT_NMA_NPA''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор КБК */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KBK''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

EXEC	BK_REPORT_BOOK_AMORT1
	0	/* Расчетный месяц */,
	''''		/* Год */,
	@cVal1,	@nOtborLink1		/* Отбор субсчетов  "Основные средства" */,
	@dDateB1	/* Начало расч. периода */,
	@dDateE1	/* Конец расч. периода */,
	1,
	@nCheck1,	/* Включить ОС, по которым не начислялась амортизация */
	@nCheck2,	/* Сводный отчет (ЦБ) */
	@cVal2, @nOtborLink2,	/* Отбор КБК */
	@nCheck3	/* Группировать по КБК */,
	@nCheck4	/* Включить только ОС, по которым начислялась амортизация за указанный */


END', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_SYSTEM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_TOP', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_TOTAL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_TOTALCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_TOTALROW', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_AP_LIST', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'EOD_PROTOCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'AFTER_REPORT_PROG', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_ADD_MODULE', 'KirRepCommon.bas', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'QUERY_DATE_TYPE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'SQUERY_NO_SHOW', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER', 'REPORT_EXTERNAL_GENERATOR', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL1', 'QUERY_NASTR_NOTE', 'Стандартный фильтр для отчета', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL1', 'QUERY_VARIANT_ID', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS1', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_OTBOR_DICTIONARY_CODE', 'BI_DICTION_KBK', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL12', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICT_SUBACCOUNTS_OS_NMA_NPA', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_FIL11', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_CAPTION', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_SQLPARAM', '@dDateB1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_VALUE', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS11', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_CAPTION', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_SQLPARAM', '@dDateE1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_VALUE', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS12', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_CAPTION', 'Включить ОС, по которым не начислялась амортизация', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_SQLPARAM', '@nCheck1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS13', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_CAPTION', 'Сводный отчет (ЦБ)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_NUMPARAM', '2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_SQLPARAM', '@nCheck2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS14', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_CAPTION', 'Группировать по КБК', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_NUMPARAM', '3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_SQLPARAM', '@nCheck3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS15', 'SQUERY_NASTR_OPTIONAL', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_CAPTION', 'Включить только ОС, по которым начислялась амортизация за указанный период', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_NUMPARAM', '4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_SQLPARAM', '@nCheck4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_BOOK_AMORT_PER_NAS16', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO


GO
--- ОТЧЕТ: ВЕДОМОСТЬ ДВИЖЕНИЯ ПО СУБСЧЕТУ (SQL_REP_VM1) --- 
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'
GO
DELETE FROM dbo.OBJECT_VAR WHERE LINK_SELF = (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1')
DELETE FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_SQL'), 'Ведомость движения по субсчету', NULL, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REPORT_COMMON_CATALOG'), 'SQL_REP_VM1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_FILTER'), 'Стандартный фильтр для запроса', 0, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1'), 'SQL_REP_VM1_FIL1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'QUERY_NASTRS'), 'Группа настроек', 6, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1'), 'SQL_REP_VM1_NAS1', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KBK'), 'Отбор КБК', 1, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'), 'SQL_REP_VM1_FIL11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_DEPART'), 'Отбор учреждений', 2, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'), 'SQL_REP_VM1_FIL12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL13')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_EMPLOYERS'), 'Отбор сотрудников', 3, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'), 'SQL_REP_VM1_FIL13', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL14')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_KAU'), 'Отбор КАУ', 4, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'), 'SQL_REP_VM1_FIL14', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL15')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'OTBOR_QUERY_SQL_DOP_CLASSIF'), 'Отбор по доп. классификации', 5, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_FIL1'), 'SQL_REP_VM1_FIL15', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS11')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PB'), 'Начало расч. периода', 7, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS11', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS12')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_DATEBOX_PE'), 'Конец расч. периода', 8, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS12', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS13')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_LSEL_SPR'), 'Субсчет', 9, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS13', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS14')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Код счета с КБК', 10, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS14', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS15')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Код счета с СГУ', 11, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS15', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS16')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Сводный отчет (ЦБ)', 12, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS16', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS17')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_COMBOBOX'), 'Показатель', 13, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS17', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS18')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Выводить итоги по показателю', 14, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS18', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS19')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Группировать в разрезе КБК', 15, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS19', NULL, NULL, 1
GO
IF NOT EXISTS (SELECT * FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS20')
	INSERT INTO dbo.OBJECT_VAR (OBJECT, [NAME], ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS)
	SELECT (SELECT LINK FROM dbo.S_OBJECTS WHERE CODE = 'NASTR_QUERY_CHECKBOX'), 'Остатки', 16, (SELECT LINK FROM dbo.OBJECT_VAR WHERE CODE = 'SQL_REP_VM1_NAS1'), 'SQL_REP_VM1_NAS20', NULL, NULL, 1
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'INIT_OBJECT_METHOD', 'm_print_query(nLink_Var)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'CHECK_VALUE_IN_TABLE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'AFTER_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'BEFORE_CHANGE_PROG_NASTR', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_CENTER_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_FOOTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_LEFT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'NASTR_XL_RIGHT_HEADER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_ADDFROM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_ADDINTO', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_ADDSELECT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_ADDWHERE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_AFTER', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_BEFORE', 'DECLARE @strAP_CODE VARCHAR (10)
SET @strAP_CODE = CASE 
								WHEN @nCombo1 = 2 THEN ''DEP''
								WHEN @nCombo1 = 3 THEN ''EMP''
								WHEN @nCombo1 = 4 THEN ''KAU''
								ELSE ''''
							END

EXEC	dbo.BK_REPORT_VM1
	@dDateB1	/* Начало расч. периода */,
	@dDateE1	/* Конец расч. периода */,
	@nSel_Spr1	/* Субсчет */,
	@nCheck1	/* Код счета с КБК */,
	@nCheck2	/* Код счета с СГУ */,
	@cVal1, @nOtborLink1	/* Отбор КБК */,
	@nCheck3	/* Сводный отчет (ЦБ) */,
	@cVal2,	@nOtborLink2	/* Отбор учреждений */,
	@cVal3,	@nOtborLink3	/* Отбор сотрудников */,
	@cVal4,	@nOtborLink4	/* Отбор КАУ */,
	@cVal5,	@nOtborLink5	/* Отбор по доп. классификации */,
	@strAP_CODE,
	@nCheck4	/* Вывести итоги по показателю */,
	@nCheck5	/* Группировать в разрезе КБК */,
	@nCheck6	/* Остатки */', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_DATETIME', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_DISTINCT', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_FOOTER', '="Исполнитель                               " & User_FIO
                                 подпись', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_FREEZEPANES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_HEADER', '=User_Name', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_PAGES', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_PROCEDURE', '#REP_VM1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_REPMAKER', 'KirRepMaker.XLS', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_REPORT', 'IIF(.T.,"VM_BY_ACCOUNT.XLT","")', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_REPORT_PATH', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_SQL', 'CREATE PROCEDURE #REP_VM1
	@dDateB1 datetime	/* Начало расч. периода */,
	@dDateE1 datetime	/* Конец расч. периода */,
	@nSel_Spr1 int	/* Субсчет */,
	@nCheck1 int	/* Код счета с КБК */,
	@nCheck2 int	/* Код счета с СГУ */,
	@nCheck3 int	/* Сводный отчет (ЦБ) */,
	@nCombo1 int	/* Показатель */,
	@nCheck4 int	/* Выводить итоги по показателю */,
	@nCheck5 int	/* Группировать в разрезе КБК */,
	@nCheck6 int	/* Остатки */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор КБК */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KBK''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор учреждений */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_DEPART''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal3 char(1), @nOtborLink3 int	/* Отбор сотрудников */
	SELECT @nOtborLink3 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_EMPLOYERS''))
	SELECT @cVal3 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink3 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal4 char(1), @nOtborLink4 int	/* Отбор КАУ */
	SELECT @nOtborLink4 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_KAU''))
	SELECT @cVal4 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink4 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal5 char(1), @nOtborLink5 int	/* Отбор по доп. классификации */
	SELECT @nOtborLink5 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_DOP_CLASSIF''))
	SELECT @cVal5 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink5 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

DECLARE @strAP_CODE VARCHAR (10)
SET @strAP_CODE = CASE 
								WHEN @nCombo1 = 2 THEN ''DEP''
								WHEN @nCombo1 = 3 THEN ''EMP''
								WHEN @nCombo1 = 4 THEN ''KAU''
								ELSE ''''
							END

EXEC	dbo.BK_REPORT_VM1
	@dDateB1	/* Начало расч. периода */,
	@dDateE1	/* Конец расч. периода */,
	@nSel_Spr1	/* Субсчет */,
	@nCheck1	/* Код счета с КБК */,
	@nCheck2	/* Код счета с СГУ */,
	@cVal1, @nOtborLink1	/* Отбор КБК */,
	@nCheck3	/* Сводный отчет (ЦБ) */,
	@cVal2,	@nOtborLink2	/* Отбор учреждений */,
	@cVal3,	@nOtborLink3	/* Отбор сотрудников */,
	@cVal4,	@nOtborLink4	/* Отбор КАУ */,
	@cVal5,	@nOtborLink5	/* Отбор по доп. классификации */,
	@strAP_CODE,
	@nCheck4	/* Вывести итоги по показателю */,
	@nCheck5	/* Группировать в разрезе КБК */,
	@nCheck6	/* Остатки */

END', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_SYSTEM', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_TOP', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_TOTAL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_TOTALCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_TOTALROW', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_AP_LIST', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'EOD_PROTOCOL', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'AFTER_REPORT_PROG', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_ADD_MODULE', 'KirRepCommon.bas', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'QUERY_DATE_TYPE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'SQUERY_NO_SHOW', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1', 'REPORT_EXTERNAL_GENERATOR', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL1', 'QUERY_NASTR_NOTE', 'Стандартный фильтр для отчета', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL1', 'QUERY_VARIANT_ID', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS1', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_OTBOR_DICTIONARY_CODE', 'BI_DICTION_KBK', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL11', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICTIONARY_DEPARTMENT', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL12', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_OTBOR_DICTIONARY_CODE', 'KU_EMPL_PLACING', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL13', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_OTBOR_DICTIONARY_CODE', 'DICTIONARY_ANALYTICAL_CODES', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL14', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_OTBOR_CHECK', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_OTBOR_DICTIONARY_CODE', 'BD_DOP_CLASSIF', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_OTBOR_FIELD', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_OTBOR_PARENT_CODE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_FIL15', 'QUERY_OTBOR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_CAPTION', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_SQLPARAM', '@dDateB1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_VALUE', 'Начало расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS11', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_CAPTION', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_CONTROL', 'DATEBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_SOURCE', 'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_SQLPARAM', '@dDateE1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_SQLTYPE', 'datetime', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_VALUE', 'Конец расч. периода', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS12', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_CAPTION', 'Субсчет', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_CONTROL', 'LSel_Spr', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_SOURCE', 'DICT_SUBACCOUNTS', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_SQLPARAM', '@nSel_Spr1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_VALUE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS13', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_CAPTION', 'Код счета с КБК', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_SQLPARAM', '@nCheck1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS14', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_CAPTION', 'Код счета с СГУ', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_NUMPARAM', '2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_SQLPARAM', '@nCheck2', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS15', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_CAPTION', 'Сводный отчет (ЦБ)', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_NUMPARAM', '3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_SAVE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_SQLPARAM', '@nCheck3', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS16', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_CAPTION', 'Показатель', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_CONTROL', 'COMBOBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_NUMPARAM', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_SOURCE', ',Учреждение,Сотрудник,КАУ', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_SQLPARAM', '@nCombo1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_VALUE', 'Сотрудник', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS17', 'SQUERY_NASTR_OPTIONAL', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_CAPTION', 'Выводить итоги по показателю', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_NUMPARAM', '4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_SQLPARAM', '@nCheck4', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_VALUE', 'Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS18', 'SQUERY_NASTR_OPTIONAL', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_CAPTION', 'Группировать в разрезе КБК', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_NUMPARAM', '5', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_SQLPARAM', '@nCheck5', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_VALUE', 'Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS19', 'SQUERY_NASTR_OPTIONAL', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'EDITABLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'SQUERY_NASTR_NON_VISIBLE', '0', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'FORMAT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_CAPTION', 'Выводить остатки', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_CONTROL', 'CHECKBOX', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_NOTE', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_NUMPARAM', '6', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_SAVE', '1', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_SOURCE', 'Выкл.,Вкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_SQLPARAM', '@nCheck6', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_SQLTYPE', 'int', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_VALUE', 'Выкл.', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'QUERY_NASTR_VALUE_TEXT', '', 0
GO
EXEC dbo.KIR_OBJECT_VAR_SET_VALUE 'SQL_REP_VM1_NAS20', 'SQUERY_NASTR_OPTIONAL', '0', 0
GO



GO
-- Отчет "Аналитическая таблица по гос. гражд. служащим  (ф.7)"
-- Сгенерировано скриптом scriptObjectVar 'REP_ANALIT_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_ANALIT_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_ANALIT_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Аналитическая таблица по гос. гражд. служащим  (ф.7)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_ANALIT_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_ANALIT_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_ANALIT_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_ANALIT_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_ANALIT_GOS_SLUSH
	@dDate1 datetime	/* Дата отчета */
AS
BEGIN

exec REP_ANALIT_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ANALIT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH'),
		'REP_ANALIT_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_ANALIT_GOS_SLUSH_N1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Дата отчета',2, 
					(Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_GROUP'),
					'REP_ANALIT_GOS_SLUSH_N1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Дата отчета'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ANALIT_GOS_SLUSH_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Аналитическая таблица по гос. гражд. служащим  (ф.7)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_ANALIT_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_ANALIT_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_ANALIT_GOS_SLUSH', 'Аналитическая таблица по гос. гражд. служащим  (ф.7)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Результаты аттестации гражданских служащих (ф.6)"
-- Сгенерировано скриптом scriptObjectVar 'REP_ATT_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_ATT_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_ATT_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Результаты аттестации гражданских служащих (ф.6)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_ATT_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_RES_ATT_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_ATT_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_RES_ATT_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_ATT_GOS_SLUSH
	@dDate1 datetime	/* Расчетная дата */
AS
BEGIN

exec REP_RES_ATT_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_ATT_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_ATT_GOS_SLUSH'),
		'REP_ATT_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_ATT_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Расчетная дата',2, 
					(Select link from object_var where code = 'REP_ATT_GOS_SLUSH_GROUP'),
					'REP_ATT_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_ATT_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Результаты аттестации гражданских служащих (ф.6)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_ATT_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_ATT_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_ATT_GOS_SLUSH', 'Результаты аттестации гражданских служащих (ф.6)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Реестр госуд.гражд.служащих (ф.8)"
-- Сгенерировано скриптом scriptObjectVar 'REP_REESTR_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_REESTR_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_REESTR_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Реестр госуд.гражд.служащих (ф.8)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_REESTR_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_REESTR_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_REESTR_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKERMULTISHEET.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_REESTR_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_REESTR_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_REESTR_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REESTR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepReestrGS.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH'),
		'REP_REESTR_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_GROUP'),
					'REP_REESTR_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2014'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REESTR_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_GROUP'),
					'REP_REESTR_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'год'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REESTR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Реестр госуд.гражд.служащих (ф.8)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_REESTR_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_REESTR_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_REESTR_GOS_SLUSH', 'Реестр госуд.гражд.служащих (ф.8)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Сведения о замещении должностей гос. гражд. службы (ф.3)"
-- Сгенерировано скриптом scriptObjectVar 'REP_REPL_KADR_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_REPL_KADR_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о замещении должностей гос. гражд. службы (ф.3)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_REPL_KADR_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_REPL_KADR_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_REPL_KADR_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_REPL_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_REPL_KADR_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_REPL_KADR_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_REPL_KADR_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH'),
		'REP_REPL_KADR_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_GROUP'),
					'REP_REPL_KADR_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_GROUP'),
					'REP_REPL_KADR_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_REPL_KADR_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о замещении должностей гос. гражд. службы (ф.3)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_REPL_KADR_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_REPL_KADR_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_REPL_KADR_GOS_SLUSH', 'Сведения о замещении должностей гос. гражд. службы (ф.3)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Сведения о государственных гражданских служащих (ф.1)"
-- Сгенерировано скриптом scriptObjectVar 'REP_SVED_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_SVED_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_SVED_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о государственных гражданских служащих (ф.1)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_SVED_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec SVED_GOS_SLUSH @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_SVED_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_SVED_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_SVED_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec SVED_GOS_SLUSH @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_SVED_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_SVED_GOS_SLUSH'),
		'REP_SVED_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_SVED_GOS_SLUSH_GROUP'),
					'REP_SVED_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'

						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_SVED_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_SVED_GOS_SLUSH_GROUP'),
					'REP_SVED_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'1 полугодие'

GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_SVED_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Постановление №389-РГ"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = NULL

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_TREE_ROOT')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_TREE_ROOT'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'),0)

IF COALESCE(@LINK_SELF,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'KADRY_POST_389', 'Постановление №389-РГ', @ORD, NULL, 1, @LINK_SELF, 'FOLDER', NULL, @LINK_VAR, 3
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о государственных гражданских служащих (ф.1)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_SVED_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_SVED_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_SVED_GOS_SLUSH', 'Сведения о государственных гражданских служащих (ф.1)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Сведения о временно отсутствующих гос. гражд. служащих (ф.2)"
-- Сгенерировано скриптом scriptObjectVar 'REP_TMP_OTS_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_TMP_OTS_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Сведения о временно отсутствующих гос. гражд. служащих (ф.2)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_TMP_OTS_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_TMP_OTS_GS @dDate1, @dDate2'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_TMP_OTS_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_TMP_OTS_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_TMP_OTS_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_TMP_OTS_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_TMP_OTS_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH'),
		'REP_TMP_OTS_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_GROUP'),
					'REP_TMP_OTS_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_GROUP'),
					'REP_TMP_OTS_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_TMP_OTS_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Сведения о временно отсутствующих гос. гражд. служащих (ф.2)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_TMP_OTS_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_TMP_OTS_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_TMP_OTS_GOS_SLUSH', 'Сведения о временно отсутствующих гос. гражд. служащих (ф.2)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Список уволенных за отчетный период (ф.4)"
-- Сгенерировано скриптом scriptObjectVar 'REP_UVOL_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_UVOL_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_UVOL_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Список уволенных за отчетный период (ф.4)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_UVOL_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_UVOL_GS @cYear1, @nCombo1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_UVOL_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_UVOL_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_UVOL_GOS_SLUSH
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nCombo1 int	/* Вывод сведений */
AS
BEGIN

exec REP_UVOL_GS @cYear1, @nCombo1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_UVOL_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH'),
		'REP_UVOL_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',2, 
					(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_GROUP'),
					'REP_UVOL_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_UVOL_GOS_SLUSH_PARAM2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Вывод сведений',3, 
					(Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_GROUP'),
					'REP_UVOL_GOS_SLUSH_PARAM2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Сведения за:'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'1 полугодие,год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_UVOL_GOS_SLUSH_PARAM2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Список уволенных за отчетный период (ф.4)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_UVOL_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_UVOL_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_UVOL_GOS_SLUSH', 'Список уволенных за отчетный период (ф.4)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
-- Отчет "Информация о вакантных должностях гражд. службы (ф.5)"
-- Сгенерировано скриптом scriptObjectVar 'REP_VAC_POST_GOS_SLUSH'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'REP_VAC_POST_GOS_SLUSH'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'REP_VAC_POST_GOS_SLUSH'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Информация о вакантных должностях гражд. службы (ф.5)',401, 
	(Select link from object_var where code = 'KADRY_SQL_CATALOG'),
	'REP_VAC_POST_GOS_SLUSH',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'exec REP_VAC_POST_GS @dDate1'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REP_VAC_POST_GOS_SLUSH'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"REP_VAC_POST_GS.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REP_VAC_POST_GOS_SLUSH
	@dDate1 datetime	/* Расчетная дата */
AS
BEGIN

exec REP_VAC_POST_GS @dDate1

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'REP_VAC_POST_GOS_SLUSH'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KirRepCommon.bas'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH_GROUP' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',1, 
		(Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH'),
		'REP_VAC_POST_GOS_SLUSH_GROUP',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'REP_VAC_POST_GOS_SLUSH_PARAM1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX'),
					'Расчетная дата',2, 
					(Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_GROUP'),
					'REP_VAC_POST_GOS_SLUSH_PARAM1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетная дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDate1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Текущая дата'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'REP_VAC_POST_GOS_SLUSH_PARAM1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO

/**************** ДОБАВЛЕНИЕ В НАВИГАТОР ОБЪЕКТА "Информация о вакантных должностях гражд. службы (ф.5)"*************/ 
 
DECLARE @LINK_VAR INT
SET @LINK_VAR = (SELECT LINK FROM OBJECT_VAR WHERE CODE = 'REP_VAC_POST_GOS_SLUSH')

DECLARE @LINK_SELF INT 
SET @LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389')

DECLARE @OBJECT INT
SET @OBJECT = (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'QUERY_SQL')

DECLARE @ORD INT, @LINK_SNAVIGATOR INT
SET @ORD = (SELECT COALESCE(MAX(ORDERS),0) + 1 FROM DBO.S_NAVIGATOR WHERE LINK_SELF = (SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'KADRY_POST_389'))
SET @LINK_SNAVIGATOR = COALESCE((SELECT LINK FROM DBO.S_NAVIGATOR WHERE CODE = 'NV_REP_VAC_POST_GOS_SLUSH'),0)

IF COALESCE(@LINK_SELF,0) > 0  AND COALESCE(@OBJECT,0) > 0  
 		EXEC DBO.W_ESN_UPDATEDOCUMENT @LINK_SNAVIGATOR, 'NV_REP_VAC_POST_GOS_SLUSH', 'Информация о вакантных должностях гражд. службы (ф.5)', @ORD, NULL, 1, @LINK_SELF, 'REPORT_QUERY', @OBJECT, @LINK_VAR, 3
GO

GO
--- Вычеты и МРОТ
declare @PERIOD datetime

SET @PERIOD = coalesce((select Max(PERIOD) from minrot),'20000101')
IF @PERIOD < '20150101'
BEGIN
	declare @P1 int, @LINK_DED INT
				
	DECLARE @Object int, @LinkDep int
	SELECT @Object = LINK FROM dbo.S_OBJECTS WHERE CODE = 'COLUMN_REF_PAY_MROT_T1'
	SELECT @LinkDep = LINK FROM dbo.DICTIONARY_DEPARTMENT WHERE TYPE = 4
	
	Declare @nRKoef numeric(18,2), @KOEF_BL numeric(18,2), @TARIF numeric(18,2), @MROT1 numeric(18,2)
	/*прежние значения*/
	select top 1 @MROT1 =MROT1, @TARIF = TARIF, @nRKoef = KOEF, @KOEF_BL = KOEF_BL from dbo.MINROT order by PERIOD desc

	Select @MROT1 = COALESCE(@MROT1,100), @TARIF = COALESCE(@TARIF,2300), @nRKoef = COALESCE(@nRKoef,1), @KOEF_BL = COALESCE(@KOEF_BL,1)

	set @P1 = 0
	exec SALARY_SAVE_DICTIONARY_MROT @P1 output, 
			/*начало периода*/'20150101', 
			/*МРОТ общий*/@MROT1, 
			/*МРОТ для зарплаты*/5965, 
			/*Ставка первого разряда*/@TARIF, 
			/*Районный коэффициент*/@nRKoef, 
			/*Районный коэффициент для Б/Л*/@KOEF_BL, 
					@LinkDep

	IF COALESCE(@Object,0) > 0 AND COALESCE(@P1,0) > 0 BEGIN
		-- Заполняем первую вкладку
		
		SELECT TOP 1  @LINK_DED = LINK   FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '104'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,500)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '105'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,3000)
	--
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '114'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,1400)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '115'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,1400)
			
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '116'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,3000)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '117'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,3000)
	--
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '118'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,2800)
		
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '119'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,2800)
			
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '120'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,6000)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '121'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,6000)			
	--
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '122'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,2800)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '123'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,2800)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '124'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,6000)

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '125'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,280000,6000)									

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '313'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,2000000)				

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '501'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,4000)				

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '502'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,4000)				

		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '503'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,0,4000)				
	
		SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '602'
		IF COALESCE(@LINK_DED,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P1,@LINK_DED,@Object,12000,0)	


	END

	-- Заполняем вторую вкладку
	SELECT TOP 1  @LINK_DED = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '503'
	IF COALESCE(@P1,0) > 0 AND COALESCE(@LINK_DED,0) > 0 
		EXEC SALARY_SAVE_DICTIONARY_MROT_TABLE2 @P1, @LINK_DED, 4000


	
	-- Заполняем третью вкладку
	
	DECLARE @FSS12 int

	SELECT TOP 1 @FSS12 = LINK FROM PAYS WHERE OBJECT = 3 AND WAY_CALC = 5

	IF COALESCE(@P1,0) > 0 BEGIN
		IF COALESCE(@FSS12,0) > 0
			exec SALARY_SAVE_DICTIONARY_MROT_TABLE3 @P1, @FSS12, 0, 0.12
	END


END   

IF @PERIOD = '20150101'
BEGIN

	declare @P2 int, @LINK_DED1 INT
	DECLARE @Object1 int
	SELECT @Object1 = LINK FROM dbo.S_OBJECTS WHERE CODE = 'COLUMN_REF_PAY_MROT_T1'


	SET @P2 = (select TOP 1 link from minrot where period = @PERIOD)
	
	IF COALESCE(@Object1,0) > 0 AND COALESCE(@P2,0) > 0 BEGIN
		-- Заполняем первую вкладку

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '104'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 500 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '105'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 3000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

	--
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '114'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 1400 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '115'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 1400 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1
			
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '116'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 3000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '117'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 3000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

	--
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '118'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 2800 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '119'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 2800 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1
			
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '120'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 6000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '121'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 6000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1
	
	--
		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '122'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 2800 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '123'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 2800 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '124'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 6000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '125'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 6000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '313'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 2000000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '501'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 4000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '502'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 4000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '503'
		IF COALESCE(@LINK_DED1,0) > 0 
		Update m
			set SUMMA = 4000 
		from MINROT_DICTION  m  where LINK_MINROT = @P2 and LINK_DICTION = @LINK_DED1 and OBJECT = @Object1		

		SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '602'
		IF COALESCE(@LINK_DED1,0) > 0 
		BEGIN 
			IF exists (select * from MINROT_DICTION where LINK_DICTION = @LINK_DED1 and LINK_MINROT = @p2)
			DELETE FROM MINROT_DICTION WHERE LINK_DICTION = @LINK_DED1 and LINK_MINROT = @p2

			SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '602'
			IF COALESCE(@LINK_DED1,0) > 0 
			INSERT INTO MINROT_DICTION (LINK_MINROT,LINK_DICTION,OBJECT,PREDEL,SUMMA)
			VALUES(@P2,@LINK_DED1,@Object1,12000,0)	
		END
	END

	-- Заполняем вторую вкладку
	SELECT TOP 1  @LINK_DED1 = LINK FROM  dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '503'
	IF COALESCE(@P2,0) > 0 AND COALESCE(@LINK_DED1,0) > 0 
		EXEC SALARY_SAVE_DICTIONARY_MROT_TABLE2 @P2, @LINK_DED1, 4000
	-- Заполняем третью вкладку
	
	DECLARE @FSS12_1 int

	SELECT TOP 1 @FSS12_1 = LINK FROM PAYS WHERE OBJECT = 3 AND WAY_CALC = 5

	IF COALESCE(@P2,0) > 0 BEGIN
		IF COALESCE(@FSS12_1,0) > 0
			exec SALARY_SAVE_DICTIONARY_MROT_TABLE3 @P2, @FSS12_1, 0, 0.12
	END

END

GO
GO

---- Установка видов страховых взносов
DECLARE @LINK_OBJ INT
SET @LINK_OBJ = (SELECT TOP 1 LINK FROM dbo.S_OBJECTS SO WHERE SO.CODE = 'COLUMN_REF_PAY_MROT_T4')

if exists (SELECT * FROM MINROT_PAYS WHERE  [OBJECT] = @LINK_OBJ AND link_minrot IN (SELECT LINK FROM  dbo.MINROT WHERE PERIOD >= '20150101' AND   PERIOD < '20990101'))
DELETE FROM MINROT_PAYS WHERE  [OBJECT] = @LINK_OBJ AND link_minrot IN (SELECT LINK FROM  dbo.MINROT 
                                                                               WHERE PERIOD >= '20150101'
                                                                               AND   PERIOD < '20990101')
GO

DECLARE @LINK_OBJ INT
SET @LINK_OBJ = (SELECT TOP 1 LINK FROM dbo.S_OBJECTS SO WHERE SO.CODE = 'COLUMN_REF_PAY_MROT_T4')

INSERT INTO dbo.MINROT_PAYS (LINK_MINROT, LINK_PAYS, OBJECT)
SELECT M.LINK, P.LINK, @LINK_OBJ 
FROM dbo.MINROT M INNER JOIN dbo.PAYS P ON 1=1
WHERE 
	M.PERIOD >= '20150101'
	AND
	M.PERIOD < '20990101'
	AND
	P.[OBJECT] = 3 AND P.WAY_CALC IN (2,3, 6)
	AND
	NOT EXISTS (SELECT * FROM dbo.DICTIONARY_MROT_TABLE4 T4 WHERE T4.LINK_MINROT = M.LINK AND T4.REF_PAY = P.LINK)
ORDER BY
	M.LINK, P.LINK
GO


DECLARE @LINK_OBJ INT
SET @LINK_OBJ = (SELECT TOP 1 LINK FROM dbo.S_OBJECTS SO WHERE SO.CODE = 'COLUMN_REF_PAY_MROT_T4')

INSERT INTO dbo.MINROT_PAYS (LINK_MINROT, LINK_PAYS, OBJECT)
SELECT M.LINK, P.LINK, @LINK_OBJ 
FROM dbo.MINROT M INNER JOIN dbo.PAYS P ON 1=1
WHERE 
	M.PERIOD >= '20150101'
	AND
	M.PERIOD < '20990101'
	AND
	P.[OBJECT] = 3 AND P.WAY_CALC IN (10, 11)
	AND
	NOT EXISTS (SELECT * FROM dbo.DICTIONARY_MROT_TABLE4 T4 WHERE T4.LINK_MINROT = M.LINK AND T4.REF_PAY = P.LINK)
ORDER BY
	M.LINK, P.LINK
		
GO



GO

--Обновление настроек 2015 года
exec dbo.SA_SET_STATIC_NASTR '2015'
GO


/*Формирование всех используемых графиков на 2015 год*/
DECLARE @Cur1 CURSOR, @LinkGrophik int, @VID_LINK int, @NAME_GR varchar(254)
DECLARE @Cur2 CURSOR, @DAY tinyint, @HOUR numeric(18,2), @TD_LINK int

DECLARE @MONTH INT, @YEAR INT
DECLARE @LINK INT, @LINK2 INT, @gDayNorm INT, @gHourNorm numeric(18,2)

DECLARE @ISMINUTES TINYINT
SET @ISMINUTES = DBO.SA_GET_OPTION_BY_CODE('TABEL_OPT10') --УЧЕТ ВРЕМЕНИ В ЧАСАХ И МИНУТАХ

SET @Cur1 = CURSOR FORWARD_ONLY

FOR select LINK, VID_LINK, [NAME] from GRAPH order by link
OPEN @Cur1
FETCH NEXT FROM @Cur1 INTO @LinkGrophik, @VID_LINK, @NAME_GR
WHILE (@@fetch_status <> -1)
BEGIN
	IF (@@fetch_status <> -2)
	BEGIN

		SELECT @YEAR = 2015, @MONTH = 1
		WHILE @MONTH <= 12
		BEGIN

			IF NOT EXISTS(SELECT @LinkGrophik FROM dbo.KD_GRAPH_TABLE WHERE [YEAR] = @YEAR AND [MONTH] = @MONTH AND LINK_GR = @LinkGrophik)
			BEGIN
				IF object_id('tempdb..#sa_tmp_graph') is not null
				drop table #sa_tmp_graph
				
				CREATE TABLE #sa_tmp_graph(CHECKED tinyint, UPD tinyint, DEL tinyint, [DAY] tinyint, [HOUR] numeric(18,2), TD_LINK int, TD_CODE varchar(10),
						TD_NAME varchar(254), PRIORITET tinyint )
				
				INSERT INTO #sa_tmp_graph(CHECKED, UPD, DEL, [DAY], [HOUR], TD_LINK, TD_CODE, TD_NAME, PRIORITET)
				exec dbo.KD_GRAPH_FILL @VID_LINK, @MONTH, @YEAR
				
				Select @gHourNorm = DBO.MINUTES_TO_NUM(SUM(DBO.NUM_TO_MINUTES([HOUR],@ISMINUTES)),@ISMINUTES) from #sa_tmp_graph where [HOUR] > 0
				Select @gDayNorm = COUNT(DISTINCT [DAY]) from #sa_tmp_graph where [HOUR] > 0
				
				IF COALESCE(@gHourNorm,0) > 0 AND coalesce(@gDayNorm,0) > 0
				BEGIN
				
					EXEC dbo.KD_GRAPH_SAVE @LinkGrophik OUT, @LINK2 OUT, @NAME_GR, @MONTH, @YEAR, @VID_LINK, @gDayNorm, @gHourNorm
		
					SET @Cur2 = CURSOR FORWARD_ONLY
					
					FOR select [DAY], [HOUR], [TD_LINK] from #sa_tmp_graph order by [DAY]
					OPEN @Cur2
					FETCH NEXT FROM @Cur2 INTO @DAY, @HOUR, @TD_LINK
					WHILE (@@fetch_status <> -1)
					BEGIN
						IF (@@fetch_status <> -2)
						BEGIN
							exec dbo.KD_GRAPH_TABLE_SAVE @LINK2, @DAY, @HOUR, @TD_LINK
						END
					
						FETCH NEXT FROM @Cur2 INTO @DAY, @HOUR, @TD_LINK
					END
					
					CLOSE @Cur2
					DEALLOCATE @Cur2
				END
			END

			Set @MONTH = @MONTH + 1
		END
		
	END
	FETCH NEXT FROM @Cur1 INTO @LinkGrophik, @VID_LINK, @NAME_GR
END

CLOSE @Cur1
DEALLOCATE @Cur1
GO




/*НАСТРОЙКИ ТАРИФОВ  2015 ГОДА*/


--Общий (НР)
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 2 --Фонд Социального Страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 670000 AND TARIF = 1),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',670000, 2.9, 1

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',999999999, 0, 1
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 3 --Федеральный фонд медицинского страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФФОМС',999999999, 5.1, 1
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 6 --ПФ Страховая часть
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 1),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',711000, 22, 22, 22, 1

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',999999999, 10, 10, 10, 1
GO


--- солидарную часть убераем
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 8 --ПФ Солидарная часть
IF EXISTS (select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 1)
DELETE  FROM dbo.stavki_pf WHERE link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 1

IF EXISTS (select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1)
DELETE  FROM dbo.stavki_pf WHERE link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1
GO

--- Индивидуальную часть убераем
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 9 --ПФ Индивидуальная часть
IF exists(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 1)
DELETE  FROM dbo.stavki_pf WHERE link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 1

IF exists(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20140101' and predel = 999999999 AND TARIF = 1)
DELETE  FROM dbo.stavki_pf WHERE link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1
GO


DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №1',999999999,  9, 9, 9, 1
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №2',999999999, 6, 6, 6, 1
GO

--Инвалиды (ОЗОИ)
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 2 --Фонд Социального Страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 670000 AND TARIF = 3),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',670000, 2.4, 3

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',999999999, 0, 3
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 3 --Федеральный фонд медицинского страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФФОМС',999999999, 3.7, 3
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 6 --ПФ Страховая часть
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 3),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',711000, 21, 21, 21, 3

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',999999999, 0, 0, 0, 3
GO

--ПФ Солидарная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 8 --ПФ Солидарная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 3)							/* 415000  */
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 3

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3)
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3
GO

--ПФ Индивидуальная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 9 --ПФ Индивидуальная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 3)								/* 415000  */
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 3

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3)
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №1',999999999,  9, 9, 9, 3
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №2',999999999, 6, 6, 6, 3
GO




--Упрощён. (ПНЭД)
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 2 --Фонд Социального Страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 670000 AND TARIF = 2),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',670000, 2.9, 2

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',999999999, 0, 2
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 3 --Федеральный фонд медицинского страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФФОМС',999999999, 5.1, 2
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 6 --ПФ Страховая часть
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 2),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',711000, 21.6, 21.6, 21.6, 2

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',999999999, 10, 10, 10, 2
GO

-- --ПФ Солидарная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 8 --ПФ Солидарная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 2)								/* 415000  */
DELETE FROM dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 2

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2)
DELETE FROM dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2
GO

--ПФ Индивидуальная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 9 --ПФ Индивидуальная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF =2)								/* 415000  */
DELETE from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF =2

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2)
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2
GO


DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2  ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №1',999999999,  9, 9, 9, 2
GO


DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2  ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №2',999999999, 6, 6, 6, 2
GO


--СМИ. (СМИ)
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 2 --Фонд Социального Страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 670000 AND TARIF = 4),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',670000, 2.9, 4

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФСС РФ',999999999, 0, 4
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 3 --Федеральный фонд медицинского страхования
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI @p1 output,@link_pays,'20150101','ФФОМС',999999999, 3.9, 4
GO

DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 6 --ПФ Страховая часть
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 4),0)
exec dbo.SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',711000, 23.2, 23.2, 23.2, 4

SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Страховая часть',999999999, 0, 0,0, 4
GO

-- --ПФ Солидарная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 8 --ПФ Солидарная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 4)								/* 415000  */
DELETE FROM dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF = 4

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4)
DELETE FROM dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4
GO

--ПФ Индивидуальная часть УБИРАЕМ
DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 9 --ПФ Индивидуальная часть
IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF =4)								/* 415000  */
DELETE from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 711000 AND TARIF =4

IF EXISTS(select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4)
delete from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4
GO


DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4  ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №1',999999999,  9, 9, 9, 4
GO


DECLARE @link_pays int, @p1 INT
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4  ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','ПФ Доп.тариф №2',999999999, 6, 6, 6, 4
GO



/*НАСТРОЙКИ ДОП ТАРИФОВ  2015 ГОДА Со спец оценкой*/

------------------------<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
--Общий (НР)
----------------------------
DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  8, 8, 8, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  7, 7, 7, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  6, 6, 6, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  4, 4, 4, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  2, 2, 2, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 8, 8, 8, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999,  7, 7, 7, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 6, 6, 6, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 4, 4, 4, 1,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 1 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999,  2, 2, 2, 1,@specO
GO
---------------------------------------
--Инвалиды (ОЗОИ)
---------------------------------------
DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  8, 8, 8, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  7, 7, 7, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  6, 6, 6, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  4, 4, 4, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10 -- Дополнительный тариф страхового взноса в ПФ 1 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  2, 2, 2, 3,@specO
GO


DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 8, 8, 8, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 7, 7, 7, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 6, 6, 6, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 4, 4, 4, 3,@specO
GO

DECLARE @link_pays int, @p1 INT,@specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11 --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 3 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 2, 2, 2, 3,@specO
GO
---------------------------------
--Упрощён. (ПНЭД)
----------------------------------
DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  8, 8, 8, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  7, 7, 7, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  6, 6, 6, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  4, 4, 4, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  2, 2, 2, 2,@specO
GO



DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 8, 8, 8, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 7, 7, 7, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 6, 6, 6, 2,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 4, 4, 4, 2,@specO
GO

DECLARE @link_pays int, @p1 INT , @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 2 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 2, 2, 2, 2, @specO
GO


---------------------------------
--СМИ. (СМИ)
----------------------------------
DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  8, 8, 8, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  7, 7, 7, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  6, 6, 6, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  4, 4, 4, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 10  -- Дополнительный тариф страхового взноса в ПФ 1  со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №1',999999999,  2, 2, 2, 4,@specO
GO



DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "О4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'О4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 8, 8, 8, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.4"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.4'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 7, 7, 7, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.3"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.3'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 6, 6, 6, 4,@specO
GO

DECLARE @link_pays int, @p1 INT, @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.2"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.2'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 4, 4, 4, 4,@specO
GO

DECLARE @link_pays int, @p1 INT , @specO INT 
SELECT TOP 1 @link_pays = LINK, @p1 = 0 FROM dbo.PAYS WHERE OBJECT = 3 AND WAY_CALC = 11  --Дополнительный тариф страхового взноса в ПФ 2 со спецоценкой "В3.1"
SELECT @specO = link FROM SA_SZV4_SPR WHERE spr_code = 'SPO_USL_TRUDA' AND CODE = 'В3.1'
SET @p1 = ISNULL((select TOP 1 LINK from dbo.stavki_pf where link_pays = @link_pays and date = '20150101' and predel = 999999999 AND TARIF = 4 AND SpecO = @specO ),0)
exec SALARY_SAVE_DICTIONARY_STAVKI_PF @p1 output,@link_pays,'20150101','Доп.тариф ПФ по списку №2',999999999, 2, 2, 2, 4, @specO
GO

GO
-------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>





--
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '201')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'201',
--	'Расходы по операциям с ценными бумагами, обращающимися на организованном рынке ценных бумаг',
--	'201', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '202')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'202',
--	'Расходы по операциям с ценными бумагами, не обращающимися на организованном рынке ценных бумаг',
--	'202', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '203')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'203',
--	'Расходы по операциям с ценными бумагами, не обращающимися на организованном рынке ценных бумаг, которые на момент их приобретения относились к ценным бумагам, обращающимся на организованном рынке ценных бумаг',
--	'203', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '204')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'204',
--	'Сумма убытка по операциям с ценными бумагами, не обращающимися на организованном рынке ценных бумаг',
--	'204', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '205')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'205',
--	'Сумма убытка по операциям с ценными бумагами, обращающимися на организованном рынке ценных бумаг',
--	'205', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '206')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'206',
--	'Расходы по операциям с финансовыми инструментами срочных сделок, которые обращаются на организованном рынке и базисным активом которых являются ценные бумаги и т.д.',
--	'206', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '207')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'207',
--	'Расходы по операциям с финансовыми инструментами срочных сделок, которые обращаются на организованном рынке и базисным активом которых не являются ценные бумаги  т.д.',
--	'207', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '208')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'208',
--	'Сумма убытка (уменьшающая налоговую базу по операциям с ценными бумагами) по операциям с финансовыми инструментами срочных сделок, которые обращаются на организованном рынке и базисным активом которых являются ценные бумаги и т.д.',
--	'208', 3, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '209')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'209',
--	'Сумма убытка (уменьшающая налоговую базу по операциям с финансовыми инструментами срочных сделок) по операциям с финансовыми инструментами срочных сделок, которые обращаются на организованном рынке и базисным активом которых не являются ценные бумаги и т.д.',
--	'209', 3, 0
--GO

----
--DECLARE @LINK INT
--SET @LINK = (SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '311')
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'311',
--	'Расходы на новое строительство и приобретение жилья',
--	'311', 4, 0
--GO

----
--DECLARE @LINK INT
--SET @LINK = ISNULL((SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '318'),0)
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'318',
--	'Сумма, направленная на погашение процентов по кредитам, полученным от банков в целях рефинансирования (перекредитования) кредитов',
--	'318', 4, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = ISNULL((SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '319'),0)
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'319',
--	'Сумма уплаченных налогоплательщиком пенсионных взносов по договору негосударственного  пенсионного обеспечения и (или) страховых взносов по договору добровольного пенсионного страхования',
--	'319', 10, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = ISNULL((SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '509'),0)
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'509',
--	'Вычет из суммы доходов, полученных работниками в натуральной форме в качестве оплаты труда от сельскохозяйственных товаропроизводителей',
--	'509', 6, 0
--GO
----
--DECLARE @LINK INT
--SET @LINK = ISNULL((SELECT TOP 1 LINK FROM dbo.DICTIONARY_TYP_DEDUCTION WHERE SNAME = '607'),0)
--exec dbo.X_SAVE_DICTIONARY_TYP_DEDUCTION 
--	@LINK,'607',
--	'Вычет в сумме уплаченных работодателем страховых взносов за работника на накопительную часть трудовой пенсии',
--	'607', 9, 0
--GO

GO
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Добавление системной счетов в план счетов
--Сгенерировано скриптом: EXECUTE [dbo].UNLOAD_S_ACCOUNTS 

set xact_abort ON
BEGIN TRAN



IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS

CREATE TABLE #TMP_S_ACCOUNTS (
	[LINK] int ,
	[NAME] varchar(150) NOT NULL ,
	[KSU] tinyint NOT NULL ,
	[LINK_SELF] int NULL ,
	[CODE_SELF] VARCHAR(50),
	[ORDERS] smallint NOT NULL ,
	[ZABALANS] tinyint NOT NULL ,
	[s_active] tinyint NOT NULL ,
	[s_passive] tinyint NOT NULL ,
	[s_packed] tinyint NOT NULL ,
	[s_kassa] tinyint NOT NULL ,
	[p_DVZ] tinyint NOT NULL ,
	[ap_KBK] tinyint NOT NULL ,
	[ap_EKR] tinyint NOT NULL ,
	[ap_DEP] tinyint NOT NULL ,
	[ap_SUB] tinyint NOT NULL ,
	[ap_EMP] tinyint NOT NULL ,
	[ap_NOMEN] tinyint NOT NULL ,
	[ap_INV] tinyint NOT NULL ,
	[ap_KAU] tinyint NOT NULL ,
	[ap_DEP_ACC] tinyint NOT NULL ,
	[ap_TMC] tinyint NOT NULL ,
	[ap_INDATE] tinyint NOT NULL ,
	[ap_AP1] tinyint NOT NULL ,
	[ap_AP2] tinyint NOT NULL ,
	[ap_AP3] tinyint NULL ,
	[p_NOCONTROL] tinyint NOT NULL ,
	[cSource] char(1) NOT NULL ,
	[cSinth] char(3) NOT NULL ,
	[cAnalit] char(2) NOT NULL ,
	[cUser] varchar(4) NOT NULL ,
	[p_UZAB] tinyint NOT NULL ,
	[KBK_TYPE] tinyint NOT NULL ,
	[CODE] VARCHAR(50),
	[p_EKR] tinyint NOT NULL ,
	[ANALIT_EKR] int NULL ,
	[p_KASSA] tinyint NOT NULL ,
	[NOMEN_TYPE] tinyint NOT NULL ,
	[p_DATE] tinyint NOT NULL ,
	[OB_KBK] tinyint NOT NULL ,
	[OB_EKR] tinyint NOT NULL ,
	[OB_DEP] tinyint NOT NULL ,
	[OB_SUB] tinyint NOT NULL ,
	[OB_EMP] tinyint NOT NULL ,
	[OB_NOMEN] tinyint NOT NULL ,
	[OB_INV] tinyint NOT NULL ,
	[OB_KAU] tinyint NOT NULL ,
	[OB_DEP_ACC] tinyint NOT NULL ,
	[OB_TMC] tinyint NOT NULL ,
	[OB_AP1] tinyint NOT NULL ,
	[OB_AP2] tinyint NOT NULL ,
	[OB_AP3] tinyint NOT NULL ,
	[B_YEAR0] tinyint NOT NULL ,
	[BUH_TYPE] tinyint NOT NULL ,
	[ISUSED] tinyint NOT NULL 
	)
GO
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4197,'Расчеты по компенсации затрат',0,1229,'209',2,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'','209','30','',0,2,'209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4198,'Расчеты по компенсации затрат',0,4197,'209.30',1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'1','209','30','',0,2,'1.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4199,'Расчеты по компенсации затрат',0,4197,'209.30',2,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'2','209','30','',0,2,'2.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4200,'Расчеты по компенсации затрат',0,4197,'209.30',3,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'4','209','30','',0,2,'4.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4201,'Расчеты по компенсации затрат',0,4197,'209.30',4,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'5','209','30','',0,2,'5.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4202,'Расчеты по компенсации затрат',0,4197,'209.30',5,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'6','209','30','',0,2,'6.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4203,'Расчеты по компенсации затрат',0,4197,'209.30',6,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'7','209','30','',0,2,'7.209.30',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_KAU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_KAU

CREATE TABLE #TMP_S_ACCOUNTS_KAU (
	[ACCOUNT] INT,
	[KAU] varchar(50)
)
GO
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_JOURNAL_OPERATION_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS

CREATE TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS (
	[ACCOUNT] INT,
	[JURN] varchar(50),
	[GK] bit
)
GO
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4198,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4199,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4197,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4200,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4201,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4202,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4203,'05',0)
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_SGU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_SGU

CREATE TABLE #TMP_S_ACCOUNTS_SGU (
	[ACCOUNT] INT,
	[SGU] varchar(50),
	[COMMENT] varchar(254)
)
GO
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4198,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4198,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4199,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4199,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4197,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4197,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4200,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4200,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4201,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4201,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4202,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4202,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4203,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4203,'660','')
GO

---- Обновление данных
IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

ALTER TABLE dbo.S_ACCOUNTS ADD INSERTED_LINK INT NULL
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[_INSERTED_S_ACCOUNTS] (
	LINK int ,
	INSERTED_LINK int )
ELSE 
	DELETE FROM dbo._INSERTED_S_ACCOUNTS
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS] ([LINK]) ON [INDEX]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS] ([INSERTED_LINK]) ON [INDEX]
GO

INSERT INTO dbo.S_ACCOUNTS (INSERTED_LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED)
OUTPUT INSERTED.LINK, INSERTED.INSERTED_LINK INTO [dbo].[_INSERTED_S_ACCOUNTS] (LINK, INSERTED_LINK)
SELECT LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED
FROM #TMP_S_ACCOUNTS T
WHERE NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS SA WHERE SA.CODE = T.CODE)


UPDATE SA SET 
	SA.LINK_SELF = (SELECT TOP 1 LINK FROM dbo.S_ACCOUNTS WHERE CODE = T.CODE_SELF)
FROM
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = A.LINK
	INNER JOIN #TMP_S_ACCOUNTS T ON T.LINK = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_KAU(ACCOUNT,LINK_KAU)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KAU K WHERE K.CODE = T.KAU)
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_KAU T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.JOURNAL_OPERATION_ACCOUNTS(ACCOUNT,JURN_LINK,GK)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.JOURNAL_OPERATION K WHERE K.CODE = T.JURN),
	GK = T.GK
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_JOURNAL_OPERATION_ACCOUNTS T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_SGU(ACCOUNT,LINK_SGU,COMMENT)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KOSGU K WHERE K.CODE = T.SGU),
	COMMENT = T.COMMENT
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_SGU T ON T.ACCOUNT = A.INSERTED_LINK
GO

IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
DROP INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
DROP INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[_INSERTED_S_ACCOUNTS]
GO

COMMIT TRAN
GO


GO
--Добавление системной счетов в план счетов
--Сгенерировано скриптом: EXECUTE [dbo].UNLOAD_S_ACCOUNTS 

set xact_abort ON
BEGIN TRAN



IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS

CREATE TABLE #TMP_S_ACCOUNTS (
	[LINK] int ,
	[NAME] varchar(150) NOT NULL ,
	[KSU] tinyint NOT NULL ,
	[LINK_SELF] int NULL ,
	[CODE_SELF] VARCHAR(50),
	[ORDERS] smallint NOT NULL ,
	[ZABALANS] tinyint NOT NULL ,
	[s_active] tinyint NOT NULL ,
	[s_passive] tinyint NOT NULL ,
	[s_packed] tinyint NOT NULL ,
	[s_kassa] tinyint NOT NULL ,
	[p_DVZ] tinyint NOT NULL ,
	[ap_KBK] tinyint NOT NULL ,
	[ap_EKR] tinyint NOT NULL ,
	[ap_DEP] tinyint NOT NULL ,
	[ap_SUB] tinyint NOT NULL ,
	[ap_EMP] tinyint NOT NULL ,
	[ap_NOMEN] tinyint NOT NULL ,
	[ap_INV] tinyint NOT NULL ,
	[ap_KAU] tinyint NOT NULL ,
	[ap_DEP_ACC] tinyint NOT NULL ,
	[ap_TMC] tinyint NOT NULL ,
	[ap_INDATE] tinyint NOT NULL ,
	[ap_AP1] tinyint NOT NULL ,
	[ap_AP2] tinyint NOT NULL ,
	[ap_AP3] tinyint NULL ,
	[p_NOCONTROL] tinyint NOT NULL ,
	[cSource] char(1) NOT NULL ,
	[cSinth] char(3) NOT NULL ,
	[cAnalit] char(2) NOT NULL ,
	[cUser] varchar(4) NOT NULL ,
	[p_UZAB] tinyint NOT NULL ,
	[KBK_TYPE] tinyint NOT NULL ,
	[CODE] VARCHAR(50),
	[p_EKR] tinyint NOT NULL ,
	[ANALIT_EKR] int NULL ,
	[p_KASSA] tinyint NOT NULL ,
	[NOMEN_TYPE] tinyint NOT NULL ,
	[p_DATE] tinyint NOT NULL ,
	[OB_KBK] tinyint NOT NULL ,
	[OB_EKR] tinyint NOT NULL ,
	[OB_DEP] tinyint NOT NULL ,
	[OB_SUB] tinyint NOT NULL ,
	[OB_EMP] tinyint NOT NULL ,
	[OB_NOMEN] tinyint NOT NULL ,
	[OB_INV] tinyint NOT NULL ,
	[OB_KAU] tinyint NOT NULL ,
	[OB_DEP_ACC] tinyint NOT NULL ,
	[OB_TMC] tinyint NOT NULL ,
	[OB_AP1] tinyint NOT NULL ,
	[OB_AP2] tinyint NOT NULL ,
	[OB_AP3] tinyint NOT NULL ,
	[B_YEAR0] tinyint NOT NULL ,
	[BUH_TYPE] tinyint NOT NULL ,
	[ISUSED] tinyint NOT NULL 
	)
GO
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4204,'Расчеты по суммам принудительного изъятия',0,1229,'209',3,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'','209','40','',0,2,'209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4205,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'1','209','40','',0,2,'1.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4206,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',2,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'2','209','40','',0,2,'2.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4207,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',3,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'4','209','40','',0,2,'4.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4208,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',4,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'5','209','40','',0,2,'5.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4209,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',5,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'6','209','40','',0,2,'6.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4210,'Расчеты по суммам принудительного изъятия',0,4204,'209.40',6,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'7','209','40','',0,2,'7.209.40',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_KAU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_KAU

CREATE TABLE #TMP_S_ACCOUNTS_KAU (
	[ACCOUNT] INT,
	[KAU] varchar(50)
)
GO
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_JOURNAL_OPERATION_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS

CREATE TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS (
	[ACCOUNT] INT,
	[JURN] varchar(50),
	[GK] bit
)
GO
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4205,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4206,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4204,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4207,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4208,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4209,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4210,'05',0)
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_SGU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_SGU

CREATE TABLE #TMP_S_ACCOUNTS_SGU (
	[ACCOUNT] INT,
	[SGU] varchar(50),
	[COMMENT] varchar(254)
)
GO
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4205,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4205,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4206,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4206,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4204,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4204,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4207,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4207,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4208,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4208,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4209,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4209,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4210,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4210,'660','')
GO

---- Обновление данных
IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

ALTER TABLE dbo.S_ACCOUNTS ADD INSERTED_LINK INT NULL
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[_INSERTED_S_ACCOUNTS] (
	LINK int ,
	INSERTED_LINK int )
ELSE 
	DELETE FROM dbo._INSERTED_S_ACCOUNTS
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS] ([LINK]) ON [INDEX]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS] ([INSERTED_LINK]) ON [INDEX]
GO

INSERT INTO dbo.S_ACCOUNTS (INSERTED_LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED)
OUTPUT INSERTED.LINK, INSERTED.INSERTED_LINK INTO [dbo].[_INSERTED_S_ACCOUNTS] (LINK, INSERTED_LINK)
SELECT LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED
FROM #TMP_S_ACCOUNTS T
WHERE NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS SA WHERE SA.CODE = T.CODE)


UPDATE SA SET 
	SA.LINK_SELF = (SELECT TOP 1 LINK FROM dbo.S_ACCOUNTS WHERE CODE = T.CODE_SELF)
FROM
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = A.LINK
	INNER JOIN #TMP_S_ACCOUNTS T ON T.LINK = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_KAU(ACCOUNT,LINK_KAU)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KAU K WHERE K.CODE = T.KAU)
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_KAU T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.JOURNAL_OPERATION_ACCOUNTS(ACCOUNT,JURN_LINK,GK)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.JOURNAL_OPERATION K WHERE K.CODE = T.JURN),
	GK = T.GK
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_JOURNAL_OPERATION_ACCOUNTS T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_SGU(ACCOUNT,LINK_SGU,COMMENT)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KOSGU K WHERE K.CODE = T.SGU),
	COMMENT = T.COMMENT
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_SGU T ON T.ACCOUNT = A.INSERTED_LINK
GO

IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
DROP INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
DROP INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[_INSERTED_S_ACCOUNTS]
GO

COMMIT TRAN
GO


GO
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Добавление системной счетов в план счетов
--Сгенерировано скриптом: EXECUTE [dbo].UNLOAD_S_ACCOUNTS 

set xact_abort ON
BEGIN TRAN



IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS

CREATE TABLE #TMP_S_ACCOUNTS (
	[LINK] int ,
	[NAME] varchar(150) NOT NULL ,
	[KSU] tinyint NOT NULL ,
	[LINK_SELF] int NULL ,
	[CODE_SELF] VARCHAR(50),
	[ORDERS] smallint NOT NULL ,
	[ZABALANS] tinyint NOT NULL ,
	[s_active] tinyint NOT NULL ,
	[s_passive] tinyint NOT NULL ,
	[s_packed] tinyint NOT NULL ,
	[s_kassa] tinyint NOT NULL ,
	[p_DVZ] tinyint NOT NULL ,
	[ap_KBK] tinyint NOT NULL ,
	[ap_EKR] tinyint NOT NULL ,
	[ap_DEP] tinyint NOT NULL ,
	[ap_SUB] tinyint NOT NULL ,
	[ap_EMP] tinyint NOT NULL ,
	[ap_NOMEN] tinyint NOT NULL ,
	[ap_INV] tinyint NOT NULL ,
	[ap_KAU] tinyint NOT NULL ,
	[ap_DEP_ACC] tinyint NOT NULL ,
	[ap_TMC] tinyint NOT NULL ,
	[ap_INDATE] tinyint NOT NULL ,
	[ap_AP1] tinyint NOT NULL ,
	[ap_AP2] tinyint NOT NULL ,
	[ap_AP3] tinyint NULL ,
	[p_NOCONTROL] tinyint NOT NULL ,
	[cSource] char(1) NOT NULL ,
	[cSinth] char(3) NOT NULL ,
	[cAnalit] char(2) NOT NULL ,
	[cUser] varchar(4) NOT NULL ,
	[p_UZAB] tinyint NOT NULL ,
	[KBK_TYPE] tinyint NOT NULL ,
	[CODE] VARCHAR(50),
	[p_EKR] tinyint NOT NULL ,
	[ANALIT_EKR] int NULL ,
	[p_KASSA] tinyint NOT NULL ,
	[NOMEN_TYPE] tinyint NOT NULL ,
	[p_DATE] tinyint NOT NULL ,
	[OB_KBK] tinyint NOT NULL ,
	[OB_EKR] tinyint NOT NULL ,
	[OB_DEP] tinyint NOT NULL ,
	[OB_SUB] tinyint NOT NULL ,
	[OB_EMP] tinyint NOT NULL ,
	[OB_NOMEN] tinyint NOT NULL ,
	[OB_INV] tinyint NOT NULL ,
	[OB_KAU] tinyint NOT NULL ,
	[OB_DEP_ACC] tinyint NOT NULL ,
	[OB_TMC] tinyint NOT NULL ,
	[OB_AP1] tinyint NOT NULL ,
	[OB_AP2] tinyint NOT NULL ,
	[OB_AP3] tinyint NOT NULL ,
	[B_YEAR0] tinyint NOT NULL ,
	[BUH_TYPE] tinyint NOT NULL ,
	[ISUSED] tinyint NOT NULL 
	)
GO
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4211,'Расчеты по иным доходам',0,1229,'209',10,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'','209','83','',0,2,'209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4212,'Расчеты по иным доходам',0,4211,'209.83',1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'1','209','83','',0,2,'1.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4213,'Расчеты по иным доходам',0,4211,'209.83',2,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'2','209','83','',0,2,'2.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4214,'Расчеты по иным доходам',0,4211,'209.83',3,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'4','209','83','',0,2,'4.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4215,'Расчеты по иным доходам',0,4211,'209.83',4,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'5','209','83','',0,2,'5.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4216,'Расчеты по иным доходам',0,4211,'209.83',5,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'6','209','83','',0,2,'6.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
INSERT INTO #TMP_S_ACCOUNTS (LINK,NAME,KSU,LINK_SELF,CODE_SELF,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,CODE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED) 
VALUES(4217,'Расчеты по иным доходам',0,4211,'209.83',6,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,'7','209','83','',0,2,'7.209.83',0,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0)
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_KAU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_KAU

CREATE TABLE #TMP_S_ACCOUNTS_KAU (
	[ACCOUNT] INT,
	[KAU] varchar(50)
)
GO
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_JOURNAL_OPERATION_ACCOUNTS','U') IS NOT NULL
	DROP TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS

CREATE TABLE #TMP_JOURNAL_OPERATION_ACCOUNTS (
	[ACCOUNT] INT,
	[JURN] varchar(50),
	[GK] bit
)
GO
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4212,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4213,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4211,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4214,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4215,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4216,'05',0)
INSERT INTO #TMP_JOURNAL_OPERATION_ACCOUNTS (ACCOUNT,JURN,GK) 
VALUES(4217,'05',0)
GO
GO

IF OBJECT_ID('TEMPDB..#TMP_S_ACCOUNTS_SGU','U') IS NOT NULL
	DROP TABLE #TMP_S_ACCOUNTS_SGU

CREATE TABLE #TMP_S_ACCOUNTS_SGU (
	[ACCOUNT] INT,
	[SGU] varchar(50),
	[COMMENT] varchar(254)
)
GO
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4212,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4212,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4213,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4213,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4211,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4211,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4214,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4214,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4215,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4215,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4216,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4216,'660','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4217,'560','')
INSERT INTO #TMP_S_ACCOUNTS_SGU (ACCOUNT,SGU,COMMENT) 
VALUES(4217,'660','')
GO

---- Обновление данных
IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

ALTER TABLE dbo.S_ACCOUNTS ADD INSERTED_LINK INT NULL
GO

IF not exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[_INSERTED_S_ACCOUNTS] (
	LINK int ,
	INSERTED_LINK int )
ELSE 
	DELETE FROM dbo._INSERTED_S_ACCOUNTS
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS] ([LINK]) ON [INDEX]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
CREATE INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS] ([INSERTED_LINK]) ON [INDEX]
GO

INSERT INTO dbo.S_ACCOUNTS (INSERTED_LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED)
OUTPUT INSERTED.LINK, INSERTED.INSERTED_LINK INTO [dbo].[_INSERTED_S_ACCOUNTS] (LINK, INSERTED_LINK)
SELECT LINK,NAME,KSU,ORDERS,ZABALANS,s_active,s_passive,s_packed,s_kassa,p_DVZ,ap_KBK,ap_EKR,ap_DEP,ap_SUB,ap_EMP,ap_NOMEN,ap_INV,ap_KAU,ap_DEP_ACC,ap_TMC,ap_INDATE,ap_AP1,ap_AP2,ap_AP3,p_NOCONTROL,cSource,cSinth,cAnalit,cUser,p_UZAB,KBK_TYPE,p_EKR,ANALIT_EKR,p_KASSA,NOMEN_TYPE,p_DATE,OB_KBK,OB_EKR,OB_DEP,OB_SUB,OB_EMP,OB_NOMEN,OB_INV,OB_KAU,OB_DEP_ACC,OB_TMC,OB_AP1,OB_AP2,OB_AP3,B_YEAR0,BUH_TYPE,ISUSED
FROM #TMP_S_ACCOUNTS T
WHERE NOT EXISTS (SELECT * FROM dbo.S_ACCOUNTS SA WHERE SA.CODE = T.CODE)


UPDATE SA SET 
	SA.LINK_SELF = (SELECT TOP 1 LINK FROM dbo.S_ACCOUNTS WHERE CODE = T.CODE_SELF)
FROM
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN dbo.S_ACCOUNTS SA ON SA.LINK = A.LINK
	INNER JOIN #TMP_S_ACCOUNTS T ON T.LINK = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_KAU(ACCOUNT,LINK_KAU)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KAU K WHERE K.CODE = T.KAU)
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_KAU T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.JOURNAL_OPERATION_ACCOUNTS(ACCOUNT,JURN_LINK,GK)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.JOURNAL_OPERATION K WHERE K.CODE = T.JURN),
	GK = T.GK
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_JOURNAL_OPERATION_ACCOUNTS T ON T.ACCOUNT = A.INSERTED_LINK
GO

INSERT INTO dbo.S_ACCOUNTS_SGU(ACCOUNT,LINK_SGU,COMMENT)
SELECT DISTINCT
	ACCOUNT = A.LINK, 
	LINK_KAU = (SELECT TOP 1 LINK FROM dbo.KOSGU K WHERE K.CODE = T.SGU),
	COMMENT = T.COMMENT
FROM 
	[dbo].[_INSERTED_S_ACCOUNTS] A
	INNER JOIN #TMP_S_ACCOUNTS_SGU T ON T.ACCOUNT = A.INSERTED_LINK
GO

IF Exists(select 1 from sys.columns where Name = N'INSERTED_LINK' and Object_ID = Object_ID(N'dbo.S_ACCOUNTS'))
	BEGIN
	   ALTER TABLE dbo.S_ACCOUNTS DROP COLUMN INSERTED_LINK
	END
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS')
DROP INDEX [IX_INSERTED_S_ACCOUNTS] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF EXISTS (SELECT * FROM dbo.sysindexes WHERE [name] = 'IX_INSERTED_S_ACCOUNTS2')
DROP INDEX [IX_INSERTED_S_ACCOUNTS2] ON [dbo].[_INSERTED_S_ACCOUNTS]
GO

IF exists(select * from sysobjects where id = object_id('[dbo].[_INSERTED_S_ACCOUNTS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[_INSERTED_S_ACCOUNTS]
GO

COMMIT TRAN
GO


GO
EXEC X_SET_PROP 'COLUMN_CODE_TAX_INCTAX', 'EDIT_OBJECT_METHOD', 'A_EXEC ("SELECT (oForm.Alias)")
A_VIBOR_01 (''DICTIONARY_TAX_SALARY'', oForm.ALIAS, ''LINK, CODE, NAME'', ''REF_PAY, CODE_PAY, NAME_PAY'', '''', '''', '' WAY_CALC IN (4,5,6)'', .T., 1, oForm, oObj, "")
'
GO

GO
-- Отчет "Расчетные листы"
-- Сгенерировано скриптом scriptObjectVar 'SQL_REPORT_Z_RL'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'SQL_REPORT_Z_RL'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'SQL_REPORT_Z_RL'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'Расчетные листы',103, 
	(Select link from object_var where code = 'SQL_REPORT_CATALOG_SALARY'),
	'SQL_REPORT_Z_RL',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'INIT_OBJECT_METHOD')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'INIT_OBJECT_METHOD'),
	VALUE= 'm_print_query(nLink_Var)'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'VISIBLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'VISIBLE'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_DATETIME'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FOOTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_PAGES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDFROM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDFROM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDINTO')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDINTO'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDSELECT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDSELECT'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDWHERE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDWHERE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AFTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AFTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'IF @nCheck1 = 0

EXEC dbo.SD_REP_RL
	@cYear1		/* Расчетный год */,
	@nMonth1		/* Расчетный месяц */,
	@cVal1, 
	@nOtborLink1,
	@nOption1,
	@nCheck3,
	DEFAULT,
	@nCheck4,
	@nCheck5,
	@nCheck7,
	@cVal2, 
	@nOtborLink2,
	@nCheck8, /* Выводить Ф.И.О. полностью */
	@nCheck9, /* Выводить наименование отдела вместо кода */
	@nCheck10 /* Формировать р/л за каждый месяц с начала года по выбранный месяц */

ELSE

EXEC dbo.SA_REP_RL_ONE
	@cYear1		/* Расчетный год */,
	@nMonth1		/* Расчетный месяц */,
	@cVal1, 
	@nOtborLink1,
	@nOption1,
	@nCheck3,
 	DEFAULT,
	@nCheck4,
	@nCheck5,
	@nCheck7,
	@cVal2, 
	@nOtborLink2,
	@nCheck8, /* Выводить Ф.И.О. полностью */
	@nCheck9, /* Выводить наименование отдела вместо кода */
	@nCheck10 /* Формировать р/л за каждый месяц с начала года по выбранный месяц */'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DATETIME'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DISTINCT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DISTINCT'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FREEZEPANES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PAGES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#REPORT_Z_RL'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(@nCheck1 = 0,"REP_Z_10001.XLT",IIF(@nCheck1 = 1,"REP_Z_10002.XLT",""))'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #REPORT_Z_RL
	@cYear1 VARCHAR(4)	/* Расчетный год */,
	@nMonth1 int	/* Расчетный месяц */,
	@nOption1 int	/* Порядок сортировки */,
	@nCheck1 int	/* Печатать только по одному  Р/Л на сотрудника */,
	@nCheck2 int	/* Не печатать должность сотрудника */,
	@nCheck3 int	/* Разделять Б/Л за счет ФСС и работодателя */,
	@nCheck4 int	/* Отображать источник финансирования */,
	@nCheck5 int	/* Формировать пустые р/л */,
	@nOption2 int	/* Создание отчета */,
	@nCombo1 int	/* Количество листочков на листе (HTML) */,
	@nCheck6 int	/* Детализировать остаток */,
	@nCheck7 int	/* Отображать разряд */,
	@nCheck8 int	/* Выводить Ф.И.О. полностью */,
	@nCheck9 int	/* Выводить наименование отдела вместо кода */,
	@nCheck10 int	/* Формировать р/л за каждый месяц с начала года по выбранный месяц */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор сотрудников */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_EMPL''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор групп сотрудников */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_GROUPS_EMPL''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

IF @nCheck1 = 0

EXEC dbo.SD_REP_RL
	@cYear1		/* Расчетный год */,
	@nMonth1		/* Расчетный месяц */,
	@cVal1, 
	@nOtborLink1,
	@nOption1,
	@nCheck3,
	DEFAULT,
	@nCheck4,
	@nCheck5,
	@nCheck7,
	@cVal2, 
	@nOtborLink2,
	@nCheck8, /* Выводить Ф.И.О. полностью */
	@nCheck9, /* Выводить наименование отдела вместо кода */
	@nCheck10 /* Формировать р/л за каждый месяц с начала года по выбранный месяц */

ELSE

EXEC dbo.SA_REP_RL_ONE
	@cYear1		/* Расчетный год */,
	@nMonth1		/* Расчетный месяц */,
	@cVal1, 
	@nOtborLink1,
	@nOption1,
	@nCheck3,
 	DEFAULT,
	@nCheck4,
	@nCheck5,
	@nCheck7,
	@cVal2, 
	@nOtborLink2,
	@nCheck8, /* Выводить Ф.И.О. полностью */
	@nCheck9, /* Выводить наименование отдела вместо кода */
	@nCheck10 /* Формировать р/л за каждый месяц с начала года по выбранный месяц */

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SYSTEM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SYSTEM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTAL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTAL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALROW')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALROW'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AP_LIST')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AP_LIST'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'REP_Z_RL.BAS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ALTERNATIVE_PRINT_METHOD')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ALTERNATIVE_PRINT_METHOD'),
	VALUE= 'SA_PRINT_RL()'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REPORT_Z_RL') and  PROPERTY = (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REPORT_Z_RL'),
	PROPERTY= (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR'),
	VALUE= '0'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_FILTER' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_FILTER'),
		'Стандартный фильтр для запроса',0, 
		(Select link from object_var where code = 'SQL_REPORT_Z_RL'),
		'SQL_REPORT_Z_RL_FILTER',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_OTBOR1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_EMPL'),
					'Отбор сотрудников',1, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_FILTER'),
					'SQL_REPORT_Z_RL_OTBOR1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE2') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE2'),
							'DICTIONARY_SUBDIVISION01'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICT_EMPLOYERS01'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR1'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_OTBOR2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_GROUPS_EMPL'),
					'Отбор групп сотрудников',2, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_FILTER'),
					'SQL_REPORT_Z_RL_OTBOR2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICTIONARY_GROUPS_EMPL'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_OTBOR2'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR_GR' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',3, 
		(Select link from object_var where code = 'SQL_REPORT_Z_RL'),
		'SQL_REPORT_Z_RL_NASTR_GR',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_YEARBOX'),
					'Расчетный год',4, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'FORMAT'),
							'9999'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MASKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий год,Расчетный год'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@cYear1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'VARCHAR(4)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2014'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2013'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2012'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'2012'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR10' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_COMBOBOX'),
					'Количество листочков на листе (HTML)',13, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR10',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Количество листочков на листе (HTML)'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Настойка только для варианта печати в HTML.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Лента, по 2 листочка, по 4 листочка, по 6 листочков, по 8 листочков, по 10 листочков'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Лента'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Лента'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Лента'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Лента'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Лента'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR10'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR11' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Детализировать остаток',14, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR11',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Детализировать остаток'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Детализировать остаток'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'6'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck6'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR11'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR12' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Отображать разряд',15, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR12',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Отображать разряд'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'7'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck7'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR12'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR13' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Выводить Ф.И.О. полностью',16, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR13',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Выводить Ф.И.О. полностью'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'8'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck8'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR13'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_MONTHBOX'),
					'Расчетный месяц',5, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Расчетный месяц'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'MONTHBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущий месяц,Расчетный месяц'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nMonth1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Март'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Январь'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Февраль'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Расчетный месяц'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Апрель'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR3' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_OPTIONGROUP'),
					'Порядок сортировки',6, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR3',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Порядок сортировки'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'OPTIONGROUP'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'По табельным номерам,По кодам подразделений и таб. номерам,По кодам подразделений и Ф.И.О.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nOption1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'По табельным номерам'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'По табельным номерам'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'По табельным номерам'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'По табельным номерам'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'По табельным номерам'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR4' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Печатать только по одному  Р/Л на сотрудника',7, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR4',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Печатать только по одному  Р/Л на сотрудника'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR4'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR5' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Не печатать должность сотрудника',8, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR5',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Не печатать должность сотрудника'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'2'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck2'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR5'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR6' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Разделять Б/Л за счет ФСС и работодателя',9, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR6',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Разделять Б/Л за счет ФСС и работодателя'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'3'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck3'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR6'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR7' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Отображать источник финансирования',10, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR7',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Отображать источник финансирования'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'4'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck4'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR7'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR8' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Формировать пустые р/л',11, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR8',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Формировать пустые р/л'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Включить формирование р/л на сотрудников, у которых не было доходов.

'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'5'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck5'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR8'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR9' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_OPTIONGROUP'),
					'Создание отчета',12, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR9',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Создание отчета'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'OPTIONGROUP'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Устанавливается формат формируемого файла. HTML рекомендуется для формирования большого количества расчётных листочков.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'2'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'MS Excel,HTML'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nOption2'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'HTML'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'HTML'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'HTML'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'HTML'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'HTML'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR9'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_NASTR14' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Выводить наименование отдела вместо кода',17, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_NASTR14',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Выводить наименование отдела вместо кода'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Выводить наименование отдела вместо кода'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'9'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck9'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR14'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REPORT_Z_RL_ALL_MONTH' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Формировать р/л за каждый месяц с начала года по выбранный месяц',18, 
					(Select link from object_var where code = 'SQL_REPORT_Z_RL_NASTR_GR'),
					'SQL_REPORT_Z_RL_ALL_MONTH',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Формировать р/л за каждый месяц с начала года по выбранный месяц'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'CHECKBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Формировать р/л за каждый месяц с начала года по выбранный месяц'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'10'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Выкл.,Вкл.'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCheck10'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Выкл.'

						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REPORT_Z_RL_ALL_MONTH'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
/***   Группа настроек    ***/
GO


GO
/****** Объект: Резидент******/

IF EXISTS( SELECT * FROM DBO.S_OBJECTS WHERE CODE = 'SD_EMPL_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[SDOC] D INNER JOIN [dbo].[S_OBJECTS] O ON D.[OBJECT] = O.[LINK] WHERE O.CODE = 'SD_EMPL_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[OBJECT_VAR] V INNER JOIN [dbo].[S_OBJECTS] O ON V.[OBJECT] = O.[LINK] WHERE O.CODE = 'SD_EMPL_RESIDENT')
	AND NOT EXISTS( SELECT O.LINK FROM [dbo].[DICTION] C INNER JOIN [dbo].[S_OBJECTS] O ON C.[OBJECT] = O.[LINK] WHERE O.CODE = 'SD_EMPL_RESIDENT')
	
	DELETE FROM DBO.S_OBJECTS WHERE CODE = 'SD_EMPL_RESIDENT'
ELSE
	DELETE FROM DBO.S_OBJECTS WHERE LINK_SELF IN (SELECT LINK FROM DBO.S_OBJECTS WHERE CODE = 'SD_EMPL_RESIDENT')	

GO

IF NOT EXISTS(SELECT * FROM S_OBJECTS WHERE CODE='SD_EMPL_RESIDENT')
	INSERT S_OBJECTS (CODE, NAME, ORDERS, LINK_SELF, LINK_CLASS, MANAGED, INHERITED)
	SELECT 'SD_EMPL_RESIDENT', 'Резидент', 11, (SELECT LINK FROM S_OBJECTS WHERE CODE='SD_EMPL'), (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'),0,0
ELSE
	UPDATE DBO.S_OBJECTS
	SET CODE = 'SD_EMPL_RESIDENT', NAME = 'Резидент', ORDERS = '11', LINK_SELF = (SELECT LINK FROM S_OBJECTS WHERE CODE='SD_EMPL'), LINK_CLASS = (SELECT LINK FROM S_OBJECTS WHERE CODE='EDIT_FIELD_CLASS'), MANAGED = 0, INHERITED = 0
	WHERE CODE ='SD_EMPL_RESIDENT'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'TITLE', 'Резидент'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'VISIBLE', '15'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'CONTROLSOURCE', 'm.cAlias+".RESIDENT_N"'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'EDITABLE', '1'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'ROWSOURCE', '"Нерезидент (временно проживающий),Резидент,Нерезидент (постоянно проживающий)"'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'TYPE_FIELD_DICT', 'NUMERIC(1,0)'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'SHORT_CODE_OBJ', 'RESIDENT'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'CONTROLSOURCE_EDIT', 'm.cAlias+".RESIDENT"'
GO
EXEC X_SET_PROP 'SD_EMPL_RESIDENT', 'CONTROL_NAME_EDIT', 'Acombobox18'
GO



GO
-- Отчет "ФОТ по видам начислений"
-- Сгенерировано скриптом scriptObjectVar 'SQL_REP_SA_FOT_NLIST'

/*** Сам отчет ***/

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var

CREATE TABLE #UPD_object_var (link_navigator int)

INSERT INTO #UPD_object_var (link_navigator)
SELECT  SN.LINK
FROM S_NAVIGATOR SN,OBJECT_VAR OV
WHERE SN.LINK_VAR = OV.LINK AND OV.CODE= 'SQL_REP_SA_FOT_NLIST'  

 
GO
    
	DELETE FROM OBJECT_VAR WHERE CODE = 'SQL_REP_SA_FOT_NLIST'
	INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
	Select (Select link from s_objects where code = 'QUERY_SQL'),
	'ФОТ по видам начислений',401, 
	(Select link from object_var where code = 'SQL_REPORT_CATALOG_SALARY'),
	'SQL_REP_SA_FOT_NLIST',NULL, NULL, 1
	

	UPDATE S_NAVIGATOR
	SET LINK_VAR = (SELECT TOP 1 LINK FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST') 
	FROM S_NAVIGATOR S INNER JOIN #UPD_object_var U on S.LINK = U.link_navigator
GO

if object_id('tempdb..#UPD_object_var') is not null
	drop table #UPD_object_var
GO
/*** Свойства отчета ***/
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'INIT_OBJECT_METHOD')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'INIT_OBJECT_METHOD'),
	VALUE= 'm_print_query(nLink_Var)'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'VISIBLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'VISIBLE'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'CHECK_VALUE_IN_TABLE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'BEFORE_CHANGE_PROG_NASTR'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_CENTER_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_DATETIME'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FOOTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_FREEZEPANES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_LEFT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_PAGES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'NASTR_XL_RIGHT_HEADER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDFROM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDFROM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDINTO')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDINTO'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDSELECT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDSELECT'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADDWHERE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADDWHERE'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AFTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AFTER'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_BEFORE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_BEFORE'),
	VALUE= 'EXEC 	DBO.SA_FOT_NLIST 
	@dDateB1 /* Начало периода */,
	@dDateE1 /* Конец периода */,
	@nCombo2 /* Внешние совместители */,
	@cVal1, @nOtborLink1 /* Отбор сотрудников */,
	@cVal2, @nOtborLink2 /* Отбор видов начислений */,
	@cVal3, @nOtborLink3 /* Отбор должностей */'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DATETIME')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DATETIME'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_DISTINCT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_DISTINCT'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FOOTER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FOOTER'),
	VALUE= '="Исполнитель                               " & User_FIO
                                 подпись'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_FREEZEPANES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_FREEZEPANES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_HEADER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_HEADER'),
	VALUE= '=User_Name'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PAGES')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PAGES'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_PROCEDURE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_PROCEDURE'),
	VALUE= '#SQL_REP_SA_FOT_NLIST'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPMAKER')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPMAKER'),
	VALUE= 'KIRREPMAKER.XLS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT'),
	VALUE= 'IIF(.T.,"FOT_NLIST.XLT","")'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_REPORT_PATH')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_REPORT_PATH'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SQL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SQL'),
	VALUE= 'CREATE PROCEDURE #SQL_REP_SA_FOT_NLIST
	@dDateB1 datetime	/* Начало периода */,
	@dDateE1 datetime	/* Конец периода */,
	@nCombo2 int	/* Внешние совместители */,
	@nFilterLink int	/* Фильтр */
AS
BEGIN
	DECLARE @cVal1 char(1), @nOtborLink1 int	/* Отбор сотрудников */
	SELECT @nOtborLink1 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_EMPL''))
	SELECT @cVal1 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink1 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal2 char(1), @nOtborLink2 int	/* Отбор видов начислений */
	SELECT @nOtborLink2 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_PAY_SALARY''))
	SELECT @cVal2 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink2 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))
	DECLARE @cVal3 char(1), @nOtborLink3 int	/* Отбор должностей */
	SELECT @nOtborLink3 = (SELECT LINK FROM OBJECT_VAR WHERE LINK_SELF=@nFilterLink AND OBJECT=(SELECT LINK FROM S_OBJECTS WHERE CODE=''OTBOR_QUERY_SQL_POST''))
	SELECT @cVal3 = (SELECT VALUE FROM OBJECT_VAR_VALUES WHERE LINK_UP=@nOtborLink3 AND PROPERTY=(SELECT LINK FROM S_PROPERTY WHERE CODE=''QUERY_OTBOR_CHECK''))

EXEC 	DBO.SA_FOT_NLIST 
	@dDateB1 /* Начало периода */,
	@dDateE1 /* Конец периода */,
	@nCombo2 /* Внешние совместители */,
	@cVal1, @nOtborLink1 /* Отбор сотрудников */,
	@cVal2, @nOtborLink2 /* Отбор видов начислений */,
	@cVal3, @nOtborLink3 /* Отбор должностей */

END'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_SYSTEM')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_SYSTEM'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOP')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOP'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTAL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTAL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_TOTALROW')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_TOTALROW'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_AP_LIST')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_AP_LIST'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'EOD_PROTOCOL')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'EOD_PROTOCOL'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'AFTER_REPORT_PROG')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'AFTER_REPORT_PROG'),
	VALUE= ''
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'QUERY_ADD_MODULE')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'QUERY_ADD_MODULE'),
	VALUE= 'KIRREPCOMMON.BAS'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'SQUERY_NO_SHOW')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'SQUERY_NO_SHOW'),
	VALUE= '0'
	
	
	DELETE  FROM object_var_values WHERE LINK_UP = ( Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST') and  PROPERTY = (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR')
	INSERT INTO object_var_values (LINK_UP, PROPERTY, VALUE)
	Select  LINK_UP= (Select link from object_var OV where code = 'SQL_REP_SA_FOT_NLIST'),
	PROPERTY= (Select LINK from s_property where code = 'REPORT_EXTERNAL_GENERATOR'),
	VALUE= '0'
	
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_F1' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_FILTER'),
		'Стандартный фильтр для запроса',0, 
		(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST'),
		'SQL_REP_SA_FOT_NLIST_F1',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_O1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_EMPL'),
					'Отбор сотрудников',1, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_F1'),
					'SQL_REP_SA_FOT_NLIST_O1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICT_EMPLOYERS01'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE2') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O1'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE2'),
							'DICTIONARY_SUBDIVISION01'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_O2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_PAY_SALARY'),
					'Отбор видов начислений',2, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_F1'),
					'SQL_REP_SA_FOT_NLIST_O2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICTIONARY_PAY_SALARY'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O2'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_O3' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'OTBOR_QUERY_SQL_POST'),
					'Отбор должностей',3, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_F1'),
					'SQL_REP_SA_FOT_NLIST_O3',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_CHECK') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_OTBOR_CHECK'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_OTBOR_DICTIONARY_CODE'),
							'DICTIONARY_POST'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_FIELD') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_OTBOR_FIELD'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_OTBOR_PARENT_CODE'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_OTBOR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_O3'),
							(Select link from s_property where code = 'QUERY_OTBOR_VALUE'),
							''
						
GO
/***   Группа настроек    ***/
     
		DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_G' 
		INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
		Select (Select link from s_objects where code = 'QUERY_NASTRS'),
		'Группа настроек',4, 
		(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST'),
		'SQL_REP_SA_FOT_NLIST_G',NULL, NULL, 1
		
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_N1' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX_PB'),
					'Начало периода',5, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_G'),
					'SQL_REP_SA_FOT_NLIST_N1',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Начало периода'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'На эту дату выводятся все показатели свода'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDateB1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Начало расч. месяца'

GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N1'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_N2' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_DATEBOX_PE'),
					'Конец периода',6, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_G'),
					'SQL_REP_SA_FOT_NLIST_N2',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Конец периода'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'DATEBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'До этого периода определяются даты и новый процент по стажу'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Текущая дата,Расчетная дата,Начало расч. периода,Конец расч. периода,Начало года,Конец года,Начало расч. месяца,Конец расч. месяца'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@dDateE1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'datetime'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Конец расч. месяца'
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N2'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Настройка из группы   ***/
		
					DELETE FROM object_var WHERE CODE = 'SQL_REP_SA_FOT_NLIST_N3' 
					INSERT INTO object_var (OBJECT, NAME, ORDERS, LINK_SELF, CODE, LINK_STATE, USERS, SYS) 
					Select (Select link from s_objects where code = 'NASTR_QUERY_CHECKBOX'),
					'Внешние совместители',7, 
					(Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_G'),
					'SQL_REP_SA_FOT_NLIST_N3',NULL, NULL, 1
					
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'EDITABLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'EDITABLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'SQUERY_NASTR_NON_VISIBLE'),
							'0'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'FORMAT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'FORMAT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CAPTION') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_CAPTION'),
							'Внешние совместители'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_CONTROL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_CONTROL'),
							'COMBOBOX'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NOTE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_NOTE'),
							'Внешние совместители'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_NUMPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_NUMPARAM'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SAVE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_SAVE'),
							'1'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SOURCE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_SOURCE'),
							'Не включать внешних совместителей,Включать внешних совместителей,Включать только внешних совместителей'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLPARAM') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLPARAM'),
							'@nCombo2'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_SQLTYPE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_SQLTYPE'),
							'int'
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE'),
							'Не включать внешних совместителей'
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'QUERY_NASTR_VALUE_TEXT'),
							''
						
GO
						
						DELETE FROM OBJECT_VAR_VALUES WHERE PROPERTY = (Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL') and LINK_UP = (Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3') 
						INSERT INTO OBJECT_VAR_VALUES(LINK_UP, PROPERTY, VALUE)
						Select ( Select link from object_var where code = 'SQL_REP_SA_FOT_NLIST_N3'),
							(Select link from s_property where code = 'SQUERY_NASTR_OPTIONAL'),
							'0'
						
GO
/***   Группа настроек    ***/
GO
/***   Группа настроек    ***/
GO
/***   Группа настроек    ***/
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:33:30:883PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503121G (Отчет о финансовых результатах деятельности)
-- Дата ввода : 20130101
-- Дата окончания действия : 20141230
-- Версия : 2014-12-27 13:33:30.883
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503121G' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:33:30.883',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Отчет о финансовых результатах деятельности',
    [ExportCode]          = '221       ',
    [START_DATE]          = '20130101',
    [END_DATE]            = '20141230',
    [PERIODIC]            = 3,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'sv_0503121g_20130101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503121g_20130101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL2) + ''|'' + STR(COL4) + ''|'' + STR(COL5) + ''|'' + STR(COL6) + ''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C2+''|''+C3+''|''+C4',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:33:30.883',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:33:30.883'
	BEGIN
		SELECT @vcMessage = 'Форма 0503121G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503121G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:33:30.883. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:36:41:657PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503125G (Справка по консолидируемым расчётам (годовая))
-- Дата ввода : 20111231
-- Дата окончания действия : 20141231
-- Версия : 2014-12-27 13:36:41.657
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503125G' AND [START_DATE] = '20111231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:36:41.657',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Справка по консолидируемым расчётам (годовая)',
    [ExportCode]          = '225       ',
    [START_DATE]          = '20111231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 1,
    [PRINT_OBJECT_METHOD] = 'svodprint_page_one_atr()',
    [QUERY_ADD_MODULE]    = 'sv_0503125m_20110101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503125m_20110101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_125#RA_IMPORT_FORM_125M',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = ' #  #  #
RTRIM(COL2)+''|''+RTRIM(COL3)+''|''+RTRIM(COL4)+''|''+LEFT(RIGHT(''**************************'' + RTRIM(COL5),26),3)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),4,14)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),18,1)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),19,5)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),24,3)+''|''+LEFT(COL8,1)+''|''+SUBSTRING(COL8,2,5)+''|''+SUBSTRING(COL8,7,3)+''|''+RTRIM(STR(COL6))+''|''+RTRIM(STR(COL7))+''|''+RTRIM(COL9)+''|''',
    [PARAM_IMPORT]        = ' # # # ''|''+C1+''|''+C2+''|''+C3+ ''|''+C4+C5+C6+C7+C8+''|''+C12+''|''+C13+''|''+C9+C10+C11+''|'' + C14',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_ACC_2011,REPORTS_ATR_PRP,REPORTS_FILTER_KBK',
    [SvodProc]            = 'RT_SVOD_0503125M_2011 #LSF',
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = 'RO_PRINT_125',
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = 'sv_0503125m_20090131_new.xlt',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:36:41.657',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:36:41.657'
	BEGIN
		SELECT @vcMessage = 'Форма 0503125G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503125G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:36:41.657. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:36:41:673PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503125M (Справка по консолидируемым расчётам (месячная))
-- Дата ввода : 20110101
-- Дата окончания действия : 20141231
-- Версия : 2014-12-27 13:36:41.673
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503125M' AND [START_DATE] = '20110101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:36:41.673',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Справка по консолидируемым расчётам (месячная)',
    [ExportCode]          = '225       ',
    [START_DATE]          = '20110101',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 4,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = 'svodprint_page_one_atr()',
    [QUERY_ADD_MODULE]    = 'sv_0503125m_20110101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503125m_20110101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_125#RA_IMPORT_FORM_125M',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = ' #  #  #
RTRIM(COL2)+''|''+RTRIM(COL3)+''|''+RTRIM(COL4)+''|''+LEFT(RIGHT(''**************************'' + RTRIM(COL5),26),3)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),4,14)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),18,1)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),19,5)+''|''+SUBSTRING(RIGHT(''**************************'' + RTRIM(COL5),26),24,3)+''|''+LEFT(COL8,1)+''|''+SUBSTRING(COL8,2,5)+''|''+SUBSTRING(COL8,7,3)+''|''+RTRIM(STR(COL6))+''|''+RTRIM(STR(COL7))+''|''+RTRIM(COL9)+''|''',
    [PARAM_IMPORT]        = ' # # # ''|''+C1+''|''+C2+''|''+C3+ ''|''+C4+C5+C6+C7+C8+''|''+C12+''|''+C13+''|''+C9+C10+C11+''|'' + C14',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_ACC_2011,REPORTS_ATR_PRP,REPORTS_FILTER_KBK',
    [SvodProc]            = 'RT_SVOD_0503125M_2011 #LSF',
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = 'RO_PRINT_125',
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = 'sv_0503125m_20090131_new.xlt',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:36:41.673',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:36:41.673'
	BEGIN
		SELECT @vcMessage = 'Форма 0503125M с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503125M с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:36:41.673. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 12 2015  3:40:14:980PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503128G (Отчет о принятых бюджетных  обязательствах)
-- Дата ввода : 20111231
-- Дата окончания действия : 20141231
-- Версия : 2015-01-12 15:40:14.980
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503128G' AND [START_DATE] = '20111231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-12 15:40:14.980',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Отчет о принятых бюджетных  обязательствах',
    [ExportCode]          = '228       ',
    [START_DATE]          = '20111231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 1,
    [PRINT_OBJECT_METHOD] = 'svodprint_page_itog()',
    [QUERY_ADD_MODULE]    = 'sv_0503128g_20100101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'kirrepmakermultisheet.xls',
    [QUERY_REPORT]        = 'sv_0503128g_20111231.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_128#RA_IMPORT_FORM_128',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'COL2+''|$ADM$|''+LEFT(COL16,4)+''|''+SUBSTRING(COL16,5,7)+''|''+SUBSTRING(COL16,12,3)+''|''+SUBSTRING(COL16,15,3)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''+STR(COL13)+''|''+STR(COL14)+''|''+STR(COL15)+''|''
#
LEFT(COL13,3)+''|$ADM$|'' +SUBSTRING(COL13,4,17)+''|'' +STR(COL4)+''|''+STR(COL5) + ''|'' + STR(COL6)+''|''+STR(COL7) +''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''
#
COL2+''|''+COL3+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C3+C4+C5+C6+''|''+C7+''|''+C8+''|''+C9+''|''+C10+''|''+C11+''|''+C12+''|''+C13+''|''+C14+''|''+C15
# C1+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8 +''|''+C9+''|''+C10+''|''+C11+''|''+C12
#
C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''+C9+''|''+C10+''|''+C11',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_ADM',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = 'RB_PRINT_0503128G',
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = 'sv_0503128g_20100101.xlt',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-12 15:40:14.980',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-12 15:40:14.980'
	BEGIN
		SELECT @vcMessage = 'Форма 0503128G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503128G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-12 15:40:14.980. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 12 2015  3:41:33:703PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503128M (Отчет о принятых бюджетных  обязательствах)
-- Дата ввода : 20110101
-- Дата окончания действия : 20141231
-- Версия : 2015-01-12 15:41:33.703
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503128M' AND [START_DATE] = '20110101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-12 15:41:33.703',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Отчет о принятых бюджетных  обязательствах',
    [ExportCode]          = '228       ',
    [START_DATE]          = '20110101',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 4,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 1,
    [PRINT_OBJECT_METHOD] = 'svodprint_page_itog()',
    [QUERY_ADD_MODULE]    = 'sv_0503128g_20100101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'kirrepmakermultisheet.xls',
    [QUERY_REPORT]        = 'sv_0503128g_20100101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_128#RA_IMPORT_FORM_128',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'COL2+''|$ADM$|''+LEFT(COL16,4)+''|''+SUBSTRING(COL16,5,7)+''|''+SUBSTRING(COL16,12,3)+''|''+SUBSTRING(COL16,15,3)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''+STR(COL13)+''|''+STR(COL14)+''|''+STR(COL15)+''|''
#
LEFT(COL13,3)+''|$ADM$|'' +SUBSTRING(COL13,4,17)+''|'' +STR(COL4)+''|''+STR(COL5) + ''|'' + STR(COL6)+''|''+STR(COL7) +''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''
#
COL2+''|''+COL3+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''+STR(COL11)+''|''+STR(COL12)+''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C3+C4+C5+C6+''|''+C7+''|''+C8+''|''+C9+''|''+C10+''|''+C11+''|''+C12+''|''+C13+''|''+C14+''|''+C15
# C1+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8 +''|''+C9+''|''+C10+''|''+C11+''|''+C12
#
C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''+C9+''|''+C10+''|''+C11',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_ADM',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = 'RB_PRINT_0503128G',
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = 'sv_0503128g_20100101.xlt',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-12 15:41:33.703',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-12 15:41:33.703'
	BEGIN
		SELECT @vcMessage = 'Форма 0503128M с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503128M с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-12 15:41:33.703. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:37:49:937PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503130G ( Баланс (гл)распоряд., получ бюдж. ср-в)
-- Дата ввода : 20130101
-- Дата окончания действия : 20141230
-- Версия : 2014-12-27 13:37:49.933
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503130G' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:37:49.933',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = ' Баланс (гл)распоряд., получ бюдж. ср-в',
    [ExportCode]          = '230       ',
    [START_DATE]          = '20130101',
    [END_DATE]            = '20141230',
    [PERIODIC]            = 3,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 1,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'SV_0503130G_20130101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503130G_20130101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL2)+''|''+STR(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''#RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7#C1+''|''+C2+''|''+C3+''|''',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:37:49.933',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:37:49.933'
	BEGIN
		SELECT @vcMessage = 'Форма 0503130G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503130G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:37:49.933. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 21 2015 12:10:03:350PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503168G_БД ( Сведения о движении нефинансовых активов (бюджетная деятельность))
-- Дата ввода : 20110101
-- Дата окончания действия : 20121231
-- Версия : 2015-01-21 12:10:03.350
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503168G_БД' AND [START_DATE] = '20110101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-21 12:10:03.350',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = ' Сведения о движении нефинансовых активов (бюджетная деятельность)',
    [ExportCode]          = '268b      ',
    [START_DATE]          = '20110101',
    [END_DATE]            = '20121231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'sv_0503168G_20100101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503168G_BD_20110201.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_168',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'LEFT(COL2,1)+''|''+SUBSTRING(COL2,2,5)+''|''+SUBSTRING(COL2,7,3)+''|''+RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''',
    [PARAM_IMPORT]        = '''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-21 12:10:03.350',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-21 12:10:03.350'
	BEGIN
		SELECT @vcMessage = 'Форма 0503168G_БД с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503168G_БД с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-21 12:10:03.350. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 21 2015 12:08:59:270PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503168G_БД ( Сведения о движении нефинансовых активов (бюджетная деятельность))
-- Дата ввода : 20130101
-- Дата окончания действия : 20141231
-- Версия : 2015-01-21 12:08:59.270
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503168G_БД' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-21 12:08:59.270',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = ' Сведения о движении нефинансовых активов (бюджетная деятельность)',
    [ExportCode]          = '268b      ',
    [START_DATE]          = '20130101',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'sv_0503168G_20130101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'SV_0503168G_BD_20130101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|'' #
RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''',
    [PARAM_IMPORT]        = NULL,
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-21 12:08:59.270',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-21 12:08:59.270'
	BEGIN
		SELECT @vcMessage = 'Форма 0503168G_БД с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503168G_БД с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-21 12:08:59.270. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 20 2015  3:57:45:883PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503169G_БД (Сведения по дебиторской и кредиторской задолженности (Бюдж, Дебет))
-- Дата ввода : 20121231
-- Дата окончания действия : 20141231
-- Версия : 2015-01-20 15:57:45.883
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503169G_БД' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-20 15:57:45.883',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Сведения по дебиторской и кредиторской задолженности (Бюдж, Дебет)',
    [ExportCode]          = '259       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = 'svodprint_new_gen()',
    [QUERY_ADD_MODULE]    = 'sv_0503169g_20121231.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503169g_bd_20121231.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_169',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + RTRIM(COL6) + ''|'' + RTRIM(COL7) + ''|'' #
REPLACE(LEFT(COL10,3)+''|''+SUBSTRING(COL10,4,14)+''|''+SUBSTRING(COL10,18,1)+''|''+SUBSTRING(COL10,19,5)+''|''+SUBSTRING(COL10,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL6)) +''|'' + LTRIM(STR(COL7)) + ''|'' + LTRIM(STR(COL8)) + ''|'' + LTRIM(STR(COL9)) + ''|'' # 
REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + LTRIM(STR(COL6)) + ''|'' + LTRIM(STR(COL7)) + ''|''  #
''000|00000000000000|''+LEFT(COL7,1)+''|''+SUBSTRING(COL7,2,5)+''|''+SUBSTRING(COL7,7,3)+''|''+dbo.RO_EXP(COL3)+''|''+LTRIM(STR(COL2)) +''|'' + dbo.RO_EXP(COL4) + ''|'' + dbo.RO_EXP(COL5) + ''|'' + dbo.RO_EXP(COL6) + ''|'' 
',
    [PARAM_IMPORT]        = 'REPLACE(C1+C2+C3+C4+C5,''*****************'',''00000000000000000'')+''|''+C6+''|''+C7+''|''+C8+''|''+C9 # # #
C3+C4+C5+C6+C8+''|''+C7+''|''+C6+''|''+C8+''|''+C9+''|''+C10

',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = '',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = 'RN_PRINT_169',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-20 15:57:45.883',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-20 15:57:45.883'
	BEGIN
		SELECT @vcMessage = 'Форма 0503169G_БД с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503169G_БД с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-20 15:57:45.883. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 20 2015  3:57:45:910PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503169G_БК (Сведения по дебиторской и кредиторской задолженности (Бюдж, Кредит))
-- Дата ввода : 20121231
-- Дата окончания действия : 20141231
-- Версия : 2015-01-20 15:57:45.910
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503169G_БК' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-20 15:57:45.910',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Сведения по дебиторской и кредиторской задолженности (Бюдж, Кредит)',
    [ExportCode]          = '269       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = 'svodprint_new_gen()',
    [QUERY_ADD_MODULE]    = 'sv_0503169g_20121231.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503169g_bk_20121231.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_169',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + RTRIM(COL6) + ''|'' + RTRIM(COL7) + ''|'' #
REPLACE(LEFT(COL10,3)+''|''+SUBSTRING(COL10,4,14)+''|''+SUBSTRING(COL10,18,1)+''|''+SUBSTRING(COL10,19,5)+''|''+SUBSTRING(COL10,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL6)) +''|'' + LTRIM(STR(COL7)) + ''|'' + LTRIM(STR(COL8)) + ''|'' + LTRIM(STR(COL9)) + ''|'' # 
REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + LTRIM(STR(COL6)) + ''|'' + LTRIM(STR(COL7)) + ''|''  #
''000|00000000000000|''+LEFT(COL7,1)+''|''+SUBSTRING(COL7,2,5)+''|''+SUBSTRING(COL7,7,3)+''|''+dbo.RO_EXP(COL3)+''|''+LTRIM(STR(COL2)) +''|'' + dbo.RO_EXP(COL4) + ''|'' + dbo.RO_EXP(COL5) + ''|'' + dbo.RO_EXP(COL6) + ''|'' 
',
    [PARAM_IMPORT]        = 'REPLACE(C1+C2+C3+C4+C5,''*****************'',''00000000000000000'')+''|''+C6+''|''+C7+''|''+C8+''|''+C9 # # #
C3+C4+C5+C6+C8+''|''+C7+''|''+C6+''|''+C8+''|''+C9+''|''+C10
',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = '',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = 'RN_PRINT_169',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-20 15:57:45.910',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-20 15:57:45.910'
	BEGIN
		SELECT @vcMessage = 'Форма 0503169G_БК с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503169G_БК с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-20 15:57:45.910. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 13 2015  3:25:32:220PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503169M_БД (Сведения по дебиторской и кредиторской задолженности (Бюдж, Дебет))
-- Дата ввода : 20121231
-- Дата окончания действия : 20141231
-- Версия : 2015-01-13 15:25:32.220
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503169M_БД' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-13 15:25:32.220',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Сведения по дебиторской и кредиторской задолженности (Бюдж, Дебет)',
    [ExportCode]          = '259       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 6,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = 'svodprint_new_gen()',
    [QUERY_ADD_MODULE]    = 'sv_0503169g_20121231.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503169g_bd_20121231.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + RTRIM(COL6) + ''|'' + RTRIM(COL7) + ''|'' #
REPLACE(LEFT(COL10,3)+''|''+SUBSTRING(COL10,4,14)+''|''+SUBSTRING(COL10,18,1)+''|''+SUBSTRING(COL10,19,5)+''|''+SUBSTRING(COL10,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL6)) +''|'' + LTRIM(STR(COL7)) + ''|'' + LTRIM(STR(COL8)) + ''|'' + LTRIM(STR(COL9)) + ''|'' # 
REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + LTRIM(STR(COL6)) + ''|'' + LTRIM(STR(COL7)) + ''|''  #
''000|00000000000000|''+LEFT(COL7,1)+''|''+SUBSTRING(COL7,2,5)+''|''+SUBSTRING(COL7,7,3)+''|''+dbo.RO_EXP(COL3)+''|''+LTRIM(STR(COL2)) +''|'' + dbo.RO_EXP(COL4) + ''|'' + dbo.RO_EXP(COL5) + ''|'' + dbo.RO_EXP(COL6) + ''|'' 
',
    [PARAM_IMPORT]        = 'REPLACE(C1+C2+C3+C4+C5,''*****************'',''00000000000000000'')+''|''+C6+''|''+C7+''|''+C8+''|''+C9 # # #
C3+C4+C5+C6+C8+''|''+C7+''|''+C6+''|''+C8+''|''+C9+''|''+C10',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = '',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = 'RN_PRINT_169',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-13 15:25:32.220',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-13 15:25:32.220'
	BEGIN
		SELECT @vcMessage = 'Форма 0503169M_БД с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503169M_БД с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-13 15:25:32.220. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (янв 13 2015  3:25:32:233PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503169M_БК (Сведения по дебиторской и кредиторской задолженности (Бюдж, Кредит))
-- Дата ввода : 20121231
-- Дата окончания действия : 20141231
-- Версия : 2015-01-13 15:25:32.233
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503169M_БК' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2015-01-13 15:25:32.233',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Сведения по дебиторской и кредиторской задолженности (Бюдж, Кредит)',
    [ExportCode]          = '269       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 6,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = 'svodprint_new_gen()',
    [QUERY_ADD_MODULE]    = 'sv_0503169g_20121231.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503169g_bk_20121231.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + RTRIM(COL6) + ''|'' + RTRIM(COL7) + ''|'' #
REPLACE(LEFT(COL10,3)+''|''+SUBSTRING(COL10,4,14)+''|''+SUBSTRING(COL10,18,1)+''|''+SUBSTRING(COL10,19,5)+''|''+SUBSTRING(COL10,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL6)) +''|'' + LTRIM(STR(COL7)) + ''|'' + LTRIM(STR(COL8)) + ''|'' + LTRIM(STR(COL9)) + ''|'' # 
REPLACE(LEFT(COL8,3)+''|''+SUBSTRING(COL8,4,14)+''|''+SUBSTRING(COL8,18,1)+''|''+SUBSTRING(COL8,19,5)+''|''+SUBSTRING(COL8,24,3),''000|00000000000000'',''***|**************'')+''|''+LTRIM(STR(COL4)) +''|'' + LTRIM(STR(COL5)) + ''|'' + LTRIM(STR(COL6)) + ''|'' + LTRIM(STR(COL7)) + ''|''  #
''000|00000000000000|''+LEFT(COL7,1)+''|''+SUBSTRING(COL7,2,5)+''|''+SUBSTRING(COL7,7,3)+''|''+dbo.RO_EXP(COL3)+''|''+LTRIM(STR(COL2)) +''|'' + dbo.RO_EXP(COL4) + ''|'' + dbo.RO_EXP(COL5) + ''|'' + dbo.RO_EXP(COL6) + ''|''',
    [PARAM_IMPORT]        = 'REPLACE(C1+C2+C3+C4+C5,''*****************'',''00000000000000000'')+''|''+C6+''|''+C7+''|''+C8+''|''+C9 # # #
C3+C4+C5+C6+C8+''|''+C7+''|''+C6+''|''+C8+''|''+C9+''|''+C10',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = '',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = 'RN_PRINT_169',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2015-01-13 15:25:32.233',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2015-01-13 15:25:32.233'
	BEGIN
		SELECT @vcMessage = 'Форма 0503169M_БК с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503169M_БК с версией от ' + @vcMessage + ' не может быть обновлена версией от 2015-01-13 15:25:32.233. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:35:46:920PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503230G (Разделительный (ликвидационный) баланс (гл)распоряд., получ бюдж. ср-в)
-- Дата ввода : 20130101
-- Дата окончания действия : 20141230
-- Версия : 2014-12-27 13:35:46.920
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503230G' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:35:46.920',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Разделительный (ликвидационный) баланс (гл)распоряд., получ бюдж. ср-в',
    [ExportCode]          = '230r      ',
    [START_DATE]          = '20130101',
    [END_DATE]            = '20141230',
    [PERIODIC]            = 7,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'sv_0503230g_20130101.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'sv_0503230G_20130101.xlt',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RA_EXPORT_FORM_STANDART',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL2)+''|''+STR(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''#RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7#C1+''|''+C2+''|''+C3+''|''',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '191н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:35:46.920',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:35:46.920'
	BEGIN
		SELECT @vcMessage = 'Форма 0503230G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503230G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:35:46.920. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:34:15:950PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503721G (Отчет о финансовых результатах деятельности учреждения)
-- Дата ввода : 20121231
-- Дата окончания действия : 20141230
-- Версия : 2014-12-27 13:34:15.950
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503721G' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:34:15.950',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Отчет о финансовых результатах деятельности учреждения',
    [ExportCode]          = '321       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141230',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'SV_0503721_20110101.BAS',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'SV_0503721_20121231.XLT',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RO_EXPORT_FORM_33',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL2) + ''|'' + RIGHT(''***'' + RTRIM(REPLACE(COL3,''X'','''')),3) + ''|'' + STR(COL4) + ''|'' + STR(COL5) + ''|'' + STR(COL6) + ''|'' + STR(COL7) + ''|''',
    [PARAM_IMPORT]        = 'C1 + ''|''  + C2 + ''|''+C3 + ''|''  + C4 + ''|'' + C5 + ''|'' + C6 + ''|'' + C7',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_TYPE_ORG',
    [SvodProc]            = NULL,
    [COMMENT]             = '33н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:34:15.950',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:34:15.950'
	BEGIN
		SELECT @vcMessage = 'Форма 0503721G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503721G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:34:15.950. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 27 2014  1:37:19:370PM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503730G_BU (Баланс государственного (муниципального) учреждения)
-- Дата ввода : 20121231
-- Дата окончания действия : 20141230
-- Версия : 2014-12-27 13:37:19.370
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503730G_BU' AND [START_DATE] = '20121231'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-27 13:37:19.370',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Баланс государственного (муниципального) учреждения',
    [ExportCode]          = '330       ',
    [START_DATE]          = '20121231',
    [END_DATE]            = '20141230',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'SV_0503730G_20121231.bas',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'SV_0503730G_20121231.XLT',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RO_EXPORT_FORM_33',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'LEFT(RTRIM(COL2) + ''0000'',4)+''|''+STR(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''#
RTRIM(COL1)+''|''+RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''',
    [PARAM_IMPORT]        = 'LEFT(C1,3)+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''+C9 # 
C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_TYPE_ORG,REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '33н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-27 13:37:19.370',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-27 13:37:19.370'
	BEGIN
		SELECT @vcMessage = 'Форма 0503730G_BU с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503730G_BU с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-27 13:37:19.370. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 30 2014  7:58:20:120AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 0503830G (Разделительный (ликвидационный) баланс государственного (муниципального) учреждения)
-- Дата ввода : 20130101
-- Дата окончания действия : 20141231
-- Версия : 2014-12-30 07:58:20.120
-- Параметры выгрузки :
-- только обновить  REPORT_FORMS              : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '0503830G' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-30 07:58:20.120',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Обновление только REPORT_FORMS.
UPDATE dbo.[REPORT_FORMS]
SET [NAME]                = 'Разделительный (ликвидационный) баланс государственного (муниципального) учреждения',
    [ExportCode]          = '331       ',
    [START_DATE]          = '20130101',
    [END_DATE]            = '20141231',
    [PERIODIC]            = 1,
    [ISSVOD]              = 1,
    [ISEXPORTED]          = 1,
    [ISUSERFORM]          = 1,
    [IsKonsolid]          = 0,
    [IS_AUTOFILL]         = 0,
    [PRINT_OBJECT_METHOD] = '',
    [QUERY_ADD_MODULE]    = 'SV_0503830G_20121231.BAS',
    [QUERY_BEFORE]        = '',
    [QUERY_REPMAKER]      = 'KirRepMakerMultiSheet.xls',
    [QUERY_REPORT]        = 'SV_0503830G_20130101.XLT',
    [QUERY_REPORT_PATH]   = '',
    [DECRIPT_PROC]        = NULL,
    [EXPORT_PROC]         = 'RO_EXPORT_FORM_33',
    [IsRemoteAccess]      = 0,
    [PARAM_EXPORT]        = 'RTRIM(COL2)+''|''+STR(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''+STR(COL10)+''|''#RTRIM(COL1)+''|''+RTRIM(COL3)+''|''+STR(COL4)+''|''+STR(COL5)+''|''+STR(COL6)+''|''+STR(COL7)+''|''+STR(COL8)+''|''+STR(COL9)+''|''',
    [PARAM_IMPORT]        = 'C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''+C9#C1+''|''+C2+''|''+C3+''|''+C4+''|''+C5+''|''+C6+''|''+C7+''|''+C8+''|''',
    [OBJECT]              = NULL,
    [ATRIBUTS]            = 'REPORTS_ATR_TYPE_ORG,REPORTS_FILTER_KBK',
    [SvodProc]            = NULL,
    [COMMENT]             = '33н',
    [PRINT_OBJECT_METHOD_NEW] = NULL,
    [QUERY_BEFORE_PRINT_NEW]  = '',
    [QUERY_REPORT_NEW]        = '',
    [IS_CALC]        = 1
WHERE [LINK_FORM] = @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-30 07:58:20.120',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-30 07:58:20.120'
	BEGIN
		SELECT @vcMessage = 'Форма 0503830G с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 0503830G с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-30 07:58:20.120. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (ноя 17 2014 10:53:21:803AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 4fss (Расчетная ведомость по средствам ФСС РФ)
-- Дата ввода : 20140101
-- Дата окончания действия :
-- Версия : 2014-11-17 10:53:21.803
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : нет
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.


DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '4fss' AND [START_DATE] = '20140101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-11-17 10:53:21.803',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

IF @iOLD_FORM_LINK IS NOT NULL
BEGIN
   SET @vcNEW_FORM_CODE = LEFT('NEW_' + '4fss',20)
   SELECT @dNEW_START_DATE = MAX([START_DATE]) + 1    FROM dbo.[REPORT_FORMS]    WHERE [CODE] = @vcNEW_FORM_CODE
END
ELSE BEGIN
   SET @vcNEW_FORM_CODE = '4fss'
END

SET @dNEW_START_DATE = ISNULL(@dNEW_START_DATE,'20140101')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_FORMS.
SELECT @iFORM_TYPE = [LINK] FROM dbo.[S_OBJECTS] WHERE [CODE] = 'SALARY'
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_FORMS]  @iLINK_FORM OUTPUT,'Расчетная ведомость по средствам ФСС РФ',@vcNEW_FORM_CODE,@dNEW_START_DATE,2,0,0,1,2291,'i_report_export_nalog',0,0,'19000101',NULL,''
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_FORMS',@iERROR)
END

EXEC @iERROR = dbo.[RN_REPORT_SAVE_REPORT_FORMS_PART2]  @iLINK_FORM, 'sa_print_4FSS_110214()','4FSS_110214.bas','','KirRepMakerMultiSheet.XLS','4FSS_110214.xlt','',NULL,'i_report_export_nalog',0,NULL,NULL,NULL,'          ','REPORTS_ATR_NOM_OBR',NULL,NULL,'|',1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_REPORT_SAVE_REPORT_FORMS_PART2',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_TABLES.
SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р0. Титул', @iLINK_FORM,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование',@iLINK_TABLE,0,1,0,0,0,0,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,1,0,0,0,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Всего с начала года',@iLINK_TABLE,1,0,3,1,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р0. Титул', @iLINK_FORM,1, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.1 Расчёты по обяз. страхованию', @iLINK_FORM,2
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование',@iLINK_TABLE,0,1,0,0,250,0,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,1,0,0,0,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Сумма',@iLINK_TABLE,0,0,3,2,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Номер платеж. поручения',@iLINK_TABLE,0,1,4,0,254,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.1 Расчёты по обяз. страхованию', @iLINK_FORM,2, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.2. Расходы на цели обязат. соц. страх', @iLINK_FORM,3
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование статей',@iLINK_TABLE,0,1,0,0,0,0,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Число случаев / количество получателей',@iLINK_TABLE,0,0,2,1,0,1,NULL,NULL,NULL,'999999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Количество дней, выплат, пособий',@iLINK_TABLE,0,0,3,2,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Расходы. Всего',@iLINK_TABLE,0,0,4,3,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Расходы. в т.ч. выплаты за счет средств федерального бюджета',@iLINK_TABLE,0,0,5,4,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.2. Расходы на цели обязат. соц. страх', @iLINK_FORM,3, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.3. Расчет базы для взносов ФСС', @iLINK_FORM,4
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование',@iLINK_TABLE,1,1,1,0,250,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строк',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Всего с начала расчетного периода',@iLINK_TABLE,1,0,3,3,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'В т.ч. сумма за 1 мес отч. квартала',@iLINK_TABLE,1,0,4,4,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'В т.ч. сумма за 2 мес отч. квартала',@iLINK_TABLE,1,0,5,5,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'В т.ч. сумма за 3 мес отч. квартала',@iLINK_TABLE,1,0,6,6,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.3. Расчет базы для взносов ФСС', @iLINK_FORM,4, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.3.1. Сведения, для применения пониженного', @iLINK_FORM,5
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'№ п/п',@iLINK_TABLE,1,1,1,0,4,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Фамилия имя отчество',@iLINK_TABLE,1,1,2,0,100,1,'KU_PERSON_FIO','COL2','CODE',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Дата справки',@iLINK_TABLE,1,1,3,0,10,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Срок действия',@iLINK_TABLE,1,1,4,0,10,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Всего с начала расчетного периода',@iLINK_TABLE,1,0,5,5,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'В т.ч. сумма за 1 мес отч. квартала',@iLINK_TABLE,1,0,6,6,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'В т.ч. сумма за 2 мес отч. квартала',@iLINK_TABLE,1,0,7,7,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'В т.ч. сумма за 3 мес отч. квартала',@iLINK_TABLE,1,0,8,8,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.3.1. Сведения, для применения пониженного', @iLINK_FORM,5, @iLINK_CODE_COL,1,'CALC_SMETA=exec dbo.SA_4FSS_28022011_PREPARE_INV @Lsf',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4. Условия применения пониж. тарифа таб.1', @iLINK_FORM,6
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Всего с начала расчетного периода',@iLINK_TABLE,1,0,3,3,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'В т.ч. сумма за 1 мес отч. квартала',@iLINK_TABLE,1,0,4,4,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'В т.ч. сумма за 2 мес отч. квартала',@iLINK_TABLE,1,0,5,5,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'В т.ч. сумма за 3 мес отч. квартала',@iLINK_TABLE,1,0,6,6,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4. Условия применения пониж. тарифа таб.1', @iLINK_FORM,6, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4.1 Условия применения пониж. тарифа таб.2', @iLINK_FORM,7
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Всего с начала расчетного периода',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'В т.ч. сумма за 1 мес отч. квартала',@iLINK_TABLE,1,0,4,4,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'В т.ч. сумма за 2 мес отч. квартала',@iLINK_TABLE,1,0,5,5,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'В т.ч. сумма за 3 мес отч. квартала',@iLINK_TABLE,1,0,6,6,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4.1 Условия применения пониж. тарифа таб.2', @iLINK_FORM,7, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4.2. Расчёт условий для орг. инф. техн.', @iLINK_FORM,8
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'По итогам  9-ти месяцев года, предшествующего текущему расчетному пери',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'По итогам текущего отчетного (расчетного) периода',@iLINK_TABLE,1,0,4,4,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Дата записи в реестре аккредитованных организаций',@iLINK_TABLE,1,1,5,5,10,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'№ записи в реестре аккредитованных организаций',@iLINK_TABLE,1,1,6,6,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4.2. Расчёт условий для орг. инф. техн.', @iLINK_FORM,8, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4.3. Расчёт условий для орг. и и.п. - упро', @iLINK_FORM,9
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,0,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'С начала отчетного (расчетного) периода',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4.3. Расчёт условий для орг. и и.п. - упро', @iLINK_FORM,9, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4.4. Расчёт условий для некомерч. орг.', @iLINK_FORM,10
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,0,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'По итогам года, предшествующего текущему расчетному периоду',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'По итогам текущего расчетного периода',@iLINK_TABLE,1,0,4,4,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4.4. Расчёт условий для некомерч. орг.', @iLINK_FORM,10, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.4.5.Свед., для прим. пониж. тарифа п14 ч1', @iLINK_FORM,11
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'№ п/п',@iLINK_TABLE,1,1,1,0,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'№ патента',@iLINK_TABLE,1,1,2,0,10,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Вид предпринимательской деятельности, установленный законом субъекта Российской Федерации',@iLINK_TABLE,1,1,3,0,254,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Сведения из патента - дата начала действия',@iLINK_TABLE,1,1,4,0,10,1,NULL,NULL,NULL,'99.99.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Сведения из патента - дата окончания действия',@iLINK_TABLE,1,1,5,0,10,1,NULL,NULL,NULL,'99.99.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Всего с начала расчетного периода',@iLINK_TABLE,0,0,6,0,2,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'В т.ч. за последние три месяца о.п. - 1 месяц',@iLINK_TABLE,1,0,7,0,2,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'В т.ч. за последние три месяца о.п. - 2 месяц',@iLINK_TABLE,1,0,8,0,2,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'В т.ч. за последние три месяца о.п. - 3 месяц',@iLINK_TABLE,1,0,9,0,2,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.4.5.Свед., для прим. пониж. тарифа п14 ч1', @iLINK_FORM,11, @iLINK_CODE_COL,1,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р1.Табл.5. Выпл. за счёт средств Федерал. бюджета', @iLINK_FORM,12
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование статей',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Всего число получателей',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Всего количество дней, выплат, пособий',@iLINK_TABLE,1,0,4,4,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Всего расходы (сумма)',@iLINK_TABLE,1,0,5,5,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'В т.ч. Чернобыльская АЭС число получателей',@iLINK_TABLE,1,0,6,6,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'В т.ч. Чернобыльская АЭС количество дней, выплат, пособий',@iLINK_TABLE,1,0,7,7,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'В т.ч. Чернобыльская АЭС расходы (сумма)',@iLINK_TABLE,1,0,8,8,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'В т.ч. ПО "Маяк" число получателей',@iLINK_TABLE,1,0,9,9,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'В т.ч. ПО "Маяк" количество дней, выплат, пособий',@iLINK_TABLE,1,0,10,10,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'В т.ч. ПО "Маяк" расходы (сумма)',@iLINK_TABLE,1,0,11,11,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'В т.ч. Семипалатинский полигон число получателей',@iLINK_TABLE,1,0,12,12,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'В т.ч. Семипалатинский полигон количество дней, выплат, пособий',@iLINK_TABLE,1,0,13,13,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'В т.ч. Семипалатинский полигон расходы (сумма)',@iLINK_TABLE,1,0,14,14,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'В т.ч. подразделения особого риска число получателей',@iLINK_TABLE,1,0,15,15,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 16,'В т.ч. подразделения особого риска количество дней, выплат, пособий',@iLINK_TABLE,1,0,16,16,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 17,'В т.ч. подразделения особого риска расходы (сумма)',@iLINK_TABLE,1,0,17,17,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 18,'В т.ч. доп.выпл. по № 255-ФЗ число получателей',@iLINK_TABLE,1,0,18,18,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 19,'В т.ч. доп.выпл. по № 255-ФЗ количество дней, выплат, пособий',@iLINK_TABLE,1,0,19,19,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 20,'В т.ч. доп.выпл. по № 255-ФЗ расходы (сумма)',@iLINK_TABLE,1,0,20,20,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р1.Табл.5. Выпл. за счёт средств Федерал. бюджета', @iLINK_FORM,12, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р2.Табл.6. Несчастные случаи - база', @iLINK_FORM,13
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Выплаты, на которые начисляются стр. взносы, всего',@iLINK_TABLE,1,0,3,3,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'в.т.ч. выплаты инвалидам, на которые начисляются стр. взносы',@iLINK_TABLE,1,0,4,4,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Выплаты , на которые не начисляются стр. взносы',@iLINK_TABLE,1,0,5,5,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Размер страхового тарифа',@iLINK_TABLE,1,0,6,6,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Скидка к страховому тарифу',@iLINK_TABLE,1,0,7,7,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Дата установления надбавки к стр. тарифу',@iLINK_TABLE,1,1,8,9,10,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'% надбавки к стр. тарифу',@iLINK_TABLE,1,0,9,9,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Размер тарифа с учётом скидки (надбавки)',@iLINK_TABLE,1,0,10,10,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р2.Табл.6. Несчастные случаи - база', @iLINK_FORM,13, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р2.Табл.7. Несчастные случаи - расчёт', @iLINK_FORM,14
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Сумма (руб.коп.)',@iLINK_TABLE,1,0,3,3,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Номер платеж. поручения',@iLINK_TABLE,1,1,4,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р2.Табл.7. Несчастные случаи - расчёт', @iLINK_FORM,14, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р2.Табл.8. Расходы по страхованию от несч. случ.', @iLINK_FORM,15
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование статей',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Количество дней',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Сумма (руб., коп.)',@iLINK_TABLE,1,0,4,4,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р2.Табл.8. Расходы по страхованию от несч. случ.', @iLINK_FORM,15, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р2.Табл.9. Численность пострадавших по стр. случ.', @iLINK_FORM,16
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Численность пострадавших человек',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р2.Табл.9. Численность пострадавших по стр. случ.', @iLINK_FORM,16, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Р2.Табл.10. Свед. о рез. провед. спец. оценке усл.', @iLINK_FORM,17
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Наименование показателя',@iLINK_TABLE,0,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код строки',@iLINK_TABLE,1,1,2,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Общее количество рабочих мест страхователя',@iLINK_TABLE,1,0,3,3,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Кол. раб. мест, в отн. усл.труд. на которых провед. спец.оценка у.т. - на начало года',@iLINK_TABLE,1,0,4,4,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Кол. раб. мест, на которых провед. спец.оценка. Вред и опасн классы  - 3 класс',@iLINK_TABLE,1,0,6,6,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Кол. раб. мест, на которых провед. спец. оценка. Вред и опасн классы  - 4 класс',@iLINK_TABLE,1,0,7,7,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Общ. число. раб., на вред. и (или) опас. производст. подлежащих медосмот',@iLINK_TABLE,1,0,8,8,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Кол. раб., на вред. и (или) опас. производ. прошедших медосмотр на нач',@iLINK_TABLE,1,0,9,9,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Р2.Табл.10. Свед. о рез. провед. спец. оценке усл.', @iLINK_FORM,17, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

DECLARE @iError INT

-- Выгрузка строк статических таблиц.
IF OBJECT_ID('tempdb..#R') IS NOT NULL
BEGIN
   DROP TABLE #R
END

CREATE TABLE #R([ORDERS]      SMALLINT,
                [LINK_TABLE]  INT,
                [CALC_ORDERS] SMALLINT,
                [PRINT_NULL]  TINYINT)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #R',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN
INSERT #R VALUES (1,1,1,1)
INSERT #R VALUES (2,1,3,1)
INSERT #R VALUES (3,1,4,1)
INSERT #R VALUES (4,1,4,1)
INSERT #R VALUES (1,2,1,1)
INSERT #R VALUES (2,2,2,1)
INSERT #R VALUES (3,2,34,1)
INSERT #R VALUES (4,2,4,1)
INSERT #R VALUES (5,2,33,1)
INSERT #R VALUES (6,2,6,1)
INSERT #R VALUES (7,2,7,1)
INSERT #R VALUES (8,2,8,1)
INSERT #R VALUES (9,2,34,1)
INSERT #R VALUES (10,2,10,1)
INSERT #R VALUES (11,2,33,1)
INSERT #R VALUES (12,2,12,1)
INSERT #R VALUES (13,2,13,1)
INSERT #R VALUES (14,2,14,1)
INSERT #R VALUES (15,2,34,1)
INSERT #R VALUES (16,2,16,1)
INSERT #R VALUES (17,2,33,1)
INSERT #R VALUES (18,2,18,1)
INSERT #R VALUES (19,2,19,1)
INSERT #R VALUES (20,2,20,1)
INSERT #R VALUES (21,2,34,1)
INSERT #R VALUES (22,2,22,1)
INSERT #R VALUES (23,2,33,1)
INSERT #R VALUES (24,2,24,1)
INSERT #R VALUES (25,2,25,1)
INSERT #R VALUES (26,2,26,1)
INSERT #R VALUES (27,2,34,1)
INSERT #R VALUES (28,2,28,1)
INSERT #R VALUES (29,2,33,1)
INSERT #R VALUES (30,2,30,1)
INSERT #R VALUES (31,2,31,1)
INSERT #R VALUES (32,2,32,1)
INSERT #R VALUES (33,2,55,1)
INSERT #R VALUES (34,2,34,1)
INSERT #R VALUES (35,2,35,1)
INSERT #R VALUES (36,2,36,1)
INSERT #R VALUES (37,2,37,1)
INSERT #R VALUES (38,2,38,1)
INSERT #R VALUES (39,2,39,1)
INSERT #R VALUES (40,2,53,1)
INSERT #R VALUES (41,2,41,1)
INSERT #R VALUES (42,2,52,1)
INSERT #R VALUES (43,2,43,1)
INSERT #R VALUES (44,2,44,1)
INSERT #R VALUES (45,2,45,1)
INSERT #R VALUES (46,2,53,1)
INSERT #R VALUES (47,2,47,1)
INSERT #R VALUES (48,2,52,1)
INSERT #R VALUES (49,2,49,1)
INSERT #R VALUES (50,2,50,1)
INSERT #R VALUES (1,3,2,1)
INSERT #R VALUES (2,3,1,1)
INSERT #R VALUES (3,3,2,1)
INSERT #R VALUES (4,3,1,1)
INSERT #R VALUES (5,3,3,1)
INSERT #R VALUES (6,3,2,1)
INSERT #R VALUES (7,3,1,1)
INSERT #R VALUES (8,3,2,1)
INSERT #R VALUES (9,3,1,1)
INSERT #R VALUES (10,3,1,1)
INSERT #R VALUES (11,3,1,1)
INSERT #R VALUES (12,3,4,1)
INSERT #R VALUES (1,4,1,1)
INSERT #R VALUES (2,4,2,1)
INSERT #R VALUES (3,4,3,1)
INSERT #R VALUES (4,4,4,1)
INSERT #R VALUES (5,4,5,1)
INSERT #R VALUES (6,4,6,1)
INSERT #R VALUES (7,4,7,1)
INSERT #R VALUES (8,4,8,1)
INSERT #R VALUES (1,6,1,1)
INSERT #R VALUES (2,6,2,1)
INSERT #R VALUES (3,6,4,1)
INSERT #R VALUES (1,7,1,1)
INSERT #R VALUES (2,7,2,1)
INSERT #R VALUES (3,7,4,1)
INSERT #R VALUES (4,7,5,1)
INSERT #R VALUES (5,7,6,1)
INSERT #R VALUES (6,7,7,1)
INSERT #R VALUES (1,8,1,1)
INSERT #R VALUES (2,8,3,1)
INSERT #R VALUES (3,8,4,1)
INSERT #R VALUES (4,8,5,1)
INSERT #R VALUES (5,8,6,1)
INSERT #R VALUES (1,9,1,1)
INSERT #R VALUES (2,9,2,1)
INSERT #R VALUES (3,9,3,1)
INSERT #R VALUES (1,10,1,1)
INSERT #R VALUES (2,10,2,1)
INSERT #R VALUES (3,10,3,1)
INSERT #R VALUES (4,10,4,1)
INSERT #R VALUES (5,10,5,1)
INSERT #R VALUES (1,12,1,1)
INSERT #R VALUES (2,12,3,1)
INSERT #R VALUES (3,12,4,1)
INSERT #R VALUES (4,12,5,1)
INSERT #R VALUES (5,12,6,1)
INSERT #R VALUES (6,12,7,1)
INSERT #R VALUES (7,12,8,1)
INSERT #R VALUES (1,13,1,1)
INSERT #R VALUES (2,13,3,1)
INSERT #R VALUES (3,13,4,1)
INSERT #R VALUES (4,13,5,1)
INSERT #R VALUES (5,13,6,1)
INSERT #R VALUES (1,14,1,1)
INSERT #R VALUES (2,14,3,1)
INSERT #R VALUES (3,14,4,1)
INSERT #R VALUES (4,14,5,1)
INSERT #R VALUES (5,14,6,1)
INSERT #R VALUES (6,14,7,1)
INSERT #R VALUES (7,14,8,1)
INSERT #R VALUES (8,14,9,1)
INSERT #R VALUES (9,14,10,1)
INSERT #R VALUES (10,14,11,1)
INSERT #R VALUES (11,14,12,1)
INSERT #R VALUES (12,14,13,1)
INSERT #R VALUES (13,14,14,1)
INSERT #R VALUES (14,14,15,1)
INSERT #R VALUES (15,14,16,1)
INSERT #R VALUES (16,14,17,1)
INSERT #R VALUES (17,14,18,1)
INSERT #R VALUES (18,14,19,1)
INSERT #R VALUES (19,14,20,1)
INSERT #R VALUES (20,14,21,1)
INSERT #R VALUES (21,14,22,1)
INSERT #R VALUES (22,14,23,1)
INSERT #R VALUES (23,14,24,1)
INSERT #R VALUES (24,14,25,1)
INSERT #R VALUES (25,14,26,1)
INSERT #R VALUES (26,14,27,1)
INSERT #R VALUES (27,14,28,1)
INSERT #R VALUES (28,14,29,1)
INSERT #R VALUES (29,14,30,1)
INSERT #R VALUES (30,14,31,1)
INSERT #R VALUES (31,14,32,1)
INSERT #R VALUES (1,15,1,1)
INSERT #R VALUES (2,15,3,1)
INSERT #R VALUES (3,15,4,1)
INSERT #R VALUES (4,15,5,1)
INSERT #R VALUES (5,15,6,1)
INSERT #R VALUES (6,15,7,1)
INSERT #R VALUES (7,15,8,1)
INSERT #R VALUES (8,15,9,1)
INSERT #R VALUES (9,15,10,1)
INSERT #R VALUES (10,15,11,1)
INSERT #R VALUES (1,16,1,1)
INSERT #R VALUES (2,16,3,1)
INSERT #R VALUES (3,16,4,1)
INSERT #R VALUES (4,16,5,1)
INSERT #R VALUES (5,16,6,1)
INSERT #R VALUES (1,17,1,1)
INSERT #R VALUES (2,17,2,1)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #R) <> 156
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #R',0)
END

ALTER TABLE dbo.[REPORT_ROWS] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_ROWS] ([ORDERS],
                          [LINK_TABLE],
                          [CALC_ORDERS],
                          [PRINT_NULL])
SELECT [C].[ORDERS],
       [B].[LINK_TABLE],
       [C].[CALC_ORDERS],
       [C].[PRINT_NULL]
FROM #tabInfo            [A]
JOIN dbo.[REPORT_TABLES] [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN #R                  [C] ON [B].[ORDERS] = [C].[LINK_TABLE]

ALTER TABLE dbo.[REPORT_ROWS] ENABLE TRIGGER ALL

DROP TABLE #R

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

-- Выгрузка REPORT_FORMULA.
IF OBJECT_ID('tempdb..#F') IS NOT NULL
BEGIN
   DROP TABLE #F
END

CREATE TABLE #F([ORDER_TABLE] INT,
                [ORDER_ROW]   INT,
                [ORDER_COL]   INT,
                [FORMULA]  VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #F',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
INSERT #F VALUES (1,1,1,'Численность работников                                                                                                                                                                                                                                        ')
INSERT #F VALUES (1,2,1,'из них: женщин                                                                                                                                                                                                                                            ')
INSERT #F VALUES (1,3,1,'работающих инвалидов                                                                                                                                                                                                                                      ')
INSERT #F VALUES (1,4,1,'работающих, занятых на работах с вредными и (или) опасными производственными факторами                                                                                                                                                                    ')
INSERT #F VALUES (1,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (1,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (1,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (1,4,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (1,1,3,'4ФСС_09022012_УСТАНОВКА() + 4ФСС_РАЗДЕЛ1(К.СТР.,6)')
INSERT #F VALUES (1,2,3,'4ФСС_РАЗДЕЛ1(К.СТР.,6)')
INSERT #F VALUES (1,3,3,'4ФСС_РАЗДЕЛ1(К.СТР.,6)')
INSERT #F VALUES (1,4,3,'4ФСС_РАЗДЕЛ1(К.СТР.,6)')
INSERT #F VALUES (2,1,1,'Задолженность за страхователем на начало расчетного периода                                                                                                                                                                                               ')
INSERT #F VALUES (2,2,1,'Начислено страховых взносов                                                                                                                                                                                                                               ')
INSERT #F VALUES (2,3,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,4,1,'за отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,5,1,'1 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,6,1,'2 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,7,1,'3 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,8,1,'Начислено страховых взносов по актам проверок                                                                                                                                                                                                             ')
INSERT #F VALUES (2,9,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,10,1,'за отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,11,1,'1 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,12,1,'2 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,13,1,'3 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,14,1,'Начислено страховых взносов страхователем за прошлые годы                                                                                                                                                                                                 ')
INSERT #F VALUES (2,15,1,'Не принято к зачету расходов территориальным органом Фонда                                                                                                                                                                                                ')
INSERT #F VALUES (2,16,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,17,1,'за отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,18,1,'1 месяц')
INSERT #F VALUES (2,19,1,'2 месяц')
INSERT #F VALUES (2,20,1,'3 месяц')
INSERT #F VALUES (2,21,1,'Получено от территориального органа Фонда на банковский счет в возмещение произведенных расходов                                                                                                                                                          ')
INSERT #F VALUES (2,22,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,23,1,'за отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,24,1,'1 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,25,1,'2 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,26,1,'3 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,27,1,'Возврат сумм излишне перечисленных страховых взносов                                                                                                                                                                                                      ')
INSERT #F VALUES (2,28,1,'Всего (стр. 1 - 7)                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,29,1,'Задолженность за территориальным органом Фонда на конец отчетного (расчетного) периода                                                                                                                                                                    ')
INSERT #F VALUES (2,30,1,'в том числе: за счет превышения расходов                                                                                                                                                                                                                  ')
INSERT #F VALUES (2,31,1,'                       за счет переплаты страховых взносов                                                                                                                                                                                                ')
INSERT #F VALUES (2,32,1,'Задолженность за территориальным органом Фонда на начало расчетного периода                                                                                                                                                                               ')
INSERT #F VALUES (2,33,1,'в том числе: за счет превышения расходов                                                                                                                                                                                                                  ')
INSERT #F VALUES (2,34,1,'                       за счет переплаты страховых взносов                                                                                                                                                                                                ')
INSERT #F VALUES (2,35,1,'Расходы на цели обязательного социального страхования                                                                                                                                                                                                     ')
INSERT #F VALUES (2,36,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,37,1,'за отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,38,1,'1 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,39,1,'2 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,40,1,'3 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,41,1,'Перечислены страховые взносы                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,42,1,'на начало квартала                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,43,1,'За отчетный квартал (месяцы)                                                                                                                                                                                                                              ')
INSERT #F VALUES (2,44,1,'1 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,45,1,'2 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,46,1,'3 месяц                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,47,1,'Списано                                                                                                                                                                                                                                                   ')
INSERT #F VALUES (2,48,1,'Всего (стр. 12, 15, 16, 17)                                                                                                                                                                                                                               ')
INSERT #F VALUES (2,49,1,'Задолженность за страхователем на конец отчетного (расчетного) периода                                                                                                                                                                                    ')
INSERT #F VALUES (2,50,1,'в том числе недоимка                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (2,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,3,2,'2_1                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,4,2,'2_2                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,5,2,'2_3                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,6,2,'2_4                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,7,2,'2_5                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,8,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,9,2,'3_1                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,10,2,'3_2                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,11,2,'3_3                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,12,2,'3_4                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,13,2,'3_5                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,14,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,15,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,16,2,'5_1                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,17,2,'5_2                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,18,2,'5_3')
INSERT #F VALUES (2,19,2,'5_4')
INSERT #F VALUES (2,20,2,'5_5')
INSERT #F VALUES (2,21,2,'6                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,22,2,'6_1                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,23,2,'6_2                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,24,2,'6_3                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,25,2,'6_4                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,26,2,'6_5                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (2,27,2,'7                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,28,2,'8                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (2,29,2,'9                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (2,30,2,'10                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (2,31,2,'11                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,32,2,'12                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (2,33,2,'13                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (2,34,2,'14                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,35,2,'15                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,36,2,'15_1                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,37,2,'15_2                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,38,2,'15_3                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,39,2,'15_4                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,40,2,'15_5                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,41,2,'16                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,42,2,'16_1                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,43,2,'16_2                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (2,44,2,'16_3                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (2,45,2,'16_4                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (2,46,2,'16_5                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (2,47,2,'17                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,48,2,'18                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,49,2,'19                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (2,50,2,'20                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (2,1,3,'4ФСС_РАЗДЕЛ1(''0101'',3)')
INSERT #F VALUES (2,3,3,'4ФСС_РАЗДЕЛ1(''0121'',3)')
INSERT #F VALUES (2,5,3,'4ФСС_РАЗДЕЛ1(''0123'',3)')
INSERT #F VALUES (2,6,3,'4ФСС_РАЗДЕЛ1(''0124'',3)')
INSERT #F VALUES (2,7,3,'4ФСС_РАЗДЕЛ1(''0125'',3)')
INSERT #F VALUES (2,18,3,'')
INSERT #F VALUES (2,19,3,'')
INSERT #F VALUES (2,20,3,'')
INSERT #F VALUES (2,22,3,'АДТКТ("_.304.05:_.201.11:_.201.21:_.201.27","_.303.02","ДЛЯ ДАТА>=''01.01'' И ДАТА<КВАРТАЛ")')
INSERT #F VALUES (2,24,3,'АДТКТ("_.304.05:_.201.11:_.201.21:_.201.27","_.303.02","ДЛЯ ДАТА=МЕСЯЦ(1)")')
INSERT #F VALUES (2,25,3,'АДТКТ("_.304.05:_.201.11:_.201.21:_.201.27","_.303.02","ДЛЯ ДАТА=МЕСЯЦ(2)")')
INSERT #F VALUES (2,26,3,'АДТКТ("_.304.05:_.201.11:_.201.21:_.201.27","_.303.02","ДЛЯ ДАТА=МЕСЯЦ(3)")')
INSERT #F VALUES (2,29,3,'4ФСС_РАЗДЕЛ1(''0109'',3)')
INSERT #F VALUES (2,30,3,'4ФСС_РАЗДЕЛ1(''0109'',3)')
INSERT #F VALUES (2,32,3,'4ФСС_РАЗДЕЛ1(''0112'',3)')
INSERT #F VALUES (2,33,3,'4ФСС_РАЗДЕЛ1(''0112'',3)')
INSERT #F VALUES (2,36,3,'АДТКТ("_.303.02","_.302.13","ДЛЯ ДАТА>=''01.01'' И ДАТА<КВАРТАЛ")')
INSERT #F VALUES (2,38,3,'АДТКТ("_.303.02","_.302.13","ДЛЯ ДАТА=МЕСЯЦ(1)")')
INSERT #F VALUES (2,39,3,'АДТКТ("_.303.02","_.302.13","ДЛЯ ДАТА=МЕСЯЦ(2)")')
INSERT #F VALUES (2,40,3,'АДТКТ("_.303.02","_.302.13","ДЛЯ ДАТА=МЕСЯЦ(3)")')
INSERT #F VALUES (2,42,3,'АДТКТ("_.303.02","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА>=''01.01'' И ДАТА<КВАРТАЛ")')
INSERT #F VALUES (2,44,3,'АДТКТ("_.303.02","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(1)")')
INSERT #F VALUES (2,45,3,'АДТКТ("_.303.02","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(2)")')
INSERT #F VALUES (2,46,3,'АДТКТ("_.303.02","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(3)")')
INSERT #F VALUES (2,49,3,'4ФСС_РАЗДЕЛ1(''0119'',3)')
INSERT #F VALUES (2,1,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,2,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,3,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,4,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,5,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,6,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,7,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,8,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,9,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,10,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,11,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,12,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,13,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,14,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,15,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,16,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,17,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,18,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,19,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,20,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,21,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,22,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,23,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,24,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,25,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,26,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,27,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,28,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,29,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,30,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,31,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,32,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,33,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,34,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,35,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,36,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,37,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,38,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,39,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,40,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,41,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,42,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,43,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,44,4,'4ФСС_РАЗДЕЛ_ПП1(''01163'',3)')
INSERT #F VALUES (2,45,4,'4ФСС_РАЗДЕЛ_ПП1(''01164'',3)')
INSERT #F VALUES (2,46,4,'4ФСС_РАЗДЕЛ_ПП1(''01165'',3)')
INSERT #F VALUES (2,47,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,48,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,49,4,'ЗАПРЕТ()')
INSERT #F VALUES (2,50,4,'ЗАПРЕТ()')
INSERT #F VALUES (3,1,1,'По временной нетрудоспособности                                                                                                                                                                                                                               ')
INSERT #F VALUES (3,2,1,'      из них: по внешнему совместительству                                                                                                                                                                                                                    ')
INSERT #F VALUES (3,3,1,'По беременности и родам                                                                                                                                                                                                                                       ')
INSERT #F VALUES (3,4,1,'      из них: по внешнему совместительству                                                                                                                                                                                                                    ')
INSERT #F VALUES (3,5,1,'Единовременное пособие женщинам, вставшим на учет в медицинских учреждениях в ранние сроки беременности                                                                                                                                                   ')
INSERT #F VALUES (3,6,1,'Единовременное пособие при рождении ребенка                                                                                                                                                                                                               ')
INSERT #F VALUES (3,7,1,'Ежемесячное пособие по уходу за ребенком                                                                                                                                                                                                                  ')
INSERT #F VALUES (3,8,1,'          в том числе: по уходу за первым ребенком                                                                                                                                                                                                        ')
INSERT #F VALUES (3,9,1,'          по уходу за вторым и последующими детьми                                                                                                                                                                                                        ')
INSERT #F VALUES (3,10,1,'Оплата 4-х дополнительных выходных дней для ухода за детьми-инвалидами                                                                                                                                                                                    ')
INSERT #F VALUES (3,11,1,'Социальное пособие на погребение                                                                                                                                                                                                                          ')
INSERT #F VALUES (3,12,1,'ИТОГО ( сумма строк 1+ 3+ 5+ 6+ 7+ 10+11)                                                                                                                                                                                                                 ')
INSERT #F VALUES (3,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (3,2,2,'2                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (3,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (3,4,2,'4                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (3,5,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (3,6,2,'6                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (3,7,2,'7                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (3,8,2,'8                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (3,9,2,'9                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (3,10,2,'10                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (3,11,2,'11                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (3,12,2,'12                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (3,1,3,'4ФСС_РАЗДЕЛ1(''0201'',7)')
INSERT #F VALUES (3,2,3,'4ФСС_РАЗДЕЛ1(''0202'',7)')
INSERT #F VALUES (3,3,3,'4ФСС_РАЗДЕЛ1(''0203'',7)')
INSERT #F VALUES (3,4,3,'4ФСС_РАЗДЕЛ1(''0204'',7)')
INSERT #F VALUES (3,5,3,'ЗАПРЕТ()')
INSERT #F VALUES (3,6,3,'ЗАПРЕТ()')
INSERT #F VALUES (3,8,3,'4ФСС_РАЗДЕЛ1(''0208'',7)')
INSERT #F VALUES (3,9,3,'4ФСС_РАЗДЕЛ1(''0209'',7)')
INSERT #F VALUES (3,10,3,'ЗАПРЕТ()')
INSERT #F VALUES (3,11,3,'ЗАПРЕТ()')
INSERT #F VALUES (3,12,3,'ЗАПРЕТ()')
INSERT #F VALUES (3,1,4,'4ФСС_РАЗДЕЛ1(''0201'',6)')
INSERT #F VALUES (3,2,4,'4ФСС_РАЗДЕЛ1(''0202'',6)')
INSERT #F VALUES (3,3,4,'4ФСС_РАЗДЕЛ1(''0203'',6)')
INSERT #F VALUES (3,4,4,'4ФСС_РАЗДЕЛ1(''0204'',6)')
INSERT #F VALUES (3,5,4,'4ФСС_РАЗДЕЛ1(''0205'',6) ')
INSERT #F VALUES (3,6,4,'4ФСС_РАЗДЕЛ1(''0206'',6)  ')
INSERT #F VALUES (3,8,4,'4ФСС_РАЗДЕЛ1(''0208'',6)')
INSERT #F VALUES (3,9,4,'4ФСС_РАЗДЕЛ1(''0209'',6)')
INSERT #F VALUES (3,10,4,'4ФСС_РАЗДЕЛ1(''0210'',6)')
INSERT #F VALUES (3,11,4,'4ФСС_РАЗДЕЛ1(''0211'',6)')
INSERT #F VALUES (3,1,5,'4ФСС_РАЗДЕЛ1(''0201'',3)')
INSERT #F VALUES (3,2,5,'4ФСС_РАЗДЕЛ1(''0202'',3)')
INSERT #F VALUES (3,3,5,'4ФСС_РАЗДЕЛ1(''0203'',3)')
INSERT #F VALUES (3,4,5,'4ФСС_РАЗДЕЛ1(''0204'',3)')
INSERT #F VALUES (3,5,5,'4ФСС_РАЗДЕЛ1(''0205'',3) ')
INSERT #F VALUES (3,6,5,'4ФСС_РАЗДЕЛ1(''0206'',3)  ')
INSERT #F VALUES (3,8,5,'4ФСС_РАЗДЕЛ1(''0208'',3)')
INSERT #F VALUES (3,9,5,'4ФСС_РАЗДЕЛ1(''0209'',3)')
INSERT #F VALUES (3,10,5,'4ФСС_РАЗДЕЛ1(''0210'',3)')
INSERT #F VALUES (3,11,5,'4ФСС_РАЗДЕЛ1(''0211'',3)')
INSERT #F VALUES (3,5,6,'ЗАПРЕТ()')
INSERT #F VALUES (3,6,6,'ЗАПРЕТ()')
INSERT #F VALUES (4,1,1,'Суммы выплат и иных вознаграждений, начисленных в пользу физических лиц, в соответствии со ст.7 Федерального закона от 24 июля 2009 г. № 212-ФЗ                                                                                                           ')
INSERT #F VALUES (4,2,1,'Суммы, не подлежащие обложению страховыми взносами в соответствии со ст.9 Федерального закона от 24 июля 2009 г. № 212-ФЗ                                                                                                                                 ')
INSERT #F VALUES (4,3,1,'Суммы, превышающие предельную величину базы для начисления страховых взносов, установленную в соответствии со ст. 8 Федерального закона от 24                                                                                                             ')
INSERT #F VALUES (4,4,1,'Итого база для начисления страховых взносов  (строка 1 - строка 2 - строка 3)                                                                                                                                                                             ')
INSERT #F VALUES (4,5,1,'из них: сумма выплат и иных вознаграждений физическим лицам, являющимся инвалидами I, II, III группы                                                                                                                                                      ')
INSERT #F VALUES (4,6,1,'Cумма выплат и иных вознаграждений, производимых физическим лицам в связи с осуществлением фармацевтической деятельности                                                                                                                                  ')
INSERT #F VALUES (4,7,1,'Cумма выплат и иных вознаграждений членам экипажей судов, зарегистрированных в Российском международном реестре судов, за исполнение трудовых обязанностей члена экипажа судна                                                                            ')
INSERT #F VALUES (4,8,1,'Cумма выплат и иных вознаграждений,производимых физическим лицам индивидуальными предпринимателями, применяющими патентную систему налогообложения                                                                                                        ')
INSERT #F VALUES (4,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (4,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (4,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (4,4,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (4,5,2,'5                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (4,6,2,'6                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (4,7,2,'7                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (4,8,2,'8                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (4,1,3,'4ФСС_РАЗДЕЛ1(''030103'',3)')
INSERT #F VALUES (4,2,3,'4ФСС_РАЗДЕЛ1(''030203'',3)')
INSERT #F VALUES (4,3,3,'4ФСС_РАЗДЕЛ1(''030303'',3)')
INSERT #F VALUES (4,5,3,'4ФСС_РАЗДЕЛ1(''030503'',3)')
INSERT #F VALUES (4,6,3,'4ФСС_РАЗДЕЛ1(''030603'',3)')
INSERT #F VALUES (4,7,3,'4ФСС_РАЗДЕЛ1(''030703'',3)')
INSERT #F VALUES (4,8,3,'4ФСС_РАЗДЕЛ1(''030803'',3)')
INSERT #F VALUES (4,1,4,'4ФСС_РАЗДЕЛ1(''030104'',3)')
INSERT #F VALUES (4,2,4,'4ФСС_РАЗДЕЛ1(''030204'',3)')
INSERT #F VALUES (4,3,4,'4ФСС_РАЗДЕЛ1(''030304'',3)')
INSERT #F VALUES (4,5,4,'4ФСС_РАЗДЕЛ1(''030504'',3)')
INSERT #F VALUES (4,6,4,'4ФСС_РАЗДЕЛ1(''030604'',3)')
INSERT #F VALUES (4,7,4,'4ФСС_РАЗДЕЛ1(''030704'',3)')
INSERT #F VALUES (4,8,4,'4ФСС_РАЗДЕЛ1(''030804'',3)')
INSERT #F VALUES (4,1,5,'4ФСС_РАЗДЕЛ1(''030105'',3)')
INSERT #F VALUES (4,2,5,'4ФСС_РАЗДЕЛ1(''030205'',3)')
INSERT #F VALUES (4,3,5,'4ФСС_РАЗДЕЛ1(''030305'',3)')
INSERT #F VALUES (4,5,5,'4ФСС_РАЗДЕЛ1(''030505'',3)')
INSERT #F VALUES (4,6,5,'4ФСС_РАЗДЕЛ1(''030605'',3)')
INSERT #F VALUES (4,7,5,'4ФСС_РАЗДЕЛ1(''030705'',3)')
INSERT #F VALUES (4,8,5,'4ФСС_РАЗДЕЛ1(''030805'',3)')
INSERT #F VALUES (4,1,6,'4ФСС_РАЗДЕЛ1(''030106'',3)')
INSERT #F VALUES (4,2,6,'4ФСС_РАЗДЕЛ1(''030206'',3)')
INSERT #F VALUES (4,3,6,'4ФСС_РАЗДЕЛ1(''030306'',3)')
INSERT #F VALUES (4,5,6,'4ФСС_РАЗДЕЛ1(''030506'',3)')
INSERT #F VALUES (4,6,6,'4ФСС_РАЗДЕЛ1(''030606'',3)')
INSERT #F VALUES (4,7,6,'4ФСС_РАЗДЕЛ1(''030706'',3)')
INSERT #F VALUES (4,8,6,'4ФСС_РАЗДЕЛ1(''030806'',3)')
INSERT #F VALUES (6,1,1,'Численность членов организации, всего (чел.)                                                                                                                                                                                                                  ')
INSERT #F VALUES (6,2,1,'     из них: численность инвалидов и их законных представителей (чел.)                                                                                                                                                                                    ')
INSERT #F VALUES (6,3,1,'Удельный вес, % ( стр.2  / стр.1) х 100                                                                                                                                                                                                                   ')
INSERT #F VALUES (6,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (6,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (6,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (7,1,1,'Среднесписочная численность, всего (чел.)                                                                                                                                                                                                                     ')
INSERT #F VALUES (7,2,1,'  из них: среднесписочная численность инвалидов (чел.)                                                                                                                                                                                                        ')
INSERT #F VALUES (7,3,1,'Удельный вес, % (стр. 5 / стр. 4) х 100                                                                                                                                                                                                                       ')
INSERT #F VALUES (7,4,1,'Фонд оплаты труда,
всего (руб.)                                                                                                                                                                                                                              ')
INSERT #F VALUES (7,5,1,'     из него: заработная плата инвалидов (руб.)                                                                                                                                                                                                               ')
INSERT #F VALUES (7,6,1,'Удельный вес заработной платы инвалидов, % (стр. 8 / стр. 7) х 100                                                                                                                                                                                            ')
INSERT #F VALUES (7,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (7,2,2,'2                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (7,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (7,4,2,'4                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (7,5,2,'5                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (7,6,2,'6                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (8,1,1,' Средняя численность работников/среднесписочная численность работников (чел.)                                                                                                                                                                             ')
INSERT #F VALUES (8,2,1,' Сумма доходов, определяемая в соответствии со статьей 248 Налогового кодекса Российской Федерации, всего (руб.)                                                                                                                                          ')
INSERT #F VALUES (8,3,1,'  из них: сумма доходов, определяемая  исходя из критериев, указанных в пункте 2 части 2.1 или пункте 2 части 2.2 статьи  57 Федерального закона от 24 июля 2009 г. № 212-ФЗ (руб.)                                                                           ')
INSERT #F VALUES (8,4,1,'  доля доходов, определяемая в целях применения  части 5 статьи  58 Федерального закона от 24 июля 2009 г. № 212-ФЗ (%)
(стр.3 / стр. 2) х 100                                                                                                               ')
INSERT #F VALUES (8,5,1,'Сведения из реестра аккредитованных организаций, осуществляющих деятельность в области информационных технологий*                                                                                                                                             ')
INSERT #F VALUES (8,1,2,'1                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (8,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (8,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (8,4,2,'4                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (8,5,2,'5                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (8,5,3,'ЗАПРЕТ()')
INSERT #F VALUES (8,1,5,'ЗАПРЕТ()')
INSERT #F VALUES (8,2,5,'ЗАПРЕТ()')
INSERT #F VALUES (8,3,5,'ЗАПРЕТ()')
INSERT #F VALUES (8,4,5,'ЗАПРЕТ()')
INSERT #F VALUES (8,1,6,'ЗАПРЕТ()')
INSERT #F VALUES (8,2,6,'ЗАПРЕТ()')
INSERT #F VALUES (8,3,6,'ЗАПРЕТ()')
INSERT #F VALUES (8,4,6,'ЗАПРЕТ()')
INSERT #F VALUES (9,1,1,'Сумма доходов, определяемая в соответствии со статьей 346.15 Налогового кодекса Российской Федерации, всего (руб.)                                                                                                                                            ')
INSERT #F VALUES (9,2,1,'  из них: сумма доходов, определяемая в целях применения части 1.4 статьи 58 Федерального закона от 24 июля 2009 г.                                       № 212-ФЗ (руб.)                                                                                     ')
INSERT #F VALUES (9,3,1,'Доля доходов, определяемая в целях применения части 1.4 статьи 58 Федерального закона от 24 июля 2009 г.                                                              № 212-ФЗ (%)
(стр. 2 / стр. 1) х 100                                                   ')
INSERT #F VALUES (9,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (9,2,2,'2                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (9,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (10,1,1,'Сумма доходов*, всего (руб.)                                                                                                                                                                                                                                  ')
INSERT #F VALUES (10,2,1,'из них: сумма доходов в виде целевых поступлений на содержание некоммерческих организаций и ведение ими уставной деятельности, поименованной в пункте 11 части 1 статьи 58 Федерального закона от 24 июля 2009 г. № 212-ФЗ                                    ')
INSERT #F VALUES (10,3,1,'сумма доходов в виде грантов, получаемых для осуществления деятельности, поименованной в пункте 11 части 1 статьи 58 Федерального закона от 24 июля 2009 г. № 212-ФЗ                                                                                          ')
INSERT #F VALUES (10,4,1,'сумма доходов от осуществления видов экономической деятельности, указанных в подпунктах р - ф, я.4 - я.6 пункта 8 части 1 статьи 58 Федерального закона от 24 июля 2009 г. № 212-ФЗ (руб.)                                                                    ')
INSERT #F VALUES (10,5,1,'Доля доходов, определяемая в целях применения части 5.1 статьи 58 Федерального закона от 24 июля 2009 г. № 212-ФЗ (%)
((с. 2 + с. 3 + с.4) / с. 1) х 100                                                                                                     ')
INSERT #F VALUES (10,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (10,2,2,'2                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (10,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (10,4,2,'4                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (10,5,2,'5                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (12,1,1,'Пособие по временной нетрудоспособности                                                                                                                                                                                                                   ')
INSERT #F VALUES (12,2,1,'Пособие по беременности и родам                                                                                                                                                                                                                           ')
INSERT #F VALUES (12,3,1,'Ежемесячное пособие по уходу за ребенком, всего (стр. 4, 5)                                                                                                                                                                                               ')
INSERT #F VALUES (12,4,1,'в том числе: по уходу за первым ребенком                                                                                                                                                                                                                      ')
INSERT #F VALUES (12,5,1,'по уходу за вторым и 
последующими детьми                                                                                                                                                                                                                ')
INSERT #F VALUES (12,6,1,'Социальное пособие на погребение или возмещение стоимости гарантированного перечня услуг по погребению                                                                                                                                                    ')
INSERT #F VALUES (12,7,1,'ВСЕГО (строки 1 - 3, 6)                                                                                                                                                                                                                                   ')
INSERT #F VALUES (12,1,2,'1                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,4,2,'4                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (12,5,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,6,2,'6                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,7,2,'7                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (12,7,4,'ЗАПРЕТ()')
INSERT #F VALUES (12,7,7,'ЗАПРЕТ()')
INSERT #F VALUES (12,7,10,'ЗАПРЕТ()')
INSERT #F VALUES (12,2,12,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,12,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,12,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,12,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,12,'ЗАПРЕТ()')
INSERT #F VALUES (12,2,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,7,13,'ЗАПРЕТ()')
INSERT #F VALUES (12,2,14,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,14,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,14,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,14,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,14,'ЗАПРЕТ()')
INSERT #F VALUES (12,7,16,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,18,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,18,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,18,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,18,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,19,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,19,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,19,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,19,'ЗАПРЕТ()')
INSERT #F VALUES (12,7,19,'ЗАПРЕТ()')
INSERT #F VALUES (12,3,20,'ЗАПРЕТ()')
INSERT #F VALUES (12,4,20,'ЗАПРЕТ()')
INSERT #F VALUES (12,5,20,'ЗАПРЕТ()')
INSERT #F VALUES (12,6,20,'ЗАПРЕТ()')
INSERT #F VALUES (13,1,1,'Всего с начала расчетного  периода                                                                                                                                                                                                                        ')
INSERT #F VALUES (13,2,1,'    В том числе за последние три месяца отчетного периода                                                                                                                                                                                                 ')
INSERT #F VALUES (13,3,1,'       В том числе за 1 месяц                                                                                                                                                                                                                             ')
INSERT #F VALUES (13,4,1,'       В том числе за 2 месяц                                                                                                                                                                                                                             ')
INSERT #F VALUES (13,5,1,'       В том числе за 3 месяц                                                                                                                                                                                                                             ')
INSERT #F VALUES (13,1,2,'1                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (13,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (13,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (13,4,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (13,5,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (13,1,3,'4ФСС_РАЗДЕЛ1(''060103'',3)')
INSERT #F VALUES (13,3,3,'4ФСС_РАЗДЕЛ1(''060303'',3)')
INSERT #F VALUES (13,4,3,'4ФСС_РАЗДЕЛ1(''060403'',3)')
INSERT #F VALUES (13,5,3,'4ФСС_РАЗДЕЛ1(''060503'',3)')
INSERT #F VALUES (13,1,4,'4ФСС_РАЗДЕЛ1(''060104'',3)')
INSERT #F VALUES (13,3,4,'4ФСС_РАЗДЕЛ1(''060304'',3)')
INSERT #F VALUES (13,4,4,'4ФСС_РАЗДЕЛ1(''060404'',3)')
INSERT #F VALUES (13,5,4,'4ФСС_РАЗДЕЛ1(''060504'',3)')
INSERT #F VALUES (13,1,5,'4ФСС_РАЗДЕЛ1(''060105'',3)')
INSERT #F VALUES (13,3,5,'4ФСС_РАЗДЕЛ1(''060305'',3)')
INSERT #F VALUES (13,4,5,'4ФСС_РАЗДЕЛ1(''060405'',3)')
INSERT #F VALUES (13,5,5,'4ФСС_РАЗДЕЛ1(''060505'',3)')
INSERT #F VALUES (13,1,6,'4ФСС_СПРАВОЧНИК(''tax_rate'')')
INSERT #F VALUES (13,2,6,'ЗАПРЕТ()')
INSERT #F VALUES (13,3,6,'ЗАПРЕТ()')
INSERT #F VALUES (13,4,6,'ЗАПРЕТ()')
INSERT #F VALUES (13,5,6,'ЗАПРЕТ()')
INSERT #F VALUES (13,1,7,'4ФСС_СПРАВОЧНИК(''discount'')')
INSERT #F VALUES (13,2,7,'ЗАПРЕТ()')
INSERT #F VALUES (13,3,7,'ЗАПРЕТ()')
INSERT #F VALUES (13,4,7,'ЗАПРЕТ()')
INSERT #F VALUES (13,5,7,'ЗАПРЕТ()')
INSERT #F VALUES (13,1,8,'4ФСС_СПРАВОЧНИК(''raise_date'')')
INSERT #F VALUES (13,2,8,'ЗАПРЕТ()')
INSERT #F VALUES (13,3,8,'ЗАПРЕТ()')
INSERT #F VALUES (13,4,8,'ЗАПРЕТ()')
INSERT #F VALUES (13,5,8,'ЗАПРЕТ()')
INSERT #F VALUES (13,1,9,'4ФСС_СПРАВОЧНИК(''raise_val'')')
INSERT #F VALUES (13,2,9,'ЗАПРЕТ()')
INSERT #F VALUES (13,3,9,'ЗАПРЕТ()')
INSERT #F VALUES (13,4,9,'ЗАПРЕТ()')
INSERT #F VALUES (13,5,9,'ЗАПРЕТ()')
INSERT #F VALUES (13,1,10,'4ФСС_СПРАВОЧНИК(''tax_total'')')
INSERT #F VALUES (13,2,10,'ЗАПРЕТ()')
INSERT #F VALUES (13,3,10,'ЗАПРЕТ()')
INSERT #F VALUES (13,4,10,'ЗАПРЕТ()')
INSERT #F VALUES (13,5,10,'ЗАПРЕТ()')
INSERT #F VALUES (14,1,1,'Задолженность за страхователем на начало расчетного периода                                                                                                                                                                                                   ')
INSERT #F VALUES (14,2,1,'Начислено страховых взносов                                                                                                                                                                                                                               ')
INSERT #F VALUES (14,3,1,'на начало отчетного периода                                                                                                                                                                                                                               ')
INSERT #F VALUES (14,4,1,'за последние три месяца отчетного периода                                                                                                                                                                                                                 ')
INSERT #F VALUES (14,5,1,'          1 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,6,1,'          2 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,7,1,'          3 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,8,1,'Начислено взносов по результатам проверок                                                                                                                                                                                                                 ')
INSERT #F VALUES (14,9,1,'Не принято к зачету расходов территориальным органом Фонда за прошлые расчетные периоды                                                                                                                                                                   ')
INSERT #F VALUES (14,10,1,'Начислено взносов страхователем за прошлые расчетные периоды                                                                                                                                                                                              ')
INSERT #F VALUES (14,11,1,'Получено от территориального органа Фонда на банковский счет                                                                                                                                                                                              ')
INSERT #F VALUES (14,12,1,'Возврат сумм излишне уплаченных (взысканных) страховых взносов                                                                                                                                                                                            ')
INSERT #F VALUES (14,13,1,'Всего  (сумма строк 1+2+3+4+5+6+7)                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,14,1,'Задолженность за территориальным органом Фонда на конец отчетного периода                                                                                                                                                                                     ')
INSERT #F VALUES (14,15,1,'Задолженность за территориальным органом Фонда на начало расчетного периода                                                                                                                                                                                   ')
INSERT #F VALUES (14,16,1,'Расходы по обязательному социальному страхованию                                                                                                                                                                                                          ')
INSERT #F VALUES (14,17,1,'на начало отчетного периода                                                                                                                                                                                                                               ')
INSERT #F VALUES (14,18,1,'за последние три месяца отчетного периода                                                                                                                                                                                                                 ')
INSERT #F VALUES (14,19,1,'          1 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,20,1,'          2 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,21,1,'          3 месяц                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,22,1,'Уплачено страховых взносов                                                                                                                                                                                                                                ')
INSERT #F VALUES (14,23,1,'на начало отчетного периода                                                                                                                                                                                                                               ')
INSERT #F VALUES (14,24,1,'за последние три месяца отчетного периода дата, № платежного  поручения                                                                                                                                                                                   ')
INSERT #F VALUES (14,25,1,'          1 месяц                                                                                                                                                                                                                                             ')
INSERT #F VALUES (14,26,1,'          2 месяц                                                                                                                                                                                                                                             ')
INSERT #F VALUES (14,27,1,'          3 месяц                                                                                                                                                                                                                                             ')
INSERT #F VALUES (14,28,1,'Списанная сумма задолженности страхователя                                                                                                                                                                                                                ')
INSERT #F VALUES (14,29,1,'Всего (сумма строк 10+11+12+13                                                                                                                                                                                                                            ')
INSERT #F VALUES (14,30,1,'Задолженность за страхователем на конец отчетного периода                                                                                                                                                                                                     ')
INSERT #F VALUES (14,31,1,'           в том числе недоимка                                                                                                                                                                                                                           ')
INSERT #F VALUES (14,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (14,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,3,2,'2_1                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (14,4,2,'2_2                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (14,5,2,'2_3                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (14,6,2,'2_4                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (14,7,2,'2_5                                                                                                                                                                                                                                                       ')
INSERT #F VALUES (14,8,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,9,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,10,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,11,2,'6                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,12,2,'7                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,13,2,'8                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (14,14,2,'9                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (14,15,2,'10                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (14,16,2,'11                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,17,2,'11_1                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,18,2,'11_2                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,19,2,'11_3                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,20,2,'11_4                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,21,2,'11_5                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,22,2,'12                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,23,2,'12_1                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,24,2,'12_2                                                                                                                                                                                                                                                      ')
INSERT #F VALUES (14,25,2,'12_3                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (14,26,2,'12_4                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (14,27,2,'12_5                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (14,28,2,'13                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,29,2,'14                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,30,2,'15                                                                                                                                                                                                                                                            ')
INSERT #F VALUES (14,31,2,'16                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (14,1,3,'4ФСС_РАЗДЕЛ1(''0701'',3)')
INSERT #F VALUES (14,3,3,'4ФСС_РАЗДЕЛ1(''1021'',3)')
INSERT #F VALUES (14,5,3,'4ФСС_РАЗДЕЛ1(''1023'',3)')
INSERT #F VALUES (14,6,3,'4ФСС_РАЗДЕЛ1(''1024'',3)')
INSERT #F VALUES (14,7,3,'4ФСС_РАЗДЕЛ1(''1025'',3)')
INSERT #F VALUES (14,11,3,'АДТКТ("_.304.05:_.201.11:_.201.21:_.201.27","_.303.06")')
INSERT #F VALUES (14,14,3,'4ФСС_РАЗДЕЛ1(''0709'',3)')
INSERT #F VALUES (14,15,3,'4ФСС_РАЗДЕЛ1(''0710'',3)')
INSERT #F VALUES (14,17,3,'АДТКТ("_.303.06","_.302.13,"ДЛЯ ДАТА>=''01.01'' И ДАТА<КВАРТАЛ")')
INSERT #F VALUES (14,19,3,'АДТКТ("_.303.06","_.302.13,"ДЛЯ ДАТА=МЕСЯЦ(1)")')
INSERT #F VALUES (14,20,3,'АДТКТ("_.303.06","_.302.13","ДЛЯ ДАТА=МЕСЯЦ(2)")')
INSERT #F VALUES (14,21,3,'АДТКТ("_.303.06","_.302.13","ДЛЯ ДАТА=МЕСЯЦ(3)")')
INSERT #F VALUES (14,23,3,'АДТКТ("_.303.06","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА>=''01.01'' И ДАТА<КВАРТАЛ")')
INSERT #F VALUES (14,25,3,'АДТКТ("_.303.06","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(1)")')
INSERT #F VALUES (14,26,3,'АДТКТ("_.303.06","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(2)")')
INSERT #F VALUES (14,27,3,'АДТКТ("_.303.06","_.304.05:_.201.11:_.201.21:_.201.27","ДЛЯ ДАТА=МЕСЯЦ(3)")')
INSERT #F VALUES (14,30,3,'4ФСС_РАЗДЕЛ1(''0715'',3)')
INSERT #F VALUES (14,1,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,2,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,3,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,4,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,5,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,6,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,7,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,8,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,9,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,10,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,11,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,12,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,13,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,14,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,15,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,16,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,17,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,18,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,19,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,20,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,21,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,22,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,23,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,24,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,25,4,'4ФСС_РАЗДЕЛ_ПП1(''10123'',3)')
INSERT #F VALUES (14,26,4,'4ФСС_РАЗДЕЛ_ПП1(''10124'',3)')
INSERT #F VALUES (14,27,4,'4ФСС_РАЗДЕЛ_ПП1(''10125'',3)')
INSERT #F VALUES (14,28,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,29,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,30,4,'ЗАПРЕТ()')
INSERT #F VALUES (14,31,4,'ЗАПРЕТ()')
INSERT #F VALUES (15,1,1,'Пособия по временной нетрудоспособности в связи
с несчастными случаями на производстве, всего                                                                                                                                                            ')
INSERT #F VALUES (15,2,1,'      из них: по внешнему совместительству                                                                                                                                                                                                                ')
INSERT #F VALUES (15,3,1,'      пострадавшим в другой организации                                                                                                                                                                                                                       ')
INSERT #F VALUES (15,4,1,'Пособия по временной нетрудоспособности в связи
с профессиональными заболеваниями, всего                                                                                                                                                                 ')
INSERT #F VALUES (15,5,1,'      из них: по внешнему совместительству                                                                                                                                                                                                                ')
INSERT #F VALUES (15,6,1,'      пострадавшим в другой организации                                                                                                                                                                                                                       ')
INSERT #F VALUES (15,7,1,'Оплата отпуска для санаторно-курортного лечения застрахованным (сверх ежегодного оплачиваемого отпуска, установленного законодательством Российской Федерации)                                                                                            ')
INSERT #F VALUES (15,8,1,'      из них: пострадавшим в другой организации                                                                                                                                                                                                               ')
INSERT #F VALUES (15,9,1,'Финансирование предупредительных мер по сокращению производственного травматизма и профзаболеваний                                                                                                                                                        ')
INSERT #F VALUES (15,10,1,'Всего расходов (сумма строк 1, 4, 7, 9)                                                                                                                                                                                                                   ')
INSERT #F VALUES (15,1,2,'1                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,3,2,'3                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (15,4,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,5,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,6,2,'6                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (15,7,2,'7                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,8,2,'8                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (15,9,2,'9                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (15,10,2,'10                                                                                                                                                                                                                                                        ')
INSERT #F VALUES (15,1,3,'4ФСС_РАЗДЕЛ1(''1101'',6)')
INSERT #F VALUES (15,2,3,'4ФСС_РАЗДЕЛ1(''1102'',6)')
INSERT #F VALUES (15,4,3,'4ФСС_РАЗДЕЛ1(''1104'',6)')
INSERT #F VALUES (15,5,3,'4ФСС_РАЗДЕЛ1(''1105'',6)')
INSERT #F VALUES (15,7,3,'4ФСС_РАЗДЕЛ1(''1107'',6)')
INSERT #F VALUES (15,9,3,'ЗАПРЕТ()')
INSERT #F VALUES (15,10,3,'ЗАПРЕТ()')
INSERT #F VALUES (15,1,4,'4ФСС_РАЗДЕЛ1(''1101'',3)')
INSERT #F VALUES (15,2,4,'4ФСС_РАЗДЕЛ1(''1102'',3)')
INSERT #F VALUES (15,4,4,'4ФСС_РАЗДЕЛ1(''1104'',3)')
INSERT #F VALUES (15,5,4,'4ФСС_РАЗДЕЛ1(''1105'',3)')
INSERT #F VALUES (15,7,4,'4ФСС_РАЗДЕЛ1(''1107'',3)')
INSERT #F VALUES (16,1,1,'По несчастным случаям                                                                                                                                                                                                                                     ')
INSERT #F VALUES (16,2,1,'      из них: со смертельным исходом                                                                                                                                                                                                                      ')
INSERT #F VALUES (16,3,1,'По профессиональным заболеваниям                                                                                                                                                                                                                          ')
INSERT #F VALUES (16,4,1,'ВСЕГО пострадавших (сумма строк 1, 3)                                                                                                                                                                                                                     ')
INSERT #F VALUES (16,5,1,'в том числе пострадавших (застрахованных) по случаям, закончившимся только временной нетрудоспособностью                                                                                                                                                  ')
INSERT #F VALUES (16,1,2,'1                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (16,2,2,'2                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (16,3,2,'3                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (16,4,2,'4                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (16,5,2,'5                                                                                                                                                                                                                                                         ')
INSERT #F VALUES (17,1,1,'Аттестация рабочих мест по условиям труда                                                                                                                                                                                                                     ')
INSERT #F VALUES (17,2,1,'Проведение обязательных предварительных и периодических медицинских осмотров (обследований) работников                                                                                                                                                        ')
INSERT #F VALUES (17,1,2,'1                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (17,2,2,'2                                                                                                                                                                                                                                                             ')
INSERT #F VALUES (17,1,3,'4ФСС_РАЗДЕЛ1(''100103'',3)')
INSERT #F VALUES (17,2,3,'ЗАПРЕТ()')
INSERT #F VALUES (17,1,4,'4ФСС_РАЗДЕЛ1(''100104'',3)')
INSERT #F VALUES (17,2,4,'ЗАПРЕТ()')
INSERT #F VALUES (17,1,6,'4ФСС_РАЗДЕЛ1(''100105'',3)')
INSERT #F VALUES (17,2,6,'ЗАПРЕТ()')
INSERT #F VALUES (17,1,7,'4ФСС_РАЗДЕЛ1(''100106'',3)')
INSERT #F VALUES (17,2,7,'ЗАПРЕТ()')
INSERT #F VALUES (17,1,8,'ЗАПРЕТ()')
INSERT #F VALUES (17,1,9,'ЗАПРЕТ()')

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #F) <> 601
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #F',0)
END

ALTER TABLE dbo.[REPORT_FORMULA] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_FORMULA] ([LINK_ROW],
                             [LINK_COL],
                             [FORMULA])
SELECT [D].[LINK_ROW],
       [C].[LINK_COL],
       [E].[FORMULA]
FROM #tabInfo              [A]
JOIN dbo.[REPORT_TABLES]   [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN dbo.[REPORT_COLOUMNS] [C] ON [B].[LINK_TABLE] = [C].[LINK_TABLE]
JOIN dbo.[REPORT_ROWS]     [D] ON [B].[LINK_TABLE] = [D].[LINK_TABLE]
JOIN #F                    [E] ON [E].[ORDER_TABLE] = [B].[ORDERS] AND [E].[ORDER_COL] = [C].[ORDERS] AND [E].[ORDER_ROW] = [D].[ORDERS]

ALTER TABLE dbo.[REPORT_FORMULA] ENABLE TRIGGER ALL

DROP TABLE #F

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN

DECLARE @iERROR INT, @iLINK_FORM_NEW INT, @iLINK_FORM INT

SELECT @iLINK_FORM = [LINK_FORM],
       @iLINK_FORM_NEW = [LINK_FORM_NEW]
FROM #tabInfo

--IF @iLINK_FORM_NEW <> @iLINK_FORM
--BEGIN
  EXEC @iERROR = dbo.[RA_UNION_FORM_STRUCT] @iLINK_FORM, @iLINK_FORM_NEW, 1
--END
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UNION_FORM_STRUCT',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.2стр.2_2гр.3 =  т.2стр.2_3гр.3 +  т.2стр.2_4гр.3 +  т.2стр.2_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.2стр.3_2гр.3 =  т.2стр.3_3гр.3 +  т.2стр.3_4гр.3 +  т.2стр.3_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(3,NULL,0,NULL,3,7,0,0,0,'т.2стр.5_2гр.3 =  т.2стр.5_3гр.3 +  т.2стр.5_4гр.3 +  т.2стр.5_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(4,NULL,0,NULL,4,7,0,0,0,'т.2стр.6_2гр.3 =  т.2стр.6_3гр.3 +  т.2стр.6_4гр.3 +  т.2стр.6_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(5,NULL,0,NULL,5,7,0,0,0,'т.2стр.15_2гр.3 =  т.2стр.15_3гр.3 +  т.2стр.15_4гр.3 +  т.2стр.15_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(6,NULL,0,NULL,6,7,0,0,0,'т.2стр.16_2гр.3 =  т.2стр.16_3гр.3 +  т.2стр.16_4гр.3 +  т.2стр.16_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(7,NULL,0,NULL,7,7,0,0,0,'т.2стр.15гр.3 =  т.3стр.12гр.4',0,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(8,NULL,0,NULL,8,7,0,0,0,'т.4стр.4гр.3 =  т.4стр.1гр.3 -  т.4стр.2гр.3 -  т.4стр.3гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(9,NULL,0,NULL,9,7,0,0,0,'т.4стр.4гр.4 =  т.4стр.1гр.4 -  т.4стр.2гр.4 -  т.4стр.3гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(10,NULL,0,NULL,10,7,0,0,0,'т.4стр.4гр.5 =  т.4стр.1гр.5 -  т.4стр.2гр.5 -  т.4стр.3гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(11,NULL,0,NULL,11,7,0,0,0,'т.4стр.4гр.6 =  т.4стр.1гр.6 -  т.4стр.2гр.6 -  т.4стр.3гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(12,NULL,0,NULL,12,7,0,0,0,'т.6стр.1гр.3 =  т.6стр.1гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(13,NULL,0,NULL,13,7,0,0,0,'т.6стр.2гр.3 =  т.6стр.2гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(14,NULL,0,NULL,14,7,0,0,0,'т.6стр.3гр.3 =  т.6стр.2гр.3 /  т.6стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(15,NULL,0,NULL,15,7,0,0,0,'т.6стр.3гр.4 =  т.6стр.2гр.4 /  т.6стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(16,NULL,0,NULL,16,7,0,0,0,'т.6стр.3гр.5 =  т.6стр.2гр.5 /  т.6стр.1гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(17,NULL,0,NULL,17,7,0,0,0,'т.6стр.3гр.6 =  т.6стр.2гр.6 /  т.6стр.1гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(18,NULL,0,NULL,18,7,0,0,0,'т.7стр.1гр.3 =  т.7стр.1гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(19,NULL,0,NULL,19,7,0,0,0,'т.7стр.2гр.3 =  т.7стр.2гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(20,NULL,0,NULL,20,7,0,0,0,'т.7стр.3гр.3 =  т.7стр.2гр.3 /  т.7стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(21,NULL,0,NULL,21,7,0,0,0,'т.7стр.3гр.4 =  т.7стр.2гр.4 /  т.7стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(22,NULL,0,NULL,22,7,0,0,0,'т.7стр.3гр.5 =  т.7стр.2гр.5 /  т.7стр.1гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(23,NULL,0,NULL,23,7,0,0,0,'т.7стр.3гр.6 =  т.7стр.2гр.6 /  т.7стр.1гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(24,NULL,0,NULL,24,7,0,0,0,'т.7стр.6гр.3 =  т.7стр.5гр.3 /  т.7стр.4гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(25,NULL,0,NULL,25,7,0,0,0,'т.7стр.6гр.4 =  т.7стр.5гр.4 /  т.7стр.4гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(26,NULL,0,NULL,26,7,0,0,0,'т.7стр.6гр.5 =  т.7стр.5гр.5 /  т.7стр.4гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(27,NULL,0,NULL,27,7,0,0,0,'т.7стр.6гр.6 =  т.7стр.5гр.6 /  т.7стр.4гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(28,NULL,0,NULL,28,7,0,0,0,'т.8стр.4гр.3 =  т.8стр.3гр.3 /  т.8стр.2гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(29,NULL,0,NULL,29,7,0,0,0,'т.12стр.1гр.5 =  т.3стр.1гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(30,NULL,0,NULL,30,7,0,0,0,'т.12стр.2гр.5 =  т.3стр.3гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(31,NULL,0,NULL,31,7,0,0,0,'т.12стр.4гр.5 =  т.3стр.8гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(32,NULL,0,NULL,32,7,0,0,0,'т.12стр.5гр.5 =  т.3стр.9гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(33,NULL,0,NULL,33,7,0,0,0,'т.12стр.6гр.5 =  т.3стр.11гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(34,NULL,0,NULL,34,7,0,0,0,'т.13стр.2гр.3 =  т.13стр.3гр.3 +  т.13стр.4гр.3 +  т.13стр.5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(35,NULL,0,NULL,35,7,0,0,0,'т.13стр.2гр.4 =  т.13стр.3гр.4 +  т.13стр.4гр.4 +  т.13стр.5гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(36,NULL,0,NULL,36,7,0,0,0,'т.13стр.2гр.5 =  т.13стр.3гр.5 +  т.13стр.4гр.5 +  т.13стр.5гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(37,NULL,0,NULL,37,7,0,0,0,'т.14стр.2_2гр.3 =  т.14стр.2_3гр.3 +  т.14стр.2_4гр.3 +  т.14стр.2_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(38,NULL,0,NULL,38,7,0,0,0,'т.14стр.11_2гр.3 =  т.14стр.11_3гр.3 +  т.14стр.11_4гр.3 +  т.14стр.11_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(39,NULL,0,NULL,39,7,0,0,0,'т.14стр.12_2гр.3 =  т.14стр.12_3гр.3 +  т.14стр.12_4гр.3 +  т.14стр.12_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(40,NULL,0,NULL,40,7,0,0,0,'т.15стр.10гр.4 =  т.15стр.1гр.4 +  т.15стр.4гр.4 +  т.15стр.7гр.4 +  т.15стр.9гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(41,NULL,0,NULL,41,7,0,0,0,'т.16стр.4гр.3 =  т.16стр.1гр.3 +  т.16стр.3гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(42,NULL,0,NULL,42,7,0,0,0,'т.13гр.3 =  -  т.13гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(43,NULL,0,NULL,43,7,0,0,0,'т.13гр.3 =  -  т.13гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(44,NULL,0,NULL,44,7,0,0,0,'т.3стр.7гр.2 =  т.3стр.8гр.2 +  т.3стр.9гр.2',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(45,NULL,0,NULL,45,7,0,0,0,'т.3стр.7гр.3 =  т.3стр.8гр.3 +  т.3стр.9гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(46,NULL,0,NULL,46,7,0,0,0,'т.3стр.7гр.4 =  т.3стр.8гр.4 +  т.3стр.9гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(47,NULL,0,NULL,47,7,0,0,0,'т.3стр.7гр.5 =  т.3стр.8гр.5 +  т.3стр.9гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(48,NULL,0,NULL,48,7,0,0,0,'т.1стр.2гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(49,NULL,0,NULL,49,7,0,0,0,'т.1стр.3гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(50,NULL,0,NULL,50,7,0,0,0,'т.1стр.4гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(51,NULL,0,NULL,51,7,0,0,0,'т.3стр.2гр.2 <=  т.3стр.1гр.2',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(52,NULL,0,NULL,52,7,0,0,0,'т.3стр.2гр.3 <=  т.3стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(53,NULL,0,NULL,53,7,0,0,0,'т.3стр.2гр.4 <=  т.3стр.1гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(54,NULL,0,NULL,54,7,0,0,0,'т.3стр.2гр.5 <=  т.3стр.1гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(55,NULL,0,NULL,55,7,0,0,0,'т.3стр.4гр.3 <=  т.3стр.3гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(56,NULL,0,NULL,56,7,0,0,0,'т.3стр.4гр.4 <=  т.3стр.3гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(57,NULL,0,NULL,57,7,0,0,0,'т.3стр.4гр.5 <=  т.3стр.3гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(58,NULL,0,NULL,58,7,0,0,0,'т.4стр.1гр.3 >=  т.4стр.1гр.4 +  т.4стр.1гр.5 +  т.4стр.1гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(59,NULL,0,NULL,59,7,0,0,0,'т.4стр.2гр.3 >=  т.4стр.2гр.4 +  т.4стр.2гр.5 +  т.4стр.2гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(60,NULL,0,NULL,60,7,0,0,0,'т.4стр.3гр.3 >=  т.4стр.3гр.4 +  т.4стр.3гр.5 +  т.4стр.3гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(61,NULL,0,NULL,61,7,0,0,0,'т.4стр.4гр.3 >=  т.4стр.4гр.4 +  т.4стр.4гр.5 +  т.4стр.4гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(62,NULL,0,NULL,62,7,0,0,0,'т.4стр.5гр.3 >=  т.4стр.5гр.4 +  т.4стр.5гр.5 +  т.4стр.5гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(63,NULL,0,NULL,63,7,0,0,0,'т.4стр.5гр.3 <=  т.4стр.4гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(64,NULL,0,NULL,64,7,0,0,0,'т.4стр.5гр.4 <=  т.4стр.4гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(65,NULL,0,NULL,65,7,0,0,0,'т.4стр.5гр.5 <=  т.4стр.4гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(66,NULL,0,NULL,66,7,0,0,0,'т.4стр.5гр.6 <=  т.4стр.4гр.6',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(67,NULL,0,NULL,67,7,0,0,0,'т.13стр.1гр.4 <=  т.13стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(68,NULL,0,NULL,68,7,0,0,0,'т.14стр.16гр.3 <=  т.14стр.15гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(69,NULL,0,NULL,69,7,0,0,0,'т.14стр.11гр.3 =  т.15стр.10гр.4',0,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(70,NULL,0,NULL,70,7,0,0,0,'т.15стр.1гр.3 >=  т.15стр.2гр.3 +  т.15стр.3гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(71,NULL,0,NULL,71,7,0,0,0,'т.15стр.1гр.4 >=  т.15стр.2гр.4 +  т.15стр.3гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(72,NULL,0,NULL,72,7,0,0,0,'т.15стр.4гр.3 >=  т.15стр.5гр.3 +  т.15стр.6гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(73,NULL,0,NULL,73,7,0,0,0,'т.15стр.4гр.4 >=  т.15стр.5гр.4 +  т.15стр.6гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(74,NULL,0,NULL,74,7,0,0,0,'т.15стр.7гр.3 >=  т.15стр.8гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(75,NULL,0,NULL,75,7,0,0,0,'т.15стр.7гр.4 >=  т.15стр.8гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(76,NULL,0,NULL,76,7,0,0,0,'т.8стр.4гр.4 =  т.8стр.3гр.4 /  т.8стр.2гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(77,NULL,0,NULL,77,7,0,0,0,'т.9стр.3гр.3 =  т.9стр.2гр.3 /  т.9стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(78,NULL,0,NULL,78,7,0,0,0,'т.10стр.5гр.3 =  т.10стр.4гр.3 +  т.10стр.3гр.3 +  т.10стр.2гр.3 /  т.10стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(79,NULL,0,NULL,79,7,0,0,0,'т.10стр.5гр.4 =  т.10стр.4гр.4 +  т.10стр.3гр.4 +  т.10стр.2гр.4 /  т.10стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(80,NULL,0,NULL,80,7,0,0,0,'т.3стр.12гр.4 =  т.3стр.1гр.4 +  т.3стр.3гр.4 +  т.3стр.5гр.4 +  т.3стр.6гр.4 +  т.3стр.7гр.4 +  т.3стр.10гр.4 +  т.3стр.11гр.4',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(81,NULL,0,NULL,81,7,0,0,0,'т.3стр.12гр.5 =  т.3стр.1гр.5 +  т.3стр.3гр.5 +  т.3стр.5гр.5 +  т.3стр.6гр.5 +  т.3стр.7гр.5 +  т.3стр.10гр.5 +  т.3стр.11гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(82,NULL,0,NULL,82,7,0,0,0,'т.12стр.3гр.5 =  т.12стр.4гр.5 +  т.12стр.5гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(83,NULL,0,NULL,83,7,0,0,0,'т.14стр.2гр.3 =  т.14стр.2_1гр.3 +  т.14стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(84,NULL,0,NULL,84,7,0,0,0,'т.14стр.11гр.3 =  т.14стр.11_1гр.3 +  т.14стр.11_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(85,NULL,0,NULL,85,7,0,0,0,'т.14стр.12гр.3 =  т.14стр.12_1гр.3 +  т.14стр.12_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(86,NULL,0,NULL,86,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',0,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(87,NULL,0,NULL,87,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(88,NULL,0,NULL,88,7,0,0,0,'т.2стр.2гр.3 =  т.2стр.2_1гр.3 +  т.2стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(89,NULL,0,NULL,89,7,0,0,0,'т.2стр.3гр.3 =  т.2стр.3_1гр.3 +  т.2стр.3_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(90,NULL,0,NULL,90,7,0,0,0,'т.2стр.5гр.3 =  т.2стр.5_1гр.3 +  т.2стр.5_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(91,NULL,0,NULL,91,7,0,0,0,'т.2стр.6гр.3 =  т.2стр.6_1гр.3 +  т.2стр.6_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(92,NULL,0,NULL,92,7,0,0,0,'т.2стр.15гр.3 =  т.2стр.15_1гр.3 +  т.2стр.15_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(93,NULL,0,NULL,93,7,0,0,0,'т.2стр.16гр.3 =  т.2стр.16_1гр.3 +  т.2стр.16_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(94,NULL,0,NULL,95,7,0,0,0,'т.3стр.12гр.4 =  т.3стр.1гр.4 +  т.3стр.3гр.4 +  т.3стр.5гр.4 +  т.3стр.6гр.4 +  т.3стр.7гр.4 +  т.3стр.10гр.4 +  т.3стр.11гр.4',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(95,NULL,0,NULL,96,7,0,0,0,'т.3стр.12гр.5 =  т.3стр.1гр.5 +  т.3стр.3гр.5 +  т.3стр.5гр.5 +  т.3стр.6гр.5 +  т.3стр.7гр.5 +  т.3стр.10гр.5 +  т.3стр.11гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(96,NULL,0,NULL,97,7,0,0,0,'т.12стр.3гр.5 =  т.12стр.4гр.5 +  т.12стр.5гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(97,NULL,0,NULL,98,7,0,0,0,'т.14стр.2гр.3 =  т.14стр.2_1гр.3 +  т.14стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(98,NULL,0,NULL,99,7,0,0,0,'т.14стр.11гр.3 =  т.14стр.11_1гр.3 +  т.14стр.11_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(99,NULL,0,NULL,100,7,0,0,0,'т.14стр.12гр.3 =  т.14стр.12_1гр.3 +  т.14стр.12_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(100,NULL,0,NULL,101,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',0,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(101,NULL,0,NULL,102,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(102,NULL,0,NULL,103,7,0,0,0,'т.2стр.8гр.3 =  т.2стр.1гр.3 +  т.2стр.2гр.3 +  т.2стр.3гр.3 +  т.2стр.4гр.3 +  т.2стр.5гр.3 +  т.2стр.6гр.3 +  т.2стр.7гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(103,NULL,0,NULL,104,7,0,0,0,'т.2стр.18гр.3 =  т.2стр.12гр.3 +  т.2стр.15гр.3 +  т.2стр.16гр.3 +  т.2стр.17гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(104,NULL,0,NULL,105,7,0,0,0,'т.12стр.7гр.3 =  т.12стр.1гр.3 +  т.12стр.2гр.3 +  т.12стр.3гр.3 +  т.12стр.6гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(105,NULL,0,NULL,106,7,0,0,0,'т.12стр.7гр.5 =  т.12стр.1гр.5 +  т.12стр.2гр.5 +  т.12стр.3гр.5 +  т.12стр.6гр.5',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(106,NULL,0,NULL,107,7,0,0,0,'т.12стр.7гр.6 =  т.12стр.1гр.6 +  т.12стр.2гр.6 +  т.12стр.3гр.6 +  т.12стр.6гр.6',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(107,NULL,0,NULL,108,7,0,0,0,'т.12стр.7гр.8 =  т.12стр.1гр.8 +  т.12стр.2гр.8 +  т.12стр.3гр.8 +  т.12стр.6гр.8',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(108,NULL,0,NULL,109,7,0,0,0,'т.12стр.7гр.9 =  т.12стр.1гр.9 +  т.12стр.2гр.9 +  т.12стр.3гр.9 +  т.12стр.6гр.9',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(109,NULL,0,NULL,110,7,0,0,0,'т.12стр.7гр.11 =  т.12стр.1гр.11 +  т.12стр.2гр.11 +  т.12стр.3гр.11 +  т.12стр.6гр.11',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(110,NULL,0,NULL,111,7,0,0,0,'т.12стр.7гр.12 =  т.12стр.1гр.12 +  т.12стр.2гр.12 +  т.12стр.3гр.12 +  т.12стр.6гр.12',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(111,NULL,0,NULL,112,7,0,0,0,'т.12стр.7гр.14 =  т.12стр.1гр.14 +  т.12стр.2гр.14 +  т.12стр.3гр.14 +  т.12стр.6гр.14',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(112,NULL,0,NULL,113,7,0,0,0,'т.12стр.7гр.15 =  т.12стр.1гр.15 +  т.12стр.2гр.15 +  т.12стр.3гр.15 +  т.12стр.6гр.15',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(113,NULL,0,NULL,114,7,0,0,0,'т.12стр.7гр.17 =  т.12стр.1гр.17 +  т.12стр.2гр.17 +  т.12стр.3гр.17 +  т.12стр.6гр.17',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(114,NULL,0,NULL,115,7,0,0,0,'т.12стр.7гр.18 =  т.12стр.1гр.18 +  т.12стр.2гр.18 +  т.12стр.3гр.18 +  т.12стр.6гр.18',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(115,NULL,0,NULL,116,7,0,0,0,'т.12стр.7гр.20 =  т.12стр.1гр.20 +  т.12стр.2гр.20 +  т.12стр.3гр.20 +  т.12стр.6гр.20',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(116,NULL,0,NULL,117,7,0,0,0,'т.14стр.8гр.3 =  т.14стр.1гр.3 +  т.14стр.2гр.3 +  т.14стр.3гр.3 +  т.14стр.4гр.3 +  т.14стр.5гр.3 +  т.14стр.6гр.3 +  т.14стр.7гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(117,NULL,0,NULL,118,7,0,0,0,'т.14стр.14гр.3 =  т.14стр.10гр.3 +  т.14стр.11гр.3 +  т.14стр.12гр.3 +  т.14стр.13гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(118,NULL,0,NULL,119,7,0,0,0,'Проверки =  0',0,100,1,'20141113','','','','4fss','20140101','','=',9,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 118
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(3,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(4,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(5,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(6,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(7,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(8,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(9,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(10,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(11,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(12,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(13,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(14,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(15,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(16,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(17,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(18,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(19,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(20,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(21,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(22,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(23,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(24,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(25,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(26,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(27,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','8',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(28,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(29,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(29,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(30,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(30,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(31,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(31,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(32,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(32,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(33,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(33,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(34,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(35,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(36,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(37,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(38,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(39,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','10','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(40,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','9','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(41,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','16',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(41,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','16',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(41,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','16',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(42,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(42,2,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''1'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(43,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(43,2,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(44,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(44,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(44,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(45,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(45,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(45,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(46,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(46,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(46,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(47,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(47,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(47,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(48,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(48,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(49,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(49,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(50,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(50,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(51,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(51,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(52,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(52,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(53,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(53,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(54,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(54,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(55,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(55,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(56,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(56,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(57,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(57,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(58,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(59,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(60,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(61,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(62,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(63,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(63,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(64,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(64,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(65,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(65,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(66,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(66,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(67,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(67,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(68,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(68,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(69,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(69,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','10','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(70,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(70,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(70,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(71,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(71,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(71,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(72,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(72,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(72,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(73,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(73,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(73,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','6','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(74,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(74,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(75,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(75,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','8','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','8',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(76,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','9',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(77,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','9',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','9',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','10',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(78,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,5,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,6,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','10',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(79,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,5,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,6,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(80,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(81,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(82,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(82,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(82,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(83,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(83,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(83,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(84,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(84,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(84,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(85,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(85,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(85,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(86,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''1'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(86,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(86,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(87,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(87,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(87,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(88,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(88,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(88,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(89,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(89,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(89,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(90,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(90,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(90,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(91,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(91,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(91,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(92,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(92,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(92,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(93,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(94,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(95,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(96,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(96,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(96,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(97,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(97,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(97,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(98,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(98,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(98,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(99,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(99,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(99,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''1'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(100,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(101,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(102,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','18','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(103,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','17','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(104,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(105,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(106,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(107,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(108,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(109,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(110,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(111,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(112,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(113,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(114,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(115,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(116,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(117,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','14','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(117,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','10','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(117,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(117,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(117,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','13','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(118,1,2,'+',NULL,NULL,NULL,NULL,0,0,'SA_4FSS_EXPORT_TEST(0)','Проверки','','','','','','','','','',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(118,2,1,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 424
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-- Обновление связей с группами форм.

DELETE dbo.[REPORT_FORM_GROUPS_REF]
WHERE [LINK_FORM] = @iLINK_FORM

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '3         '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'3','Квартальные формы',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '999999    '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'999999','формы отчетности',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

-- Переформирование процедур RI_PROC_T.
DECLARE curTable CURSOR FOR
SELECT [LINK_TABLE],
       [ORDERS]
FROM [REPORT_TABLES]
WHERE [LINK_FORM] = @iLINK_FORM

OPEN curTable

FETCH NEXT
FROM curTable
INTO @iTABLE_LINK,
     @tTABLE_ORDER

WHILE @@FETCH_STATUS = 0
BEGIN
   EXEC @iERROR = dbo.[I_REPORT_CREATE_PROC] @iTABLE_LINK
   IF @iERROR <> 0
   BEGIN
      INSERT #tabErrorLog VALUES ('I_REPORT_CREATE_PROC',@iERROR)
   END
   FETCH NEXT
   FROM curTable
   INTO @iTABLE_LINK,
        @tTABLE_ORDER
END
CLOSE curTable
DEALLOCATE curTable

EXEC dbo.[I_CONTROL_RULES_ACTION] 3, @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-11-17 10:53:21.803',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-11-17 10:53:21.803'
	BEGIN
		SELECT @vcMessage = 'Форма 4fss с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 4fss с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-11-17 10:53:21.803. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (ноя 13 2014 10:40:43:620AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : 4fss (Расчетная ведомость по средствам ФСС РФ)
-- Дата ввода : 20140101
-- Дата окончания действия :
-- Версия : 2014-11-13 10:40:43.617
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : да
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = '4fss' AND [START_DATE] = '20140101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-11-13 10:40:43.617',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.2стр.2_2гр.3 =  т.2стр.2_3гр.3 +  т.2стр.2_4гр.3 +  т.2стр.2_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.2стр.3_2гр.3 =  т.2стр.3_3гр.3 +  т.2стр.3_4гр.3 +  т.2стр.3_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(3,NULL,0,NULL,3,7,0,0,0,'т.2стр.5_2гр.3 =  т.2стр.5_3гр.3 +  т.2стр.5_4гр.3 +  т.2стр.5_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(4,NULL,0,NULL,4,7,0,0,0,'т.2стр.6_2гр.3 =  т.2стр.6_3гр.3 +  т.2стр.6_4гр.3 +  т.2стр.6_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(5,NULL,0,NULL,5,7,0,0,0,'т.2стр.15_2гр.3 =  т.2стр.15_3гр.3 +  т.2стр.15_4гр.3 +  т.2стр.15_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(6,NULL,0,NULL,6,7,0,0,0,'т.2стр.16_2гр.3 =  т.2стр.16_3гр.3 +  т.2стр.16_4гр.3 +  т.2стр.16_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(7,NULL,0,NULL,7,7,0,0,0,'т.2стр.15гр.3 =  т.3стр.12гр.4',0,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(8,NULL,0,NULL,8,7,0,0,0,'т.4стр.4гр.3 =  т.4стр.1гр.3 -  т.4стр.2гр.3 -  т.4стр.3гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(9,NULL,0,NULL,9,7,0,0,0,'т.4стр.4гр.4 =  т.4стр.1гр.4 -  т.4стр.2гр.4 -  т.4стр.3гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(10,NULL,0,NULL,10,7,0,0,0,'т.4стр.4гр.5 =  т.4стр.1гр.5 -  т.4стр.2гр.5 -  т.4стр.3гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(11,NULL,0,NULL,11,7,0,0,0,'т.4стр.4гр.6 =  т.4стр.1гр.6 -  т.4стр.2гр.6 -  т.4стр.3гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(12,NULL,0,NULL,12,7,0,0,0,'т.6стр.1гр.3 =  т.6стр.1гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(13,NULL,0,NULL,13,7,0,0,0,'т.6стр.2гр.3 =  т.6стр.2гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(14,NULL,0,NULL,14,7,0,0,0,'т.6стр.3гр.3 =  т.6стр.2гр.3 /  т.6стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(15,NULL,0,NULL,15,7,0,0,0,'т.6стр.3гр.4 =  т.6стр.2гр.4 /  т.6стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(16,NULL,0,NULL,16,7,0,0,0,'т.6стр.3гр.5 =  т.6стр.2гр.5 /  т.6стр.1гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(17,NULL,0,NULL,17,7,0,0,0,'т.6стр.3гр.6 =  т.6стр.2гр.6 /  т.6стр.1гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(18,NULL,0,NULL,18,7,0,0,0,'т.7стр.1гр.3 =  т.7стр.1гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(19,NULL,0,NULL,19,7,0,0,0,'т.7стр.2гр.3 =  т.7стр.2гр.6',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(20,NULL,0,NULL,20,7,0,0,0,'т.7стр.3гр.3 =  т.7стр.2гр.3 /  т.7стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(21,NULL,0,NULL,21,7,0,0,0,'т.7стр.3гр.4 =  т.7стр.2гр.4 /  т.7стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(22,NULL,0,NULL,22,7,0,0,0,'т.7стр.3гр.5 =  т.7стр.2гр.5 /  т.7стр.1гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(23,NULL,0,NULL,23,7,0,0,0,'т.7стр.3гр.6 =  т.7стр.2гр.6 /  т.7стр.1гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(24,NULL,0,NULL,24,7,0,0,0,'т.7стр.6гр.3 =  т.7стр.5гр.3 /  т.7стр.4гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(25,NULL,0,NULL,25,7,0,0,0,'т.7стр.6гр.4 =  т.7стр.5гр.4 /  т.7стр.4гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(26,NULL,0,NULL,26,7,0,0,0,'т.7стр.6гр.5 =  т.7стр.5гр.5 /  т.7стр.4гр.5 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(27,NULL,0,NULL,27,7,0,0,0,'т.7стр.6гр.6 =  т.7стр.5гр.6 /  т.7стр.4гр.6 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(28,NULL,0,NULL,28,7,0,0,0,'т.8стр.4гр.3 =  т.8стр.3гр.3 /  т.8стр.2гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(29,NULL,0,NULL,29,7,0,0,0,'т.12стр.1гр.5 =  т.3стр.1гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(30,NULL,0,NULL,30,7,0,0,0,'т.12стр.2гр.5 =  т.3стр.3гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(31,NULL,0,NULL,31,7,0,0,0,'т.12стр.4гр.5 =  т.3стр.8гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(32,NULL,0,NULL,32,7,0,0,0,'т.12стр.5гр.5 =  т.3стр.9гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(33,NULL,0,NULL,33,7,0,0,0,'т.12стр.6гр.5 =  т.3стр.11гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(34,NULL,0,NULL,34,7,0,0,0,'т.13стр.2гр.3 =  т.13стр.3гр.3 +  т.13стр.4гр.3 +  т.13стр.5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(35,NULL,0,NULL,35,7,0,0,0,'т.13стр.2гр.4 =  т.13стр.3гр.4 +  т.13стр.4гр.4 +  т.13стр.5гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(36,NULL,0,NULL,36,7,0,0,0,'т.13стр.2гр.5 =  т.13стр.3гр.5 +  т.13стр.4гр.5 +  т.13стр.5гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(37,NULL,0,NULL,37,7,0,0,0,'т.14стр.2_2гр.3 =  т.14стр.2_3гр.3 +  т.14стр.2_4гр.3 +  т.14стр.2_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(38,NULL,0,NULL,38,7,0,0,0,'т.14стр.11_2гр.3 =  т.14стр.11_3гр.3 +  т.14стр.11_4гр.3 +  т.14стр.11_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(39,NULL,0,NULL,39,7,0,0,0,'т.14стр.12_2гр.3 =  т.14стр.12_3гр.3 +  т.14стр.12_4гр.3 +  т.14стр.12_5гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(40,NULL,0,NULL,40,7,0,0,0,'т.15стр.10гр.4 =  т.15стр.1гр.4 +  т.15стр.4гр.4 +  т.15стр.7гр.4 +  т.15стр.9гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(41,NULL,0,NULL,41,7,0,0,0,'т.16стр.4гр.3 =  т.16стр.1гр.3 +  т.16стр.3гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(42,NULL,0,NULL,42,7,0,0,0,'т.13гр.3 =  -  т.13гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(43,NULL,0,NULL,43,7,0,0,0,'т.13гр.3 =  -  т.13гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(44,NULL,0,NULL,44,7,0,0,0,'т.3стр.7гр.2 =  т.3стр.8гр.2 +  т.3стр.9гр.2',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(45,NULL,0,NULL,45,7,0,0,0,'т.3стр.7гр.3 =  т.3стр.8гр.3 +  т.3стр.9гр.3',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(46,NULL,0,NULL,46,7,0,0,0,'т.3стр.7гр.4 =  т.3стр.8гр.4 +  т.3стр.9гр.4',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(47,NULL,0,NULL,47,7,0,0,0,'т.3стр.7гр.5 =  т.3стр.8гр.5 +  т.3стр.9гр.5',1,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(48,NULL,0,NULL,48,7,0,0,0,'т.1стр.2гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(49,NULL,0,NULL,49,7,0,0,0,'т.1стр.3гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(50,NULL,0,NULL,50,7,0,0,0,'т.1стр.4гр.3 <=  т.1стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(51,NULL,0,NULL,51,7,0,0,0,'т.3стр.2гр.2 <=  т.3стр.1гр.2',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(52,NULL,0,NULL,52,7,0,0,0,'т.3стр.2гр.3 <=  т.3стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(53,NULL,0,NULL,53,7,0,0,0,'т.3стр.2гр.4 <=  т.3стр.1гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(54,NULL,0,NULL,54,7,0,0,0,'т.3стр.2гр.5 <=  т.3стр.1гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(55,NULL,0,NULL,55,7,0,0,0,'т.3стр.4гр.3 <=  т.3стр.3гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(56,NULL,0,NULL,56,7,0,0,0,'т.3стр.4гр.4 <=  т.3стр.3гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(57,NULL,0,NULL,57,7,0,0,0,'т.3стр.4гр.5 <=  т.3стр.3гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(58,NULL,0,NULL,58,7,0,0,0,'т.4стр.1гр.3 >=  т.4стр.1гр.4 +  т.4стр.1гр.5 +  т.4стр.1гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(59,NULL,0,NULL,59,7,0,0,0,'т.4стр.2гр.3 >=  т.4стр.2гр.4 +  т.4стр.2гр.5 +  т.4стр.2гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(60,NULL,0,NULL,60,7,0,0,0,'т.4стр.3гр.3 >=  т.4стр.3гр.4 +  т.4стр.3гр.5 +  т.4стр.3гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(61,NULL,0,NULL,61,7,0,0,0,'т.4стр.4гр.3 >=  т.4стр.4гр.4 +  т.4стр.4гр.5 +  т.4стр.4гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(62,NULL,0,NULL,62,7,0,0,0,'т.4стр.5гр.3 >=  т.4стр.5гр.4 +  т.4стр.5гр.5 +  т.4стр.5гр.6',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(63,NULL,0,NULL,63,7,0,0,0,'т.4стр.5гр.3 <=  т.4стр.4гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(64,NULL,0,NULL,64,7,0,0,0,'т.4стр.5гр.4 <=  т.4стр.4гр.4',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(65,NULL,0,NULL,65,7,0,0,0,'т.4стр.5гр.5 <=  т.4стр.4гр.5',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(66,NULL,0,NULL,66,7,0,0,0,'т.4стр.5гр.6 <=  т.4стр.4гр.6',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(67,NULL,0,NULL,67,7,0,0,0,'т.13стр.1гр.4 <=  т.13стр.1гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(68,NULL,0,NULL,68,7,0,0,0,'т.14стр.16гр.3 <=  т.14стр.15гр.3',0,0,1,'20141113','','','','4fss','20140101','','<=',1,'','')
INSERT #A VALUES(69,NULL,0,NULL,69,7,0,0,0,'т.14стр.11гр.3 =  т.15стр.10гр.4',0,0,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(70,NULL,0,NULL,70,7,0,0,0,'т.15стр.1гр.3 >=  т.15стр.2гр.3 +  т.15стр.3гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(71,NULL,0,NULL,71,7,0,0,0,'т.15стр.1гр.4 >=  т.15стр.2гр.4 +  т.15стр.3гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(72,NULL,0,NULL,72,7,0,0,0,'т.15стр.4гр.3 >=  т.15стр.5гр.3 +  т.15стр.6гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(73,NULL,0,NULL,73,7,0,0,0,'т.15стр.4гр.4 >=  т.15стр.5гр.4 +  т.15стр.6гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(74,NULL,0,NULL,74,7,0,0,0,'т.15стр.7гр.3 >=  т.15стр.8гр.3',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(75,NULL,0,NULL,75,7,0,0,0,'т.15стр.7гр.4 >=  т.15стр.8гр.4',0,0,1,'20141113','','','','4fss','20140101','','>=',1,'','')
INSERT #A VALUES(76,NULL,0,NULL,76,7,0,0,0,'т.8стр.4гр.4 =  т.8стр.3гр.4 /  т.8стр.2гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(77,NULL,0,NULL,77,7,0,0,0,'т.9стр.3гр.3 =  т.9стр.2гр.3 /  т.9стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(78,NULL,0,NULL,78,7,0,0,0,'т.10стр.5гр.3 =  т.10стр.4гр.3 +  т.10стр.3гр.3 +  т.10стр.2гр.3 /  т.10стр.1гр.3 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(79,NULL,0,NULL,79,7,0,0,0,'т.10стр.5гр.4 =  т.10стр.4гр.4 +  т.10стр.3гр.4 +  т.10стр.2гр.4 /  т.10стр.1гр.4 *  100',1,0,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(80,NULL,0,NULL,80,7,0,0,0,'т.3стр.12гр.4 =  т.3стр.1гр.4 +  т.3стр.3гр.4 +  т.3стр.5гр.4 +  т.3стр.6гр.4 +  т.3стр.7гр.4 +  т.3стр.10гр.4 +  т.3стр.11гр.4',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(81,NULL,0,NULL,81,7,0,0,0,'т.3стр.12гр.5 =  т.3стр.1гр.5 +  т.3стр.3гр.5 +  т.3стр.5гр.5 +  т.3стр.6гр.5 +  т.3стр.7гр.5 +  т.3стр.10гр.5 +  т.3стр.11гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(82,NULL,0,NULL,82,7,0,0,0,'т.12стр.3гр.5 =  т.12стр.4гр.5 +  т.12стр.5гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(83,NULL,0,NULL,83,7,0,0,0,'т.14стр.2гр.3 =  т.14стр.2_1гр.3 +  т.14стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(84,NULL,0,NULL,84,7,0,0,0,'т.14стр.11гр.3 =  т.14стр.11_1гр.3 +  т.14стр.11_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(85,NULL,0,NULL,85,7,0,0,0,'т.14стр.12гр.3 =  т.14стр.12_1гр.3 +  т.14стр.12_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(86,NULL,0,NULL,87,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(87,NULL,0,NULL,88,7,0,0,0,'т.2стр.2гр.3 =  т.2стр.2_1гр.3 +  т.2стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(88,NULL,0,NULL,89,7,0,0,0,'т.2стр.3гр.3 =  т.2стр.3_1гр.3 +  т.2стр.3_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(89,NULL,0,NULL,90,7,0,0,0,'т.2стр.5гр.3 =  т.2стр.5_1гр.3 +  т.2стр.5_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(90,NULL,0,NULL,91,7,0,0,0,'т.2стр.6гр.3 =  т.2стр.6_1гр.3 +  т.2стр.6_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(91,NULL,0,NULL,92,7,0,0,0,'т.2стр.15гр.3 =  т.2стр.15_1гр.3 +  т.2стр.15_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(92,NULL,0,NULL,93,7,0,0,0,'т.2стр.16гр.3 =  т.2стр.16_1гр.3 +  т.2стр.16_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(93,NULL,0,NULL,95,7,0,0,0,'т.3стр.12гр.4 =  т.3стр.1гр.4 +  т.3стр.3гр.4 +  т.3стр.5гр.4 +  т.3стр.6гр.4 +  т.3стр.7гр.4 +  т.3стр.10гр.4 +  т.3стр.11гр.4',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(94,NULL,0,NULL,96,7,0,0,0,'т.3стр.12гр.5 =  т.3стр.1гр.5 +  т.3стр.3гр.5 +  т.3стр.5гр.5 +  т.3стр.6гр.5 +  т.3стр.7гр.5 +  т.3стр.10гр.5 +  т.3стр.11гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(95,NULL,0,NULL,97,7,0,0,0,'т.12стр.3гр.5 =  т.12стр.4гр.5 +  т.12стр.5гр.5',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(96,NULL,0,NULL,98,7,0,0,0,'т.14стр.2гр.3 =  т.14стр.2_1гр.3 +  т.14стр.2_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(97,NULL,0,NULL,99,7,0,0,0,'т.14стр.11гр.3 =  т.14стр.11_1гр.3 +  т.14стр.11_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(98,NULL,0,NULL,100,7,0,0,0,'т.14стр.12гр.3 =  т.14стр.12_1гр.3 +  т.14стр.12_2гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(99,NULL,0,NULL,102,7,0,0,0,'т.14гр.3 =  т.14гр.3 -  т.14гр.3',1,1,1,'20141113','','','','4fss','20140101','','=',0,'','')
INSERT #A VALUES(100,NULL,0,NULL,103,7,0,0,0,'т.2стр.8гр.3 =  т.2стр.1гр.3 +  т.2стр.2гр.3 +  т.2стр.3гр.3 +  т.2стр.4гр.3 +  т.2стр.5гр.3 +  т.2стр.6гр.3 +  т.2стр.7гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(101,NULL,0,NULL,104,7,0,0,0,'т.2стр.18гр.3 =  т.2стр.12гр.3 +  т.2стр.15гр.3 +  т.2стр.16гр.3 +  т.2стр.17гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(102,NULL,0,NULL,105,7,0,0,0,'т.12стр.7гр.3 =  т.12стр.1гр.3 +  т.12стр.2гр.3 +  т.12стр.3гр.3 +  т.12стр.6гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(103,NULL,0,NULL,106,7,0,0,0,'т.12стр.7гр.5 =  т.12стр.1гр.5 +  т.12стр.2гр.5 +  т.12стр.3гр.5 +  т.12стр.6гр.5',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(104,NULL,0,NULL,107,7,0,0,0,'т.12стр.7гр.6 =  т.12стр.1гр.6 +  т.12стр.2гр.6 +  т.12стр.3гр.6 +  т.12стр.6гр.6',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(105,NULL,0,NULL,108,7,0,0,0,'т.12стр.7гр.8 =  т.12стр.1гр.8 +  т.12стр.2гр.8 +  т.12стр.3гр.8 +  т.12стр.6гр.8',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(106,NULL,0,NULL,109,7,0,0,0,'т.12стр.7гр.9 =  т.12стр.1гр.9 +  т.12стр.2гр.9 +  т.12стр.3гр.9 +  т.12стр.6гр.9',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(107,NULL,0,NULL,110,7,0,0,0,'т.12стр.7гр.11 =  т.12стр.1гр.11 +  т.12стр.2гр.11 +  т.12стр.3гр.11 +  т.12стр.6гр.11',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(108,NULL,0,NULL,111,7,0,0,0,'т.12стр.7гр.12 =  т.12стр.1гр.12 +  т.12стр.2гр.12 +  т.12стр.3гр.12 +  т.12стр.6гр.12',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(109,NULL,0,NULL,112,7,0,0,0,'т.12стр.7гр.14 =  т.12стр.1гр.14 +  т.12стр.2гр.14 +  т.12стр.3гр.14 +  т.12стр.6гр.14',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(110,NULL,0,NULL,113,7,0,0,0,'т.12стр.7гр.15 =  т.12стр.1гр.15 +  т.12стр.2гр.15 +  т.12стр.3гр.15 +  т.12стр.6гр.15',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(111,NULL,0,NULL,114,7,0,0,0,'т.12стр.7гр.17 =  т.12стр.1гр.17 +  т.12стр.2гр.17 +  т.12стр.3гр.17 +  т.12стр.6гр.17',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(112,NULL,0,NULL,115,7,0,0,0,'т.12стр.7гр.18 =  т.12стр.1гр.18 +  т.12стр.2гр.18 +  т.12стр.3гр.18 +  т.12стр.6гр.18',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(113,NULL,0,NULL,116,7,0,0,0,'т.12стр.7гр.20 =  т.12стр.1гр.20 +  т.12стр.2гр.20 +  т.12стр.3гр.20 +  т.12стр.6гр.20',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(114,NULL,0,NULL,117,7,0,0,0,'т.14стр.8гр.3 =  т.14стр.1гр.3 +  т.14стр.2гр.3 +  т.14стр.3гр.3 +  т.14стр.4гр.3 +  т.14стр.5гр.3 +  т.14стр.6гр.3 +  т.14стр.7гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(115,NULL,0,NULL,118,7,0,0,0,'т.14стр.14гр.3 =  т.14стр.10гр.3 +  т.14стр.11гр.3 +  т.14стр.12гр.3 +  т.14стр.13гр.3',1,2,1,'20141113','','','','4fss','20140101','','=',1,'','')
INSERT #A VALUES(116,NULL,0,NULL,119,7,0,0,0,'Проверки =  0',0,100,1,'20141113','','','','4fss','20140101','','=',9,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 116
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(3,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(4,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(5,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(6,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(7,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(8,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(9,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(10,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(11,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,3,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,4,0,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(12,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(13,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(14,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(15,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(16,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','6',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(17,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','6',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(18,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(19,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(20,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(21,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(22,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(23,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(23,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(24,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(24,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(25,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(25,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(26,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(26,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','7',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(27,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','7',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(27,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','8',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(28,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(28,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(29,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(29,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(30,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(30,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(31,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(31,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(32,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(32,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(33,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(33,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(34,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(34,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(35,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(35,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(36,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(36,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(37,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(37,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(38,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(38,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(39,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(39,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','10','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(40,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(40,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','9','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(41,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','16',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(41,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','16',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(41,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','16',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(42,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''10''','','','','','3','','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(42,2,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''1'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(43,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(43,2,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(44,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(44,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(44,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(45,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(45,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(45,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(46,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(46,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(46,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(47,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(47,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','8','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(47,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','9','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(48,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(48,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(49,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(49,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(50,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(50,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(51,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(51,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(52,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(52,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(53,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(53,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(54,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(54,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(55,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(55,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(56,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(56,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(57,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(57,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(58,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(58,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(59,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(59,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(60,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(60,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(61,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(61,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(62,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(62,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(63,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(63,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(64,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(64,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(65,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(65,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(66,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','4',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(66,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','4','4',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(67,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','13',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(67,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','13',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(68,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(68,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(69,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(69,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','10','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(70,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(70,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(70,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(71,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(71,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(71,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(72,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(72,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(72,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(73,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(73,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(73,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','6','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(74,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(74,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(75,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','7','15',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(75,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','8','15',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','8',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(76,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','8',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(76,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','9',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(77,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','9',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,3,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','9',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(77,4,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','10',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(78,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,5,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(78,6,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','5','10',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(79,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','4','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','3','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','2','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,5,0,'/',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','4','1','10',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(79,6,1,'*',NULL,NULL,NULL,NULL,0,100,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(80,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(80,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(81,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(81,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(82,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(82,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(82,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(83,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(83,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(83,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(84,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(84,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(84,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(85,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(85,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(85,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(86,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(86,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(86,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(87,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(87,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(87,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(88,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(88,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(88,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(89,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(89,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(89,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(90,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(90,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(90,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(91,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(91,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(91,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(92,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(92,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(92,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16_2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(93,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(93,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','12','3',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(94,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','5','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','10','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(94,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','11','3',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(95,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','4','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(95,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','5','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(96,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(96,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(96,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(97,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(97,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(97,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(98,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(98,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(98,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12_2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(99,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''15'' AND COL(3) < CONVERT(FLOAT,0)','','','','','3','','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(99,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(99,3,4,'-',NULL,NULL,NULL,NULL,0,0,'','','','CODE = ''9''','','','','','3','','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(100,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(100,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','18','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(101,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','15','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','16','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(101,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','17','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(102,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(102,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(103,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(103,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','5','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(104,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(104,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','6','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(105,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(105,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','8','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(106,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(106,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','9','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(107,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(107,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','11','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(108,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(108,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','12','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(109,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(109,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','14','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(110,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(110,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(111,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(111,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(112,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(112,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','18','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','7','12',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(113,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','1','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','2','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','3','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(113,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','20','6','12',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','8','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(114,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','1','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','2','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','3','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','4','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,6,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','5','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,7,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','6','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(114,8,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','7','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','14','14',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(115,2,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','10','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,3,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','11','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,4,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','12','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(115,5,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','13','14',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(116,1,2,'+',NULL,NULL,NULL,NULL,0,0,'SA_4FSS_EXPORT_TEST(0)','Проверки','','','','','','','','','',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(116,2,1,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 418
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo



UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-11-13 10:40:43.617',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-11-13 10:40:43.617'
	BEGIN
		SELECT @vcMessage = 'Форма 4fss с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма 4fss с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-11-13 10:40:43.617. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек  3 2014 10:07:55:893AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : GZ_REES (Рестр закупок товаров, работ, услуг для государственных нужд)
-- Дата ввода : 20070822
-- Дата окончания действия : 20141130
-- Версия : 2014-12-03 10:07:55.893
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : нет
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = 'GZ_REES' AND [START_DATE] = '20070822'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-03 10:07:55.893',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

IF @iOLD_FORM_LINK IS NOT NULL
BEGIN
   SET @vcNEW_FORM_CODE = LEFT('NEW_' + 'GZ_REES',20)
   SELECT @dNEW_START_DATE = MAX([START_DATE]) + 1    FROM dbo.[REPORT_FORMS]    WHERE [CODE] = @vcNEW_FORM_CODE
END
ELSE BEGIN
   SET @vcNEW_FORM_CODE = 'GZ_REES'
END

SET @dNEW_START_DATE = ISNULL(@dNEW_START_DATE,'20070822')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_FORMS.
SELECT @iFORM_TYPE = [LINK] FROM dbo.[S_OBJECTS] WHERE [CODE] = 'SMETA'
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_FORMS]  @iLINK_FORM OUTPUT,'Рестр закупок товаров, работ, услуг для государственных нужд',@vcNEW_FORM_CODE,@dNEW_START_DATE,7,1,1,0,18186,'RB_EXPORT_GZ_REESTR_TO_XML',0,0,'19000101','20141130',NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_FORMS',@iERROR)
END

EXEC @iERROR = dbo.[RN_REPORT_SAVE_REPORT_FORMS_PART2]  @iLINK_FORM, '','bb_gz_reestr_report.bas','','KirRepMakerMultiSheet.xls','bb_gz_reestr_report.xlt','','','RB_EXPORT_GZ_REESTR_TO_XML',0,NULL,NULL,NULL,'          ','',NULL,NULL,'|',1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_REPORT_SAVE_REPORT_FORMS_PART2',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_TABLES.
SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Таблица закупок', @iLINK_FORM,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'ОКДП',@iLINK_TABLE,1,1,1,0,10,1,'BB_USED_OKDP','COL1','CODE',NULL,6,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Договор(документ)',@iLINK_TABLE,1,1,2,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Основание',@iLINK_TABLE,1,1,3,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Способ размещения',@iLINK_TABLE,1,1,4,0,100,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Наименование товаров',@iLINK_TABLE,1,1,5,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Поставщики',@iLINK_TABLE,1,1,6,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Ед. изм.',@iLINK_TABLE,1,1,7,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Объем закупок в нат. выражении по договору',@iLINK_TABLE,1,0,8,0,4,1,NULL,NULL,NULL,'999 999 999 999 999.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Объем закупок в натуральном выражении фактически',@iLINK_TABLE,1,0,9,0,4,1,NULL,NULL,NULL,'999 999 999 999 999.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Цена, по договору',@iLINK_TABLE,1,0,10,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Цена, фактически',@iLINK_TABLE,1,0,11,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Объем закупок в стоимостном выражении, по договору',@iLINK_TABLE,1,0,12,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Объем закупок в стоимостном выражении, фактически',@iLINK_TABLE,1,0,13,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'Фактически оплачено, всего',@iLINK_TABLE,1,0,14,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'Фактически оплачено, бюджет',@iLINK_TABLE,1,0,15,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 16,'Фактически оплачено, ФСС',@iLINK_TABLE,1,0,16,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 17,'Срок действия госконтракта',@iLINK_TABLE,1,1,17,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 18,'Сведения о выполнении',@iLINK_TABLE,1,1,18,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 19,'Малое предприятие',@iLINK_TABLE,1,1,19,0,2,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 20,'Код строки',@iLINK_TABLE,1,1,20,0,0,1,'BB_USED_OKDP','COL1','CODE',NULL,1,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 21,'№ Договора',@iLINK_TABLE,1,1,21,0,10,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 22,'Дата договора',@iLINK_TABLE,1,1,22,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 23,'Документ',@iLINK_TABLE,1,1,23,0,100,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 24,'№ документа',@iLINK_TABLE,1,1,24,0,10,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 25,'Дата документа',@iLINK_TABLE,1,1,25,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 26,'Корреспондент',@iLINK_TABLE,1,1,26,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 27,'Адрес кореспондента',@iLINK_TABLE,1,1,27,0,250,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 28,'Код ПБС',@iLINK_TABLE,1,1,28,0,250,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Таблица закупок', @iLINK_FORM,1, @iLINK_CODE_COL,1,'CALC_SMETA=exec dbo.BB_GZ_REESTR_REPORT @LSF
KEY_FOX=RTRIM(COL1)+''$''+RTRIM(COL28)+''$'' + RTRIM(COL2)
KEY_WEB=RTRIM(isnull(COL1,''''))+''$'' + RTRIM(ISNULL(COL28,''''))+''$'' + RTRIM(ISNULL(COL2,''''))
SPLIT=COL1=LEFT(RTRIM(CODE_ROW),CHARINDEX(''$'',CODE_ROW) - 1)#COL28=SUBSTRING(RTRIM(CODE_ROW),CHARINDEX(''$'',CODE_ROW) + 1, CHARINDEX(''$'',CODE_ROW,CHARINDEX(''$'',CODE_ROW) +1) - CHARINDEX(''$'',CODE_ROW) - 1)',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN

DECLARE @iERROR INT, @iLINK_FORM_NEW INT, @iLINK_FORM INT

SELECT @iLINK_FORM = [LINK_FORM],
       @iLINK_FORM_NEW = [LINK_FORM_NEW]
FROM #tabInfo

--IF @iLINK_FORM_NEW <> @iLINK_FORM
--BEGIN
  EXEC @iERROR = dbo.[RA_UNION_FORM_STRUCT] @iLINK_FORM, @iLINK_FORM_NEW, 1
--END
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UNION_FORM_STRUCT',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.1стр.00гр.12 =  т.1стр.01гр.12 +  т.1стр.02гр.12 +  т.1стр.03гр.12 +  т.1стр.04гр.12 +  т.1стр.05гр.12 +  т.1стр.06гр.12 +  т.1стр.07гр.12 +  т.1стр.08гр.12 +  т.1стр.09гр.12 +  т.1стр.10гр.12 +  т.1стр.11гр.12 +  т.1стр.12гр.12 +  т.1стр.13гр.12 +  т.1стр.14гр.12 +  т.1стр.15гр.12 +  т.1стр.16гр.12 +  т.1стр.17гр.12 +  т.1стр.18гр.12 +  т.1стр.19гр.12 +  т.1стр.20гр.12 +  т.1стр.21гр.12 +  т.1стр.22гр.12 +  т.1стр.23гр.12 +  т.1стр.24гр.12 +  т.1стр.25гр.12 +  т.1стр.26гр.12 +  т.1стр.27гр.12 +  т.1стр.28гр.12 +  т.1стр.29гр.12 +  т.1стр.30гр.12 +  т.1стр.31гр.12 +  т.1стр.32гр.12 +  т.1стр.33гр.12 +  т.1стр.34гр.12 +  т.1стр.35гр.12 +  т.1стр.36гр.12 +  т.1стр.37гр.12 +  т.1стр.38гр.12 +  т.1стр.39гр.12 +  т.1стр.40гр.12 +  т.1стр.41гр.12 +  т.1стр.42гр.12 +  т.1стр.43гр.12',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.1стр.44гр.12 =  т.1стр.45гр.12 +  т.1стр.46гр.12 +  т.1стр.47гр.12',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(3,NULL,0,NULL,3,7,0,0,0,'т.1стр.48гр.12 =  т.1стр.49гр.12 +  т.1стр.50гр.12 +  т.1стр.51гр.12 +  т.1стр.52гр.12 +  т.1стр.53гр.12 +  т.1стр.54гр.12 +  т.1стр.55гр.12 +  т.1стр.56гр.12 +  т.1стр.57гр.12 +  т.1стр.58гр.12 +  т.1стр.59гр.12 +  т.1стр.60гр.12 +  т.1стр.61гр.12 +  т.1стр.62гр.12 +  т.1стр.63гр.12 +  т.1стр.64гр.12 +  т.1стр.65гр.12 +  т.1стр.66гр.12 +  т.1стр.67гр.12 +  т.1стр.68гр.12 +  т.1стр.69гр.12 +  т.1стр.70гр.12 +  т.1стр.71гр.12 +  т.1стр.72гр.12 +  т.1стр.73гр.12 +  т.1стр.74гр.12 +  т.1стр.75гр.12 +  т.1стр.76гр.12 +  т.1стр.77гр.12 +  т.1стр.78гр.12 +  т.1стр.79гр.12 +  т.1стр.80гр.12 +  т.1стр.81гр.12 +  т.1стр.82гр.12 +  т.1стр.83гр.12 +  т.1стр.84гр.12 +  т.1стр.85гр.12 +  т.1стр.86гр.12 +  т.1стр.87гр.12 +  т.1стр.88гр.12 +  т.1стр.89гр.12 +  т.1стр.90гр.12 +  т.1стр.91гр.12 +  т.1стр.92гр.12 +  т.1стр.93гр.12 +  т.1стр.94гр.12 +  т.1стр.95гр.12 +  т.1стр.96гр.12 +  т.1стр.97гр.12 +  т.1стр.98гр.12 +  т.1стр.99гр.12',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(4,NULL,0,NULL,4,7,0,0,0,'т.1стр.00гр.13 =  т.1стр.01гр.13 +  т.1стр.02гр.13 +  т.1стр.03гр.13 +  т.1стр.04гр.13 +  т.1стр.05гр.13 +  т.1стр.06гр.13 +  т.1стр.07гр.13 +  т.1стр.08гр.13 +  т.1стр.09гр.13 +  т.1стр.10гр.13 +  т.1стр.11гр.13 +  т.1стр.12гр.13 +  т.1стр.13гр.13 +  т.1стр.14гр.13 +  т.1стр.15гр.13 +  т.1стр.16гр.13 +  т.1стр.17гр.13 +  т.1стр.18гр.13 +  т.1стр.19гр.13 +  т.1стр.20гр.13 +  т.1стр.21гр.13 +  т.1стр.22гр.13 +  т.1стр.23гр.13 +  т.1стр.24гр.13 +  т.1стр.25гр.13 +  т.1стр.26гр.13 +  т.1стр.27гр.13 +  т.1стр.28гр.13 +  т.1стр.29гр.13 +  т.1стр.30гр.13 +  т.1стр.31гр.13 +  т.1стр.32гр.13 +  т.1стр.33гр.13 +  т.1стр.34гр.13 +  т.1стр.35гр.13 +  т.1стр.36гр.13 +  т.1стр.37гр.13 +  т.1стр.38гр.13 +  т.1стр.39гр.13 +  т.1стр.40гр.13 +  т.1стр.41гр.13 +  т.1стр.42гр.13 +  т.1стр.43гр.13',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(5,NULL,0,NULL,5,7,0,0,0,'т.1стр.44гр.13 =  т.1стр.45гр.13 +  т.1стр.46гр.13 +  т.1стр.47гр.13',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(6,NULL,0,NULL,6,7,0,0,0,'т.1стр.48гр.13 =  т.1стр.49гр.13 +  т.1стр.50гр.13 +  т.1стр.51гр.13 +  т.1стр.52гр.13 +  т.1стр.53гр.13 +  т.1стр.54гр.13 +  т.1стр.55гр.13 +  т.1стр.56гр.13 +  т.1стр.57гр.13 +  т.1стр.58гр.13 +  т.1стр.59гр.13 +  т.1стр.60гр.13 +  т.1стр.61гр.13 +  т.1стр.62гр.13 +  т.1стр.63гр.13 +  т.1стр.64гр.13 +  т.1стр.65гр.13 +  т.1стр.66гр.13 +  т.1стр.67гр.13 +  т.1стр.68гр.13 +  т.1стр.69гр.13 +  т.1стр.70гр.13 +  т.1стр.71гр.13 +  т.1стр.72гр.13 +  т.1стр.73гр.13 +  т.1стр.74гр.13 +  т.1стр.75гр.13 +  т.1стр.76гр.13 +  т.1стр.77гр.13 +  т.1стр.78гр.13 +  т.1стр.79гр.13 +  т.1стр.80гр.13 +  т.1стр.81гр.13 +  т.1стр.82гр.13 +  т.1стр.83гр.13 +  т.1стр.84гр.13 +  т.1стр.85гр.13 +  т.1стр.86гр.13 +  т.1стр.87гр.13 +  т.1стр.88гр.13 +  т.1стр.89гр.13 +  т.1стр.90гр.13 +  т.1стр.91гр.13 +  т.1стр.92гр.13 +  т.1стр.93гр.13 +  т.1стр.94гр.13 +  т.1стр.95гр.13 +  т.1стр.96гр.13 +  т.1стр.97гр.13 +  т.1стр.98гр.13 +  т.1стр.99гр.13',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(7,NULL,0,NULL,7,7,0,0,0,'т.1стр.00гр.14 =  т.1стр.01гр.14 +  т.1стр.02гр.14 +  т.1стр.03гр.14 +  т.1стр.04гр.14 +  т.1стр.05гр.14 +  т.1стр.06гр.14 +  т.1стр.07гр.14 +  т.1стр.08гр.14 +  т.1стр.09гр.14 +  т.1стр.10гр.14 +  т.1стр.11гр.14 +  т.1стр.12гр.14 +  т.1стр.13гр.14 +  т.1стр.14гр.14 +  т.1стр.15гр.14 +  т.1стр.16гр.14 +  т.1стр.17гр.14 +  т.1стр.18гр.14 +  т.1стр.19гр.14 +  т.1стр.20гр.14 +  т.1стр.21гр.14 +  т.1стр.22гр.14 +  т.1стр.23гр.14 +  т.1стр.24гр.14 +  т.1стр.25гр.14 +  т.1стр.26гр.14 +  т.1стр.27гр.14 +  т.1стр.28гр.14 +  т.1стр.29гр.14 +  т.1стр.30гр.14 +  т.1стр.31гр.14 +  т.1стр.32гр.14 +  т.1стр.33гр.14 +  т.1стр.34гр.14 +  т.1стр.35гр.14 +  т.1стр.36гр.14 +  т.1стр.37гр.14 +  т.1стр.38гр.14 +  т.1стр.39гр.14 +  т.1стр.40гр.14 +  т.1стр.41гр.14 +  т.1стр.42гр.14 +  т.1стр.43гр.14',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(8,NULL,0,NULL,8,7,0,0,0,'т.1стр.44гр.14 =  т.1стр.45гр.14 +  т.1стр.46гр.14 +  т.1стр.47гр.14',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(9,NULL,0,NULL,9,7,0,0,0,'т.1стр.48гр.14 =  т.1стр.49гр.14 +  т.1стр.50гр.14 +  т.1стр.51гр.14 +  т.1стр.52гр.14 +  т.1стр.53гр.14 +  т.1стр.54гр.14 +  т.1стр.55гр.14 +  т.1стр.56гр.14 +  т.1стр.57гр.14 +  т.1стр.58гр.14 +  т.1стр.59гр.14 +  т.1стр.60гр.14 +  т.1стр.61гр.14 +  т.1стр.62гр.14 +  т.1стр.63гр.14 +  т.1стр.64гр.14 +  т.1стр.65гр.14 +  т.1стр.66гр.14 +  т.1стр.67гр.14 +  т.1стр.68гр.14 +  т.1стр.69гр.14 +  т.1стр.70гр.14 +  т.1стр.71гр.14 +  т.1стр.72гр.14 +  т.1стр.73гр.14 +  т.1стр.74гр.14 +  т.1стр.75гр.14 +  т.1стр.76гр.14 +  т.1стр.77гр.14 +  т.1стр.78гр.14 +  т.1стр.79гр.14 +  т.1стр.80гр.14 +  т.1стр.81гр.14 +  т.1стр.82гр.14 +  т.1стр.83гр.14 +  т.1стр.84гр.14 +  т.1стр.85гр.14 +  т.1стр.86гр.14 +  т.1стр.87гр.14 +  т.1стр.88гр.14 +  т.1стр.89гр.14 +  т.1стр.90гр.14 +  т.1стр.91гр.14 +  т.1стр.92гр.14 +  т.1стр.93гр.14 +  т.1стр.94гр.14 +  т.1стр.95гр.14 +  т.1стр.96гр.14 +  т.1стр.97гр.14 +  т.1стр.98гр.14 +  т.1стр.99гр.14',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(10,NULL,0,NULL,10,7,0,0,0,'т.1стр.00гр.15 =  т.1стр.01гр.15 +  т.1стр.02гр.15 +  т.1стр.03гр.15 +  т.1стр.04гр.15 +  т.1стр.05гр.15 +  т.1стр.06гр.15 +  т.1стр.07гр.15 +  т.1стр.08гр.15 +  т.1стр.09гр.15 +  т.1стр.10гр.15 +  т.1стр.11гр.15 +  т.1стр.12гр.15 +  т.1стр.13гр.15 +  т.1стр.14гр.15 +  т.1стр.15гр.15 +  т.1стр.16гр.15 +  т.1стр.17гр.15 +  т.1стр.18гр.15 +  т.1стр.19гр.15 +  т.1стр.20гр.15 +  т.1стр.21гр.15 +  т.1стр.22гр.15 +  т.1стр.23гр.15 +  т.1стр.24гр.15 +  т.1стр.25гр.15 +  т.1стр.26гр.15 +  т.1стр.27гр.15 +  т.1стр.28гр.15 +  т.1стр.29гр.15 +  т.1стр.30гр.15 +  т.1стр.31гр.15 +  т.1стр.32гр.15 +  т.1стр.33гр.15 +  т.1стр.34гр.15 +  т.1стр.35гр.15 +  т.1стр.36гр.15 +  т.1стр.37гр.15 +  т.1стр.38гр.15 +  т.1стр.39гр.15 +  т.1стр.40гр.15 +  т.1стр.41гр.15 +  т.1стр.42гр.15 +  т.1стр.43гр.15',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(11,NULL,0,NULL,11,7,0,0,0,'т.1стр.44гр.15 =  т.1стр.45гр.15 +  т.1стр.46гр.15 +  т.1стр.47гр.15',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(12,NULL,0,NULL,12,7,0,0,0,'т.1стр.48гр.15 =  т.1стр.49гр.15 +  т.1стр.50гр.15 +  т.1стр.51гр.15 +  т.1стр.52гр.15 +  т.1стр.53гр.15 +  т.1стр.54гр.15 +  т.1стр.55гр.15 +  т.1стр.56гр.15 +  т.1стр.57гр.15 +  т.1стр.58гр.15 +  т.1стр.59гр.15 +  т.1стр.60гр.15 +  т.1стр.61гр.15 +  т.1стр.62гр.15 +  т.1стр.63гр.15 +  т.1стр.64гр.15 +  т.1стр.65гр.15 +  т.1стр.66гр.15 +  т.1стр.67гр.15 +  т.1стр.68гр.15 +  т.1стр.69гр.15 +  т.1стр.70гр.15 +  т.1стр.71гр.15 +  т.1стр.72гр.15 +  т.1стр.73гр.15 +  т.1стр.74гр.15 +  т.1стр.75гр.15 +  т.1стр.76гр.15 +  т.1стр.77гр.15 +  т.1стр.78гр.15 +  т.1стр.79гр.15 +  т.1стр.80гр.15 +  т.1стр.81гр.15 +  т.1стр.82гр.15 +  т.1стр.83гр.15 +  т.1стр.84гр.15 +  т.1стр.85гр.15 +  т.1стр.86гр.15 +  т.1стр.87гр.15 +  т.1стр.88гр.15 +  т.1стр.89гр.15 +  т.1стр.90гр.15 +  т.1стр.91гр.15 +  т.1стр.92гр.15 +  т.1стр.93гр.15 +  т.1стр.94гр.15 +  т.1стр.95гр.15 +  т.1стр.96гр.15 +  т.1стр.97гр.15 +  т.1стр.98гр.15 +  т.1стр.99гр.15',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(13,NULL,0,NULL,13,7,0,0,0,'т.1стр.00гр.16 =  т.1стр.01гр.16 +  т.1стр.02гр.16 +  т.1стр.03гр.16 +  т.1стр.04гр.16 +  т.1стр.05гр.16 +  т.1стр.06гр.16 +  т.1стр.07гр.16 +  т.1стр.08гр.16 +  т.1стр.09гр.16 +  т.1стр.10гр.16 +  т.1стр.11гр.16 +  т.1стр.12гр.16 +  т.1стр.13гр.16 +  т.1стр.14гр.16 +  т.1стр.15гр.16 +  т.1стр.16гр.16 +  т.1стр.17гр.16 +  т.1стр.18гр.16 +  т.1стр.19гр.16 +  т.1стр.20гр.16 +  т.1стр.21гр.16 +  т.1стр.22гр.16 +  т.1стр.23гр.16 +  т.1стр.24гр.16 +  т.1стр.25гр.16 +  т.1стр.26гр.16 +  т.1стр.27гр.16 +  т.1стр.28гр.16 +  т.1стр.29гр.16 +  т.1стр.30гр.16 +  т.1стр.31гр.16 +  т.1стр.32гр.16 +  т.1стр.33гр.16 +  т.1стр.34гр.16 +  т.1стр.35гр.16 +  т.1стр.36гр.16 +  т.1стр.37гр.16 +  т.1стр.38гр.16 +  т.1стр.39гр.16 +  т.1стр.40гр.16 +  т.1стр.41гр.16 +  т.1стр.42гр.16 +  т.1стр.43гр.16',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(14,NULL,0,NULL,14,7,0,0,0,'т.1стр.44гр.16 =  т.1стр.45гр.16 +  т.1стр.46гр.16 +  т.1стр.47гр.16',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(15,NULL,0,NULL,15,7,0,0,0,'т.1стр.48гр.16 =  т.1стр.49гр.16 +  т.1стр.50гр.16 +  т.1стр.51гр.16 +  т.1стр.52гр.16 +  т.1стр.53гр.16 +  т.1стр.54гр.16 +  т.1стр.55гр.16 +  т.1стр.56гр.16 +  т.1стр.57гр.16 +  т.1стр.58гр.16 +  т.1стр.59гр.16 +  т.1стр.60гр.16 +  т.1стр.61гр.16 +  т.1стр.62гр.16 +  т.1стр.63гр.16 +  т.1стр.64гр.16 +  т.1стр.65гр.16 +  т.1стр.66гр.16 +  т.1стр.67гр.16 +  т.1стр.68гр.16 +  т.1стр.69гр.16 +  т.1стр.70гр.16 +  т.1стр.71гр.16 +  т.1стр.72гр.16 +  т.1стр.73гр.16 +  т.1стр.74гр.16 +  т.1стр.75гр.16 +  т.1стр.76гр.16 +  т.1стр.77гр.16 +  т.1стр.78гр.16 +  т.1стр.79гр.16 +  т.1стр.80гр.16 +  т.1стр.81гр.16 +  т.1стр.82гр.16 +  т.1стр.83гр.16 +  т.1стр.84гр.16 +  т.1стр.85гр.16 +  т.1стр.86гр.16 +  т.1стр.87гр.16 +  т.1стр.88гр.16 +  т.1стр.89гр.16 +  т.1стр.90гр.16 +  т.1стр.91гр.16 +  т.1стр.92гр.16 +  т.1стр.93гр.16 +  т.1стр.94гр.16 +  т.1стр.95гр.16 +  т.1стр.96гр.16 +  т.1стр.97гр.16 +  т.1стр.98гр.16 +  т.1стр.99гр.16',1,0,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(16,NULL,0,NULL,16,7,0,0,0,'т.1стр.ITOGгр.12 =  т.1стр.00гр.12 +  т.1стр.44гр.12 +  т.1стр.48гр.12',1,1,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(17,NULL,0,NULL,17,7,0,0,0,'т.1стр.ITOGгр.13 =  т.1стр.00гр.13 +  т.1стр.44гр.13 +  т.1стр.48гр.13',1,1,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(18,NULL,0,NULL,18,7,0,0,0,'т.1стр.ITOGгр.14 =  т.1стр.00гр.14 +  т.1стр.44гр.14 +  т.1стр.48гр.14',1,1,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(19,NULL,0,NULL,19,7,0,0,0,'т.1стр.ITOGгр.15 =  т.1стр.00гр.15 +  т.1стр.44гр.15 +  т.1стр.48гр.15',1,1,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(20,NULL,0,NULL,20,7,0,0,0,'т.1стр.ITOGгр.16 =  т.1стр.00гр.16 +  т.1стр.44гр.16 +  т.1стр.48гр.16',1,1,1,'20120608','','','','GZ_REES','20070822','','=',1,'','')
INSERT #A VALUES(21,NULL,0,NULL,23,7,0,0,0,'т.1 =  т.1',1,0,1,'20120608','','','','GZ_REES','20070822','','=',0,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 21
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(3,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(4,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(5,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(6,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(7,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(8,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(9,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(10,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(11,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(12,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(13,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(14,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(15,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(16,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(17,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(18,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(19,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(20,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','isnull(dbo.RA_GETWORDNUM(CODE,2,''$''),'''')=''''','','CODE','','','','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(21,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','isnull(dbo.RA_GETWORDNUM(CODE,2,''$''),'''')=''''','','CODE','','','','','1',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 522
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-- Обновление связей с группами форм.

DELETE dbo.[REPORT_FORM_GROUPS_REF]
WHERE [LINK_FORM] = @iLINK_FORM

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '999999    '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'999999','формы отчетности',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

-- Переформирование процедур RI_PROC_T.
DECLARE curTable CURSOR FOR
SELECT [LINK_TABLE],
       [ORDERS]
FROM [REPORT_TABLES]
WHERE [LINK_FORM] = @iLINK_FORM

OPEN curTable

FETCH NEXT
FROM curTable
INTO @iTABLE_LINK,
     @tTABLE_ORDER

WHILE @@FETCH_STATUS = 0
BEGIN
   EXEC @iERROR = dbo.[I_REPORT_CREATE_PROC] @iTABLE_LINK
   IF @iERROR <> 0
   BEGIN
      INSERT #tabErrorLog VALUES ('I_REPORT_CREATE_PROC',@iERROR)
   END
   FETCH NEXT
   FROM curTable
   INTO @iTABLE_LINK,
        @tTABLE_ORDER
END
CLOSE curTable
DEALLOCATE curTable

EXEC dbo.[I_CONTROL_RULES_ACTION] 3, @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-03 10:07:55.893',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-03 10:07:55.893'
	BEGIN
		SELECT @vcMessage = 'Форма GZ_REES с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма GZ_REES с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-03 10:07:55.893. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек  4 2014  9:51:03:080AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : GZ_REES (Рестр закупок товаров, работ, услуг для государственных нужд)
-- Дата ввода : 20141201
-- Дата окончания действия :
-- Версия : 2014-12-04 09:51:03.073
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : нет
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = 'GZ_REES' AND [START_DATE] = '20141201'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-04 09:51:03.073',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

IF @iOLD_FORM_LINK IS NOT NULL
BEGIN
   SET @vcNEW_FORM_CODE = LEFT('NEW_' + 'GZ_REES',20)
   SELECT @dNEW_START_DATE = MAX([START_DATE]) + 1    FROM dbo.[REPORT_FORMS]    WHERE [CODE] = @vcNEW_FORM_CODE
END
ELSE BEGIN
   SET @vcNEW_FORM_CODE = 'GZ_REES'
END

SET @dNEW_START_DATE = ISNULL(@dNEW_START_DATE,'20141201')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_FORMS.
SELECT @iFORM_TYPE = [LINK] FROM dbo.[S_OBJECTS] WHERE [CODE] = 'SMETA'
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_FORMS]  @iLINK_FORM OUTPUT,'Рестр закупок товаров, работ, услуг для государственных нужд',@vcNEW_FORM_CODE,@dNEW_START_DATE,7,1,1,0,18186,'RB_EXPORT_GZ_REESTR_TO_XML',0,0,'19000101',NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_FORMS',@iERROR)
END

EXEC @iERROR = dbo.[RN_REPORT_SAVE_REPORT_FORMS_PART2]  @iLINK_FORM, '','bb_gz_reestr_report.bas','','KirRepMakerMultiSheet.xls','bb_gz_reestr_report.xlt','',NULL,'RB_EXPORT_GZ_REESTR_TO_XML',0,NULL,NULL,NULL,'          ','',NULL,NULL,'|',1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_REPORT_SAVE_REPORT_FORMS_PART2',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_TABLES.
SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Таблица закупок', @iLINK_FORM,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'ОКПД',@iLINK_TABLE,1,1,1,0,12,1,'BB_USED_OKPD','COL1','CODE',NULL,6,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Договор(документ)',@iLINK_TABLE,1,1,2,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Основание',@iLINK_TABLE,1,1,3,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Способ размещения',@iLINK_TABLE,1,1,4,0,100,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Наименование товаров',@iLINK_TABLE,1,1,5,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Поставщики',@iLINK_TABLE,1,1,6,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Ед. изм.',@iLINK_TABLE,1,1,7,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Объем закупок в нат. выражении по договору',@iLINK_TABLE,1,0,8,0,4,1,NULL,NULL,NULL,'999 999 999 999 999.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Объем закупок в натуральном выражении фактически',@iLINK_TABLE,1,0,9,0,4,1,NULL,NULL,NULL,'999 999 999 999 999.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Цена, по договору',@iLINK_TABLE,1,0,10,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Цена, фактически',@iLINK_TABLE,1,0,11,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Объем закупок в стоимостном выражении, по договору',@iLINK_TABLE,1,0,12,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Объем закупок в стоимостном выражении, фактически',@iLINK_TABLE,1,0,13,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'Фактически оплачено, всего',@iLINK_TABLE,1,0,14,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'Фактически оплачено, бюджет',@iLINK_TABLE,1,0,15,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 16,'Фактически оплачено, ФСС',@iLINK_TABLE,1,0,16,0,3,1,NULL,NULL,NULL,'999 999 999 999 999.999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 17,'Срок действия госконтракта',@iLINK_TABLE,1,1,17,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 18,'Сведения о выполнении',@iLINK_TABLE,1,1,18,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 19,'Малое предприятие',@iLINK_TABLE,1,1,19,0,2,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 20,'Код строки',@iLINK_TABLE,1,1,20,0,0,1,'BB_USED_OKDP','COL1','CODE',NULL,1,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 21,'№ Договора',@iLINK_TABLE,1,1,21,0,10,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 22,'Дата договора',@iLINK_TABLE,1,1,22,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 23,'Документ',@iLINK_TABLE,1,1,23,0,100,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 24,'№ документа',@iLINK_TABLE,1,1,24,0,10,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 25,'Дата документа',@iLINK_TABLE,1,1,25,0,20,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 26,'Корреспондент',@iLINK_TABLE,1,1,26,0,254,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 27,'Адрес кореспондента',@iLINK_TABLE,1,1,27,0,250,1,'','','',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 28,'Код ПБС',@iLINK_TABLE,1,1,28,0,250,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Таблица закупок', @iLINK_FORM,1, @iLINK_CODE_COL,1,'CALC_SMETA=exec dbo.BB_GZ_REESTR_REPORT_2014 @LSF
KEY_FOX=RTRIM(COL1)+''$''+RTRIM(COL28)+''$'' + RTRIM(COL2)
KEY_WEB=RTRIM(isnull(COL1,''''))+''$'' + RTRIM(ISNULL(COL28,''''))+''$'' + RTRIM(ISNULL(COL2,''''))
SPLIT=COL1=LEFT(RTRIM(CODE_ROW),CHARINDEX(''$'',CODE_ROW) - 1)#COL28=SUBSTRING(RTRIM(CODE_ROW),CHARINDEX(''$'',CODE_ROW) + 1, CHARINDEX(''$'',CODE_ROW,CHARINDEX(''$'',CODE_ROW) +1) - CHARINDEX(''$'',CODE_ROW) - 1)',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN

DECLARE @iERROR INT, @iLINK_FORM_NEW INT, @iLINK_FORM INT

SELECT @iLINK_FORM = [LINK_FORM],
       @iLINK_FORM_NEW = [LINK_FORM_NEW]
FROM #tabInfo

--IF @iLINK_FORM_NEW <> @iLINK_FORM
--BEGIN
  EXEC @iERROR = dbo.[RA_UNION_FORM_STRUCT] @iLINK_FORM, @iLINK_FORM_NEW, 1
--END
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UNION_FORM_STRUCT',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.1стр.00гр.12 =  т.1стр.01гр.12 +  т.1стр.02гр.12 +  т.1стр.03гр.12 +  т.1стр.04гр.12 +  т.1стр.05гр.12 +  т.1стр.06гр.12 +  т.1стр.07гр.12 +  т.1стр.08гр.12 +  т.1стр.09гр.12 +  т.1стр.10гр.12 +  т.1стр.11гр.12 +  т.1стр.12гр.12 +  т.1стр.13гр.12 +  т.1стр.14гр.12 +  т.1стр.15гр.12 +  т.1стр.16гр.12 +  т.1стр.17гр.12 +  т.1стр.18гр.12 +  т.1стр.19гр.12 +  т.1стр.20гр.12 +  т.1стр.21гр.12 +  т.1стр.22гр.12 +  т.1стр.23гр.12 +  т.1стр.24гр.12 +  т.1стр.25гр.12 +  т.1стр.26гр.12 +  т.1стр.27гр.12 +  т.1стр.28гр.12 +  т.1стр.29гр.12 +  т.1стр.30гр.12 +  т.1стр.31гр.12 +  т.1стр.32гр.12 +  т.1стр.33гр.12 +  т.1стр.34гр.12 +  т.1стр.35гр.12 +  т.1стр.36гр.12 +  т.1стр.37гр.12 +  т.1стр.38гр.12 +  т.1стр.39гр.12 +  т.1стр.40гр.12 +  т.1стр.41гр.12 +  т.1стр.42гр.12 +  т.1стр.43гр.12',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.1стр.44гр.12 =  т.1стр.45гр.12 +  т.1стр.46гр.12 +  т.1стр.47гр.12',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(3,NULL,0,NULL,3,7,0,0,0,'т.1стр.48гр.12 =  т.1стр.49гр.12 +  т.1стр.50гр.12 +  т.1стр.51гр.12 +  т.1стр.52гр.12 +  т.1стр.53гр.12 +  т.1стр.54гр.12 +  т.1стр.55гр.12 +  т.1стр.56гр.12 +  т.1стр.57гр.12 +  т.1стр.58гр.12 +  т.1стр.59гр.12 +  т.1стр.60гр.12 +  т.1стр.61гр.12 +  т.1стр.62гр.12 +  т.1стр.63гр.12 +  т.1стр.64гр.12 +  т.1стр.65гр.12 +  т.1стр.66гр.12 +  т.1стр.67гр.12 +  т.1стр.68гр.12 +  т.1стр.69гр.12 +  т.1стр.70гр.12 +  т.1стр.71гр.12 +  т.1стр.72гр.12 +  т.1стр.73гр.12 +  т.1стр.74гр.12 +  т.1стр.75гр.12 +  т.1стр.76гр.12 +  т.1стр.77гр.12 +  т.1стр.78гр.12 +  т.1стр.79гр.12 +  т.1стр.80гр.12 +  т.1стр.81гр.12 +  т.1стр.82гр.12 +  т.1стр.83гр.12 +  т.1стр.84гр.12 +  т.1стр.85гр.12 +  т.1стр.86гр.12 +  т.1стр.87гр.12 +  т.1стр.88гр.12 +  т.1стр.89гр.12 +  т.1стр.90гр.12 +  т.1стр.91гр.12 +  т.1стр.92гр.12 +  т.1стр.93гр.12 +  т.1стр.94гр.12 +  т.1стр.95гр.12 +  т.1стр.96гр.12 +  т.1стр.97гр.12 +  т.1стр.98гр.12 +  т.1стр.99гр.12',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(4,NULL,0,NULL,4,7,0,0,0,'т.1стр.00гр.13 =  т.1стр.01гр.13 +  т.1стр.02гр.13 +  т.1стр.03гр.13 +  т.1стр.04гр.13 +  т.1стр.05гр.13 +  т.1стр.06гр.13 +  т.1стр.07гр.13 +  т.1стр.08гр.13 +  т.1стр.09гр.13 +  т.1стр.10гр.13 +  т.1стр.11гр.13 +  т.1стр.12гр.13 +  т.1стр.13гр.13 +  т.1стр.14гр.13 +  т.1стр.15гр.13 +  т.1стр.16гр.13 +  т.1стр.17гр.13 +  т.1стр.18гр.13 +  т.1стр.19гр.13 +  т.1стр.20гр.13 +  т.1стр.21гр.13 +  т.1стр.22гр.13 +  т.1стр.23гр.13 +  т.1стр.24гр.13 +  т.1стр.25гр.13 +  т.1стр.26гр.13 +  т.1стр.27гр.13 +  т.1стр.28гр.13 +  т.1стр.29гр.13 +  т.1стр.30гр.13 +  т.1стр.31гр.13 +  т.1стр.32гр.13 +  т.1стр.33гр.13 +  т.1стр.34гр.13 +  т.1стр.35гр.13 +  т.1стр.36гр.13 +  т.1стр.37гр.13 +  т.1стр.38гр.13 +  т.1стр.39гр.13 +  т.1стр.40гр.13 +  т.1стр.41гр.13 +  т.1стр.42гр.13 +  т.1стр.43гр.13',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(5,NULL,0,NULL,5,7,0,0,0,'т.1стр.44гр.13 =  т.1стр.45гр.13 +  т.1стр.46гр.13 +  т.1стр.47гр.13',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(6,NULL,0,NULL,6,7,0,0,0,'т.1стр.48гр.13 =  т.1стр.49гр.13 +  т.1стр.50гр.13 +  т.1стр.51гр.13 +  т.1стр.52гр.13 +  т.1стр.53гр.13 +  т.1стр.54гр.13 +  т.1стр.55гр.13 +  т.1стр.56гр.13 +  т.1стр.57гр.13 +  т.1стр.58гр.13 +  т.1стр.59гр.13 +  т.1стр.60гр.13 +  т.1стр.61гр.13 +  т.1стр.62гр.13 +  т.1стр.63гр.13 +  т.1стр.64гр.13 +  т.1стр.65гр.13 +  т.1стр.66гр.13 +  т.1стр.67гр.13 +  т.1стр.68гр.13 +  т.1стр.69гр.13 +  т.1стр.70гр.13 +  т.1стр.71гр.13 +  т.1стр.72гр.13 +  т.1стр.73гр.13 +  т.1стр.74гр.13 +  т.1стр.75гр.13 +  т.1стр.76гр.13 +  т.1стр.77гр.13 +  т.1стр.78гр.13 +  т.1стр.79гр.13 +  т.1стр.80гр.13 +  т.1стр.81гр.13 +  т.1стр.82гр.13 +  т.1стр.83гр.13 +  т.1стр.84гр.13 +  т.1стр.85гр.13 +  т.1стр.86гр.13 +  т.1стр.87гр.13 +  т.1стр.88гр.13 +  т.1стр.89гр.13 +  т.1стр.90гр.13 +  т.1стр.91гр.13 +  т.1стр.92гр.13 +  т.1стр.93гр.13 +  т.1стр.94гр.13 +  т.1стр.95гр.13 +  т.1стр.96гр.13 +  т.1стр.97гр.13 +  т.1стр.98гр.13 +  т.1стр.99гр.13',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(7,NULL,0,NULL,7,7,0,0,0,'т.1стр.00гр.14 =  т.1стр.01гр.14 +  т.1стр.02гр.14 +  т.1стр.03гр.14 +  т.1стр.04гр.14 +  т.1стр.05гр.14 +  т.1стр.06гр.14 +  т.1стр.07гр.14 +  т.1стр.08гр.14 +  т.1стр.09гр.14 +  т.1стр.10гр.14 +  т.1стр.11гр.14 +  т.1стр.12гр.14 +  т.1стр.13гр.14 +  т.1стр.14гр.14 +  т.1стр.15гр.14 +  т.1стр.16гр.14 +  т.1стр.17гр.14 +  т.1стр.18гр.14 +  т.1стр.19гр.14 +  т.1стр.20гр.14 +  т.1стр.21гр.14 +  т.1стр.22гр.14 +  т.1стр.23гр.14 +  т.1стр.24гр.14 +  т.1стр.25гр.14 +  т.1стр.26гр.14 +  т.1стр.27гр.14 +  т.1стр.28гр.14 +  т.1стр.29гр.14 +  т.1стр.30гр.14 +  т.1стр.31гр.14 +  т.1стр.32гр.14 +  т.1стр.33гр.14 +  т.1стр.34гр.14 +  т.1стр.35гр.14 +  т.1стр.36гр.14 +  т.1стр.37гр.14 +  т.1стр.38гр.14 +  т.1стр.39гр.14 +  т.1стр.40гр.14 +  т.1стр.41гр.14 +  т.1стр.42гр.14 +  т.1стр.43гр.14',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(8,NULL,0,NULL,8,7,0,0,0,'т.1стр.44гр.14 =  т.1стр.45гр.14 +  т.1стр.46гр.14 +  т.1стр.47гр.14',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(9,NULL,0,NULL,9,7,0,0,0,'т.1стр.48гр.14 =  т.1стр.49гр.14 +  т.1стр.50гр.14 +  т.1стр.51гр.14 +  т.1стр.52гр.14 +  т.1стр.53гр.14 +  т.1стр.54гр.14 +  т.1стр.55гр.14 +  т.1стр.56гр.14 +  т.1стр.57гр.14 +  т.1стр.58гр.14 +  т.1стр.59гр.14 +  т.1стр.60гр.14 +  т.1стр.61гр.14 +  т.1стр.62гр.14 +  т.1стр.63гр.14 +  т.1стр.64гр.14 +  т.1стр.65гр.14 +  т.1стр.66гр.14 +  т.1стр.67гр.14 +  т.1стр.68гр.14 +  т.1стр.69гр.14 +  т.1стр.70гр.14 +  т.1стр.71гр.14 +  т.1стр.72гр.14 +  т.1стр.73гр.14 +  т.1стр.74гр.14 +  т.1стр.75гр.14 +  т.1стр.76гр.14 +  т.1стр.77гр.14 +  т.1стр.78гр.14 +  т.1стр.79гр.14 +  т.1стр.80гр.14 +  т.1стр.81гр.14 +  т.1стр.82гр.14 +  т.1стр.83гр.14 +  т.1стр.84гр.14 +  т.1стр.85гр.14 +  т.1стр.86гр.14 +  т.1стр.87гр.14 +  т.1стр.88гр.14 +  т.1стр.89гр.14 +  т.1стр.90гр.14 +  т.1стр.91гр.14 +  т.1стр.92гр.14 +  т.1стр.93гр.14 +  т.1стр.94гр.14 +  т.1стр.95гр.14 +  т.1стр.96гр.14 +  т.1стр.97гр.14 +  т.1стр.98гр.14 +  т.1стр.99гр.14',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(10,NULL,0,NULL,10,7,0,0,0,'т.1стр.00гр.15 =  т.1стр.01гр.15 +  т.1стр.02гр.15 +  т.1стр.03гр.15 +  т.1стр.04гр.15 +  т.1стр.05гр.15 +  т.1стр.06гр.15 +  т.1стр.07гр.15 +  т.1стр.08гр.15 +  т.1стр.09гр.15 +  т.1стр.10гр.15 +  т.1стр.11гр.15 +  т.1стр.12гр.15 +  т.1стр.13гр.15 +  т.1стр.14гр.15 +  т.1стр.15гр.15 +  т.1стр.16гр.15 +  т.1стр.17гр.15 +  т.1стр.18гр.15 +  т.1стр.19гр.15 +  т.1стр.20гр.15 +  т.1стр.21гр.15 +  т.1стр.22гр.15 +  т.1стр.23гр.15 +  т.1стр.24гр.15 +  т.1стр.25гр.15 +  т.1стр.26гр.15 +  т.1стр.27гр.15 +  т.1стр.28гр.15 +  т.1стр.29гр.15 +  т.1стр.30гр.15 +  т.1стр.31гр.15 +  т.1стр.32гр.15 +  т.1стр.33гр.15 +  т.1стр.34гр.15 +  т.1стр.35гр.15 +  т.1стр.36гр.15 +  т.1стр.37гр.15 +  т.1стр.38гр.15 +  т.1стр.39гр.15 +  т.1стр.40гр.15 +  т.1стр.41гр.15 +  т.1стр.42гр.15 +  т.1стр.43гр.15',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(11,NULL,0,NULL,11,7,0,0,0,'т.1стр.44гр.15 =  т.1стр.45гр.15 +  т.1стр.46гр.15 +  т.1стр.47гр.15',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(12,NULL,0,NULL,12,7,0,0,0,'т.1стр.48гр.15 =  т.1стр.49гр.15 +  т.1стр.50гр.15 +  т.1стр.51гр.15 +  т.1стр.52гр.15 +  т.1стр.53гр.15 +  т.1стр.54гр.15 +  т.1стр.55гр.15 +  т.1стр.56гр.15 +  т.1стр.57гр.15 +  т.1стр.58гр.15 +  т.1стр.59гр.15 +  т.1стр.60гр.15 +  т.1стр.61гр.15 +  т.1стр.62гр.15 +  т.1стр.63гр.15 +  т.1стр.64гр.15 +  т.1стр.65гр.15 +  т.1стр.66гр.15 +  т.1стр.67гр.15 +  т.1стр.68гр.15 +  т.1стр.69гр.15 +  т.1стр.70гр.15 +  т.1стр.71гр.15 +  т.1стр.72гр.15 +  т.1стр.73гр.15 +  т.1стр.74гр.15 +  т.1стр.75гр.15 +  т.1стр.76гр.15 +  т.1стр.77гр.15 +  т.1стр.78гр.15 +  т.1стр.79гр.15 +  т.1стр.80гр.15 +  т.1стр.81гр.15 +  т.1стр.82гр.15 +  т.1стр.83гр.15 +  т.1стр.84гр.15 +  т.1стр.85гр.15 +  т.1стр.86гр.15 +  т.1стр.87гр.15 +  т.1стр.88гр.15 +  т.1стр.89гр.15 +  т.1стр.90гр.15 +  т.1стр.91гр.15 +  т.1стр.92гр.15 +  т.1стр.93гр.15 +  т.1стр.94гр.15 +  т.1стр.95гр.15 +  т.1стр.96гр.15 +  т.1стр.97гр.15 +  т.1стр.98гр.15 +  т.1стр.99гр.15',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(13,NULL,0,NULL,13,7,0,0,0,'т.1стр.00гр.16 =  т.1стр.01гр.16 +  т.1стр.02гр.16 +  т.1стр.03гр.16 +  т.1стр.04гр.16 +  т.1стр.05гр.16 +  т.1стр.06гр.16 +  т.1стр.07гр.16 +  т.1стр.08гр.16 +  т.1стр.09гр.16 +  т.1стр.10гр.16 +  т.1стр.11гр.16 +  т.1стр.12гр.16 +  т.1стр.13гр.16 +  т.1стр.14гр.16 +  т.1стр.15гр.16 +  т.1стр.16гр.16 +  т.1стр.17гр.16 +  т.1стр.18гр.16 +  т.1стр.19гр.16 +  т.1стр.20гр.16 +  т.1стр.21гр.16 +  т.1стр.22гр.16 +  т.1стр.23гр.16 +  т.1стр.24гр.16 +  т.1стр.25гр.16 +  т.1стр.26гр.16 +  т.1стр.27гр.16 +  т.1стр.28гр.16 +  т.1стр.29гр.16 +  т.1стр.30гр.16 +  т.1стр.31гр.16 +  т.1стр.32гр.16 +  т.1стр.33гр.16 +  т.1стр.34гр.16 +  т.1стр.35гр.16 +  т.1стр.36гр.16 +  т.1стр.37гр.16 +  т.1стр.38гр.16 +  т.1стр.39гр.16 +  т.1стр.40гр.16 +  т.1стр.41гр.16 +  т.1стр.42гр.16 +  т.1стр.43гр.16',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(14,NULL,0,NULL,14,7,0,0,0,'т.1стр.44гр.16 =  т.1стр.45гр.16 +  т.1стр.46гр.16 +  т.1стр.47гр.16',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(15,NULL,0,NULL,15,7,0,0,0,'т.1стр.48гр.16 =  т.1стр.49гр.16 +  т.1стр.50гр.16 +  т.1стр.51гр.16 +  т.1стр.52гр.16 +  т.1стр.53гр.16 +  т.1стр.54гр.16 +  т.1стр.55гр.16 +  т.1стр.56гр.16 +  т.1стр.57гр.16 +  т.1стр.58гр.16 +  т.1стр.59гр.16 +  т.1стр.60гр.16 +  т.1стр.61гр.16 +  т.1стр.62гр.16 +  т.1стр.63гр.16 +  т.1стр.64гр.16 +  т.1стр.65гр.16 +  т.1стр.66гр.16 +  т.1стр.67гр.16 +  т.1стр.68гр.16 +  т.1стр.69гр.16 +  т.1стр.70гр.16 +  т.1стр.71гр.16 +  т.1стр.72гр.16 +  т.1стр.73гр.16 +  т.1стр.74гр.16 +  т.1стр.75гр.16 +  т.1стр.76гр.16 +  т.1стр.77гр.16 +  т.1стр.78гр.16 +  т.1стр.79гр.16 +  т.1стр.80гр.16 +  т.1стр.81гр.16 +  т.1стр.82гр.16 +  т.1стр.83гр.16 +  т.1стр.84гр.16 +  т.1стр.85гр.16 +  т.1стр.86гр.16 +  т.1стр.87гр.16 +  т.1стр.88гр.16 +  т.1стр.89гр.16 +  т.1стр.90гр.16 +  т.1стр.91гр.16 +  т.1стр.92гр.16 +  т.1стр.93гр.16 +  т.1стр.94гр.16 +  т.1стр.95гр.16 +  т.1стр.96гр.16 +  т.1стр.97гр.16 +  т.1стр.98гр.16 +  т.1стр.99гр.16',1,0,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(16,NULL,0,NULL,16,7,0,0,0,'т.1стр.ITOGгр.12 =  т.1стр.00гр.12 +  т.1стр.44гр.12 +  т.1стр.48гр.12',1,1,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(17,NULL,0,NULL,17,7,0,0,0,'т.1стр.ITOGгр.13 =  т.1стр.00гр.13 +  т.1стр.44гр.13 +  т.1стр.48гр.13',1,1,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(18,NULL,0,NULL,18,7,0,0,0,'т.1стр.ITOGгр.14 =  т.1стр.00гр.14 +  т.1стр.44гр.14 +  т.1стр.48гр.14',1,1,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(19,NULL,0,NULL,19,7,0,0,0,'т.1стр.ITOGгр.15 =  т.1стр.00гр.15 +  т.1стр.44гр.15 +  т.1стр.48гр.15',1,1,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(20,NULL,0,NULL,20,7,0,0,0,'т.1стр.ITOGгр.16 =  т.1стр.00гр.16 +  т.1стр.44гр.16 +  т.1стр.48гр.16',1,1,1,'20120608','','','','GZ_REES','20141201','','=',1,'','')
INSERT #A VALUES(21,NULL,0,NULL,21,7,0,0,0,'т.1 =  т.1',1,0,1,'20120608','','','','GZ_REES','20141201','','=',0,'','')
INSERT #A VALUES(22,NULL,0,NULL,22,7,0,0,0,'0 =',1,1,1,'20141204','','','','GZ_REES','20141201','','=',9,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 22
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(3,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(3,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(4,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(4,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(5,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(5,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(6,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(6,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(7,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(7,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(8,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(8,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(9,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(9,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(10,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(10,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(11,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(11,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(12,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(12,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(13,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','01','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','02','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','03','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','04','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','05','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','06','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','07','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','08','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','09','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','10','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','11','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','12','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','13','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','14','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','15','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','16','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','17','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','18','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','19','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','20','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','21','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','22','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','23','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','24','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','25','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','26','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','27','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','28','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','29','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','30','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','31','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','32','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','33','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','34','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','35','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','36','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','37','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','38','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','39','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','40','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','41','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','42','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(13,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','43','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(14,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','45','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','46','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(14,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','47','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(15,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','49','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','50','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','51','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,5,3,'+',NULL,NULL,NULL,NULL,0,0,'','','52','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,6,3,'+',NULL,NULL,NULL,NULL,0,0,'','','53','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,7,3,'+',NULL,NULL,NULL,NULL,0,0,'','','54','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,8,3,'+',NULL,NULL,NULL,NULL,0,0,'','','55','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,9,3,'+',NULL,NULL,NULL,NULL,0,0,'','','56','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,10,3,'+',NULL,NULL,NULL,NULL,0,0,'','','57','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,11,3,'+',NULL,NULL,NULL,NULL,0,0,'','','58','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,12,3,'+',NULL,NULL,NULL,NULL,0,0,'','','59','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,13,3,'+',NULL,NULL,NULL,NULL,0,0,'','','60','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,14,3,'+',NULL,NULL,NULL,NULL,0,0,'','','61','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,15,3,'+',NULL,NULL,NULL,NULL,0,0,'','','62','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,16,3,'+',NULL,NULL,NULL,NULL,0,0,'','','63','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,17,3,'+',NULL,NULL,NULL,NULL,0,0,'','','64','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,18,3,'+',NULL,NULL,NULL,NULL,0,0,'','','65','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,19,3,'+',NULL,NULL,NULL,NULL,0,0,'','','66','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,20,3,'+',NULL,NULL,NULL,NULL,0,0,'','','67','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,21,3,'+',NULL,NULL,NULL,NULL,0,0,'','','68','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,22,3,'+',NULL,NULL,NULL,NULL,0,0,'','','69','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,23,3,'+',NULL,NULL,NULL,NULL,0,0,'','','70','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,24,3,'+',NULL,NULL,NULL,NULL,0,0,'','','71','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,25,3,'+',NULL,NULL,NULL,NULL,0,0,'','','72','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,26,3,'+',NULL,NULL,NULL,NULL,0,0,'','','73','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,27,3,'+',NULL,NULL,NULL,NULL,0,0,'','','74','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,28,3,'+',NULL,NULL,NULL,NULL,0,0,'','','75','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,29,3,'+',NULL,NULL,NULL,NULL,0,0,'','','76','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,30,3,'+',NULL,NULL,NULL,NULL,0,0,'','','77','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,31,3,'+',NULL,NULL,NULL,NULL,0,0,'','','78','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,32,3,'+',NULL,NULL,NULL,NULL,0,0,'','','79','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,33,3,'+',NULL,NULL,NULL,NULL,0,0,'','','80','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,34,3,'+',NULL,NULL,NULL,NULL,0,0,'','','81','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,35,3,'+',NULL,NULL,NULL,NULL,0,0,'','','82','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,36,3,'+',NULL,NULL,NULL,NULL,0,0,'','','83','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,37,3,'+',NULL,NULL,NULL,NULL,0,0,'','','84','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,38,3,'+',NULL,NULL,NULL,NULL,0,0,'','','85','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,39,3,'+',NULL,NULL,NULL,NULL,0,0,'','','86','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,40,3,'+',NULL,NULL,NULL,NULL,0,0,'','','87','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,41,3,'+',NULL,NULL,NULL,NULL,0,0,'','','88','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,42,3,'+',NULL,NULL,NULL,NULL,0,0,'','','89','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,43,3,'+',NULL,NULL,NULL,NULL,0,0,'','','90','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,44,3,'+',NULL,NULL,NULL,NULL,0,0,'','','91','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,45,3,'+',NULL,NULL,NULL,NULL,0,0,'','','92','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,46,3,'+',NULL,NULL,NULL,NULL,0,0,'','','93','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,47,3,'+',NULL,NULL,NULL,NULL,0,0,'','','94','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,48,3,'+',NULL,NULL,NULL,NULL,0,0,'','','95','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,49,3,'+',NULL,NULL,NULL,NULL,0,0,'','','96','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,50,3,'+',NULL,NULL,NULL,NULL,0,0,'','','97','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,51,3,'+',NULL,NULL,NULL,NULL,0,0,'','','98','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(15,52,3,'+',NULL,NULL,NULL,NULL,0,0,'','','99','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','12','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(16,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(16,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','12','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','13','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(17,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(17,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','13','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','14','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(18,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(18,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','14','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','15','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(19,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(19,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','15','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','ITOG','','','','','','16','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(20,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','00','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,3,3,'+',NULL,NULL,NULL,NULL,0,0,'','','44','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(20,4,3,'+',NULL,NULL,NULL,NULL,0,0,'','','48','','','','','','16','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(21,1,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','isnull(dbo.RA_GETWORDNUM(CODE,2,''$''),'''')=''''','','CODE','','','','','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(21,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','isnull(dbo.RA_GETWORDNUM(CODE,2,''$''),'''')=''''','','CODE','','','','','1',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(22,1,1,'+',NULL,NULL,NULL,NULL,0,0,'','','','0','','','','','','','',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(22,2,2,'+',NULL,NULL,NULL,NULL,0,0,'BB_GZ_REESTR_REPORT_ITOG_2014(0)','','','0','','','','','','','',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 524
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-- Обновление связей с группами форм.

DELETE dbo.[REPORT_FORM_GROUPS_REF]
WHERE [LINK_FORM] = @iLINK_FORM

-- Переформирование процедур RI_PROC_T.
DECLARE curTable CURSOR FOR
SELECT [LINK_TABLE],
       [ORDERS]
FROM [REPORT_TABLES]
WHERE [LINK_FORM] = @iLINK_FORM

OPEN curTable

FETCH NEXT
FROM curTable
INTO @iTABLE_LINK,
     @tTABLE_ORDER

WHILE @@FETCH_STATUS = 0
BEGIN
   EXEC @iERROR = dbo.[I_REPORT_CREATE_PROC] @iTABLE_LINK
   IF @iERROR <> 0
   BEGIN
      INSERT #tabErrorLog VALUES ('I_REPORT_CREATE_PROC',@iERROR)
   END
   FETCH NEXT
   FROM curTable
   INTO @iTABLE_LINK,
        @tTABLE_ORDER
END
CLOSE curTable
DEALLOCATE curTable

EXEC dbo.[I_CONTROL_RULES_ACTION] 3, @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-04 09:51:03.073',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-04 09:51:03.073'
	BEGIN
		SELECT @vcMessage = 'Форма GZ_REES с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма GZ_REES с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-04 09:51:03.073. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 24 2014  8:18:20:547AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : ND_TN (Налоговая декларация по транспортному налогу)
-- Дата ввода : 20130101
-- Дата окончания действия : 20131231
-- Версия : 2014-12-24 08:18:20.543
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : нет
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = 'ND_TN' AND [START_DATE] = '20130101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-24 08:18:20.543',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

IF @iOLD_FORM_LINK IS NOT NULL
BEGIN
   SET @vcNEW_FORM_CODE = LEFT('NEW_' + 'ND_TN',20)
   SELECT @dNEW_START_DATE = MAX([START_DATE]) + 1    FROM dbo.[REPORT_FORMS]    WHERE [CODE] = @vcNEW_FORM_CODE
END
ELSE BEGIN
   SET @vcNEW_FORM_CODE = 'ND_TN'
END

SET @dNEW_START_DATE = ISNULL(@dNEW_START_DATE,'20130101')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_FORMS.
SELECT @iFORM_TYPE = [LINK] FROM dbo.[S_OBJECTS] WHERE [CODE] = 'SMETA'
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_FORMS]  @iLINK_FORM OUTPUT,'Налоговая декларация по транспортному налогу',@vcNEW_FORM_CODE,@dNEW_START_DATE,1,0,1,1,18186,'i_report_export_nalog',0,0,'19000101','20131231','Приказ ФНС от 20 февраля 2012 г. N ММВ-7-11/99@ (изм. от 14.11.2013 г. N ММВ-7-3/501@)'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_FORMS',@iERROR)
END

EXEC @iERROR = dbo.[RN_REPORT_SAVE_REPORT_FORMS_PART2]  @iLINK_FORM, '','nd_tn_2013.bas','print_nd_tn_2013()','kirrepmakermultisheet.xls','ND_TN_F1152004_2013.XLT','',NULL,'i_report_export_nalog',0,NULL,NULL,NULL,'          ','',NULL,NULL,'|',1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_REPORT_SAVE_REPORT_FORMS_PART2',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_TABLES.
SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Раздел 1', @iLINK_FORM,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Блок',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код по ОКТМО',@iLINK_TABLE,0,1,2,0,11,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Исчисленная сумма налога, подлежащая уплате в бюджет',@iLINK_TABLE,0,0,3,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Сумма авансовых платежей - 1 кв.',@iLINK_TABLE,0,0,4,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Сумма авансовых платежей - 2 кв.',@iLINK_TABLE,1,0,5,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Сумма авансовых платежей - 3 кв.',@iLINK_TABLE,1,0,6,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Сумма налога, подлежащая уплате в бюджет по итогам налоговаого периода',@iLINK_TABLE,1,0,7,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Сумма налога к уменьшению',@iLINK_TABLE,1,0,8,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Код дохода',@iLINK_TABLE,1,1,9,0,20,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Номер корректировки',@iLINK_TABLE,1,1,10,0,3,1,NULL,NULL,NULL,'999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Код по месту нахождения (учета)',@iLINK_TABLE,1,1,11,0,3,1,'DICTIONARY_PLACE_ND_IMU','COL11','CODE',NULL,4,NULL,'CODE = ''213'' OR CODE = ''216'' OR CODE = ''260'''
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Код налогового периода',@iLINK_TABLE,1,1,12,0,2,1,'DICTIONARY_TAX_PERIOD','COL12','CODE',NULL,4,NULL,'CODE = ''34'' OR CODE = ''50'''
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Код формы реорганизации (ликвидации)',@iLINK_TABLE,1,1,13,0,1,1,'DICTIONARY_REORG_DEP','COL11','CODE',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'ИНН реорг. орг-ции',@iLINK_TABLE,1,1,14,0,12,1,NULL,NULL,NULL,'999999999999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'КПП реорг. орг-ции',@iLINK_TABLE,1,1,15,0,9,1,NULL,NULL,NULL,'999999999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Раздел 1', @iLINK_FORM,1, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Раздел 2', @iLINK_FORM,2
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'№ п/п',@iLINK_TABLE,1,1,1,0,3,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код вида транспортного средства',@iLINK_TABLE,1,1,2,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Идентификационный номер транспортного средства',@iLINK_TABLE,0,1,3,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Марка транспортного средства',@iLINK_TABLE,0,1,4,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Регистрац. знак транспортного средства',@iLINK_TABLE,0,1,5,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Налоговая база',@iLINK_TABLE,0,0,6,0,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Единица измерения налоговой базы по ОКЕИ',@iLINK_TABLE,0,1,7,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Экологический класс',@iLINK_TABLE,1,1,8,0,1,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Кол-во лет, прошедших с выпуска ТС',@iLINK_TABLE,1,0,9,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Количество полных месяцев владения транспортным средством',@iLINK_TABLE,1,0,10,0,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Коэффициент Кв',@iLINK_TABLE,1,0,11,0,4,1,NULL,NULL,NULL,'9.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Ставка налога',@iLINK_TABLE,1,0,12,0,2,1,NULL,NULL,NULL,'999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Сумма исчисленного налога',@iLINK_TABLE,1,0,13,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'Количество полных месяцев использования льготы',@iLINK_TABLE,1,0,14,0,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'Коэффициент Кл',@iLINK_TABLE,1,0,15,0,4,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 16,'Код налоговой льготы освобождения',@iLINK_TABLE,1,1,16,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 17,'Сумма налоговай льготы освобожд. (руб.)',@iLINK_TABLE,1,0,17,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 18,'Код налоговой льготы к уменьшению',@iLINK_TABLE,0,1,18,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 19,'Сумма налоговой льготы к уменьшению',@iLINK_TABLE,0,0,19,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 20,'Код налоговой льготы в виде снижения',@iLINK_TABLE,0,1,20,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 21,'Сумма налоговой льготы в виде снижения',@iLINK_TABLE,0,0,21,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 22,'Исчисленная сумма налога, подлежащая уплате в бюджет',@iLINK_TABLE,1,0,22,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Раздел 2', @iLINK_FORM,2, @iLINK_CODE_COL,1,'CALC_SMETA=exec dbo.RK_CALC_TN_2012 @depLink, @dateBeginPeriod, @dateEndPeriod',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

DECLARE @iError INT

-- Выгрузка строк статических таблиц.
IF OBJECT_ID('tempdb..#R') IS NOT NULL
BEGIN
   DROP TABLE #R
END

CREATE TABLE #R([ORDERS]      SMALLINT,
                [LINK_TABLE]  INT,
                [CALC_ORDERS] SMALLINT,
                [PRINT_NULL]  TINYINT)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #R',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN
INSERT #R VALUES (1,1,1,1)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #R) <> 1
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #R',0)
END

ALTER TABLE dbo.[REPORT_ROWS] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_ROWS] ([ORDERS],
                          [LINK_TABLE],
                          [CALC_ORDERS],
                          [PRINT_NULL])
SELECT [C].[ORDERS],
       [B].[LINK_TABLE],
       [C].[CALC_ORDERS],
       [C].[PRINT_NULL]
FROM #tabInfo            [A]
JOIN dbo.[REPORT_TABLES] [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN #R                  [C] ON [B].[ORDERS] = [C].[LINK_TABLE]

ALTER TABLE dbo.[REPORT_ROWS] ENABLE TRIGGER ALL

DROP TABLE #R

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

-- Выгрузка REPORT_FORMULA.
IF OBJECT_ID('tempdb..#F') IS NOT NULL
BEGIN
   DROP TABLE #F
END

CREATE TABLE #F([ORDER_TABLE] INT,
                [ORDER_ROW]   INT,
                [ORDER_COL]   INT,
                [FORMULA]  VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #F',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
INSERT #F VALUES (1,1,1,'Блок                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (1,1,2,'АВПЛАТ3_НАСТРОЙКА("О_К_Т_М_О")')
INSERT #F VALUES (1,1,9,'АВПЛАТ3_НАСТРОЙКА("Т.Н.ДОХ.КОД")')
INSERT #F VALUES (1,1,11,'214')
INSERT #F VALUES (1,1,12,'34')

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #F) <> 5
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #F',0)
END

ALTER TABLE dbo.[REPORT_FORMULA] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_FORMULA] ([LINK_ROW],
                             [LINK_COL],
                             [FORMULA])
SELECT [D].[LINK_ROW],
       [C].[LINK_COL],
       [E].[FORMULA]
FROM #tabInfo              [A]
JOIN dbo.[REPORT_TABLES]   [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN dbo.[REPORT_COLOUMNS] [C] ON [B].[LINK_TABLE] = [C].[LINK_TABLE]
JOIN dbo.[REPORT_ROWS]     [D] ON [B].[LINK_TABLE] = [D].[LINK_TABLE]
JOIN #F                    [E] ON [E].[ORDER_TABLE] = [B].[ORDERS] AND [E].[ORDER_COL] = [C].[ORDERS] AND [E].[ORDER_ROW] = [D].[ORDERS]

ALTER TABLE dbo.[REPORT_FORMULA] ENABLE TRIGGER ALL

DROP TABLE #F

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN

DECLARE @iERROR INT, @iLINK_FORM_NEW INT, @iLINK_FORM INT

SELECT @iLINK_FORM = [LINK_FORM],
       @iLINK_FORM_NEW = [LINK_FORM_NEW]
FROM #tabInfo

--IF @iLINK_FORM_NEW <> @iLINK_FORM
--BEGIN
  EXEC @iERROR = dbo.[RA_UNION_FORM_STRUCT] @iLINK_FORM, @iLINK_FORM_NEW, 1
--END
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UNION_FORM_STRUCT',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.2гр.22 =  т.2гр.13 -  т.2гр.17',1,0,1,'20140201','','','','ND_TN','20130101','','=',3,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.1стр.Блокгр.3 =  т.2гр.22',1,1,1,'20140201','','','','ND_TN','20130101','','=',0,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','22','','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','13','','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,3,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','17','','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','Блок','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','Code <> ''итого''','','','','','22','','2',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 5
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-- Обновление связей с группами форм.

DELETE dbo.[REPORT_FORM_GROUPS_REF]
WHERE [LINK_FORM] = @iLINK_FORM

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '5         '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'5','Годовые формы',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '6         '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'6','Пользовательские формы',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

SET @iGF_LINK = NULL
SELECT @iGF_LINK = [LINK] FROM dbo.[REPORT_FORM_GROUPS] WHERE [CODE] = '999999    '
EXEC @iERROR = dbo.[RV_UPDATE_REPORT_FORM_GROUPS] @iGF_LINK OUTPUT,'999999','формы отчетности',0,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RV_UPDATE_REPORT_FORM_GROUPS',@iERROR)
END

EXEC @iERROR = dbo.[RA_UPDATE_FORM_GROUPS_REF] @iLINK_FORM, @iGF_LINK
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UPDATE_FORM_GROUPS_REF',@iERROR)
END

-- Переформирование процедур RI_PROC_T.
DECLARE curTable CURSOR FOR
SELECT [LINK_TABLE],
       [ORDERS]
FROM [REPORT_TABLES]
WHERE [LINK_FORM] = @iLINK_FORM

OPEN curTable

FETCH NEXT
FROM curTable
INTO @iTABLE_LINK,
     @tTABLE_ORDER

WHILE @@FETCH_STATUS = 0
BEGIN
   EXEC @iERROR = dbo.[I_REPORT_CREATE_PROC] @iTABLE_LINK
   IF @iERROR <> 0
   BEGIN
      INSERT #tabErrorLog VALUES ('I_REPORT_CREATE_PROC',@iERROR)
   END
   FETCH NEXT
   FROM curTable
   INTO @iTABLE_LINK,
        @tTABLE_ORDER
END
CLOSE curTable
DEALLOCATE curTable

EXEC dbo.[I_CONTROL_RULES_ACTION] 3, @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-24 08:18:20.543',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-24 08:18:20.543'
	BEGIN
		SELECT @vcMessage = 'Форма ND_TN с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма ND_TN с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-24 08:18:20.543. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_FORM_STRUCT. (дек 24 2014  8:18:34:350AM)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Выгрузка структуры формы отчетности : ND_TN (Налоговая декларация по транспортному налогу)
-- Дата ввода : 20140101
-- Дата окончания действия :
-- Версия : 2014-12-24 08:18:34.350
-- Параметры выгрузки :
-- экспортировать внутридокументные КС          : да
-- выгружать только внутридокументные КС        : нет
-- удалять системные КС старой версии           : да
-- удалять все версии формы кроме текущей       : нет
-- удалять пользовательские КС старой версии    : нет
-- не обновлять форму при совпадении дат версий : нет

SET NOCOUNT               ON
SET ANSI_NULLS            ON  -- Правильная обработка NULL.
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

DECLARE @iERROR INT, @iLINK_FORM INT, @iLINK_TABLE INT, @iFORM_TYPE INT,
        @iLINK_COL INT, @iLINK_CODE_COL INT, @iLINK_ROW INT, @iLINK_TOTAL INT,
        @iOLD_FORM_LINK INT, @vcNEW_FORM_CODE VARCHAR(20), @dNEW_START_DATE DATETIME, @dOLD_UPDATE_DATE DATETIME

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

IF OBJECT_ID('tempdb..#tabStop') IS NOT NULL
BEGIN
   DROP TABLE #tabStop
END
CREATE TABLE #tabStop([CURRENT_DATE] VARCHAR(100))

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabStop',@iERROR)
END

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL
BEGIN
   DROP TABLE #tabInfo
END
CREATE TABLE #tabInfo([LINK_FORM] INT, [LINK_FORM_NEW] INT)

SET @iERROR = @@ERROR
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabInfo',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Определение старой формы текущей версии. Изменение ее кода, чтобы не мешать установке новой формы.
SELECT @iOLD_FORM_LINK = [LINK_FORM], @dOLD_UPDATE_DATE = [UPDATE_DATE]FROM dbo.[REPORT_FORMS] WHERE [CODE] = 'ND_TN' AND [START_DATE] = '20140101'

IF @dOLD_UPDATE_DATE > CONVERT(DATETIME,'2014-12-24 08:18:34.350',121)
BEGIN
   INSERT #tabStop VALUES(CONVERT(VARCHAR(50),@dOLD_UPDATE_DATE,121))
END

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

IF @iOLD_FORM_LINK IS NOT NULL
BEGIN
   SET @vcNEW_FORM_CODE = LEFT('NEW_' + 'ND_TN',20)
   SELECT @dNEW_START_DATE = MAX([START_DATE]) + 1    FROM dbo.[REPORT_FORMS]    WHERE [CODE] = @vcNEW_FORM_CODE
END
ELSE BEGIN
   SET @vcNEW_FORM_CODE = 'ND_TN'
END

SET @dNEW_START_DATE = ISNULL(@dNEW_START_DATE,'20140101')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_FORMS.
SELECT @iFORM_TYPE = [LINK] FROM dbo.[S_OBJECTS] WHERE [CODE] = 'SMETA'
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_FORMS]  @iLINK_FORM OUTPUT,'Налоговая декларация по транспортному налогу',@vcNEW_FORM_CODE,@dNEW_START_DATE,1,0,1,1,18186,'i_report_export_nalog',0,0,'19000101',NULL,'Приказ ФНС от 25 апреля 2014 г. N ММВ-7-11/254@ (изм. в приказ ФНС от 20 февраля 2012 г. N ММВ-7-11/99@")'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_FORMS',@iERROR)
END

EXEC @iERROR = dbo.[RN_REPORT_SAVE_REPORT_FORMS_PART2]  @iLINK_FORM, '','nd_tn_2015.bas','print_nd_tn_2015()','kirrepmakermultisheet.xls','ND_TN_F1152004_2015.XLT','',NULL,'i_report_export_nalog',0,NULL,NULL,NULL,'          ','',NULL,NULL,'|',1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_REPORT_SAVE_REPORT_FORMS_PART2',@iERROR)
END

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Сохранение в табл. REPORT_TABLES.
SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Раздел 1', @iLINK_FORM,1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'Блок',@iLINK_TABLE,1,1,1,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код по ОКТМО',@iLINK_TABLE,0,1,2,0,11,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Исчисленная сумма налога, подлежащая уплате в бюджет',@iLINK_TABLE,0,0,3,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Сумма авансовых платежей - 1 кв.',@iLINK_TABLE,0,0,4,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Сумма авансовых платежей - 2 кв.',@iLINK_TABLE,1,0,5,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Сумма авансовых платежей - 3 кв.',@iLINK_TABLE,1,0,6,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Сумма налога, подлежащая уплате в бюджет по итогам налоговаого периода',@iLINK_TABLE,1,0,7,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Сумма налога к уменьшению',@iLINK_TABLE,1,0,8,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Код дохода',@iLINK_TABLE,1,1,9,0,20,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Номер корректировки',@iLINK_TABLE,1,1,10,0,3,1,NULL,NULL,NULL,'999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Код по месту нахождения (учета)',@iLINK_TABLE,1,1,11,0,3,1,'DICTIONARY_PLACE_ND_IMU','COL11','CODE',NULL,4,NULL,'CODE = ''213'' OR CODE = ''216'' OR CODE = ''260'''
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Код налогового периода',@iLINK_TABLE,1,1,12,0,2,1,'DICTIONARY_TAX_PERIOD','COL12','CODE',NULL,4,NULL,'CODE = ''34'' OR CODE = ''50'''
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Код формы реорганизации (ликвидации)',@iLINK_TABLE,1,1,13,0,1,1,'DICTIONARY_REORG_DEP','COL11','CODE',NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'ИНН реорг. орг-ции',@iLINK_TABLE,1,1,14,0,12,1,NULL,NULL,NULL,'999999999999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'КПП реорг. орг-ции',@iLINK_TABLE,1,1,15,0,9,1,NULL,NULL,NULL,'999999999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Раздел 1', @iLINK_FORM,1, @iLINK_CODE_COL,0,'',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

SET @iLINK_TABLE = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE OUTPUT, 'Раздел 2', @iLINK_FORM,2
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END


-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_DINAMIC_TOTALS.

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Сохранение в табл. REPORT_COLOUMNS.
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 1,'№ п/п',@iLINK_TABLE,1,1,1,0,3,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_CODE_COL = @iLINK_COL
SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 2,'Код вида транспортного средства',@iLINK_TABLE,1,1,2,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 3,'Идентификационный номер транспортного средства',@iLINK_TABLE,0,1,3,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 4,'Марка транспортного средства',@iLINK_TABLE,0,1,4,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 5,'Регистрац. знак транспортного средства',@iLINK_TABLE,0,1,5,0,100,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 6,'Налоговая база',@iLINK_TABLE,0,0,6,0,2,1,NULL,NULL,NULL,'999 999 999 999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 7,'Единица измерения налоговой базы по ОКЕИ',@iLINK_TABLE,0,1,7,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 8,'Экологический класс',@iLINK_TABLE,1,1,8,0,1,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 9,'Кол-во лет, прошедших с выпуска ТС',@iLINK_TABLE,1,0,9,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 10,'Количество полных месяцев владения транспортным средством',@iLINK_TABLE,1,0,10,0,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 11,'Доля налогоплательщика  в праве на транспортное средство',@iLINK_TABLE,1,1,11,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 12,'Коэффициент Кв',@iLINK_TABLE,1,0,12,0,4,1,NULL,NULL,NULL,'9.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 13,'Ставка налога',@iLINK_TABLE,1,0,13,0,2,1,NULL,NULL,NULL,'999 999.99',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 14,'Коэффициент Кп',@iLINK_TABLE,1,0,14,0,1,1,NULL,NULL,NULL,'9.9',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 15,'Сумма исчисленного налога',@iLINK_TABLE,1,0,15,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 16,'Количество полных месяцев использования льготы',@iLINK_TABLE,1,0,16,0,0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 17,'Коэффициент Кл',@iLINK_TABLE,1,0,17,0,4,1,NULL,NULL,NULL,'9.9999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 18,'Код налоговой льготы освобождения',@iLINK_TABLE,1,1,18,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 19,'Сумма налоговой льготы освобожд. (руб.)',@iLINK_TABLE,1,0,19,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 20,'Код налоговой льготы к уменьшению',@iLINK_TABLE,0,1,20,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 21,'Сумма налоговой льготы к уменьшению',@iLINK_TABLE,1,0,21,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 22,'Код налоговой льготы в виде снижения',@iLINK_TABLE,0,1,22,0,50,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 23,'Сумма налоговой льготы в виде снижения',@iLINK_TABLE,0,0,23,0,0,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


SET @iLINK_COL = NULL
EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_COLOUMNS] @iLINK_COL OUTPUT, 24,'Исчисленная сумма налога, подлежащая уплате в бюджет',@iLINK_TABLE,1,0,24,0,2,1,NULL,NULL,NULL,'999 999 999 999 999',NULL,NULL,NULL
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_COLOUMNS',@iERROR)
END


EXEC @iERROR = dbo.[I_REPORT_SAVE_REPORT_TABLES] @iLINK_TABLE, 'Раздел 2', @iLINK_FORM,2, @iLINK_CODE_COL,1,'CALC_SMETA=exec dbo.RK_CALC_TN_2015 @depLink, @dateBeginPeriod, @dateEndPeriod',NULL,0
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('I_REPORT_SAVE_REPORT_TABLES',@iERROR)
END

INSERT #tabInfo VALUES (COALESCE(@iOLD_FORM_LINK, @iLINK_FORM), @iLINK_FORM)

DELETE FROM dbo.[REPORT_CONTROL_RULES] WHERE [LINK_FORM] = @iOLD_FORM_LINK AND [IsSystemsRule] = 1
END -- проверка признака остановки в #tabStop

GO

-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Выгрузка для статических таблиц.

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN

DECLARE @iError INT

-- Выгрузка строк статических таблиц.
IF OBJECT_ID('tempdb..#R') IS NOT NULL
BEGIN
   DROP TABLE #R
END

CREATE TABLE #R([ORDERS]      SMALLINT,
                [LINK_TABLE]  INT,
                [CALC_ORDERS] SMALLINT,
                [PRINT_NULL]  TINYINT)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #R',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop)
BEGIN
INSERT #R VALUES (1,1,1,1)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #R) <> 1
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #R',0)
END

ALTER TABLE dbo.[REPORT_ROWS] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_ROWS] ([ORDERS],
                          [LINK_TABLE],
                          [CALC_ORDERS],
                          [PRINT_NULL])
SELECT [C].[ORDERS],
       [B].[LINK_TABLE],
       [C].[CALC_ORDERS],
       [C].[PRINT_NULL]
FROM #tabInfo            [A]
JOIN dbo.[REPORT_TABLES] [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN #R                  [C] ON [B].[ORDERS] = [C].[LINK_TABLE]

ALTER TABLE dbo.[REPORT_ROWS] ENABLE TRIGGER ALL

DROP TABLE #R

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

-- Выгрузка REPORT_FORMULA.
IF OBJECT_ID('tempdb..#F') IS NOT NULL
BEGIN
   DROP TABLE #F
END

CREATE TABLE #F([ORDER_TABLE] INT,
                [ORDER_ROW]   INT,
                [ORDER_COL]   INT,
                [FORMULA]  VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #F',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
INSERT #F VALUES (1,1,1,'Блок                                                                                                                                                                                                                                                          ')
INSERT #F VALUES (1,1,2,'АВПЛАТ3_НАСТРОЙКА("О_К_Т_М_О")')
INSERT #F VALUES (1,1,9,'АВПЛАТ3_НАСТРОЙКА("Т.Н.ДОХ.КОД")')
INSERT #F VALUES (1,1,11,'260')
INSERT #F VALUES (1,1,12,'34')

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #F) <> 5
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #F',0)
END

ALTER TABLE dbo.[REPORT_FORMULA] DISABLE TRIGGER ALL

INSERT dbo.[REPORT_FORMULA] ([LINK_ROW],
                             [LINK_COL],
                             [FORMULA])
SELECT [D].[LINK_ROW],
       [C].[LINK_COL],
       [E].[FORMULA]
FROM #tabInfo              [A]
JOIN dbo.[REPORT_TABLES]   [B] ON [A].[LINK_FORM_NEW] = [B].[LINK_FORM]
JOIN dbo.[REPORT_COLOUMNS] [C] ON [B].[LINK_TABLE] = [C].[LINK_TABLE]
JOIN dbo.[REPORT_ROWS]     [D] ON [B].[LINK_TABLE] = [D].[LINK_TABLE]
JOIN #F                    [E] ON [E].[ORDER_TABLE] = [B].[ORDERS] AND [E].[ORDER_COL] = [C].[ORDERS] AND [E].[ORDER_ROW] = [D].[ORDERS]

ALTER TABLE dbo.[REPORT_FORMULA] ENABLE TRIGGER ALL

DROP TABLE #F

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN

DECLARE @iERROR INT, @iLINK_FORM_NEW INT, @iLINK_FORM INT

SELECT @iLINK_FORM = [LINK_FORM],
       @iLINK_FORM_NEW = [LINK_FORM_NEW]
FROM #tabInfo

--IF @iLINK_FORM_NEW <> @iLINK_FORM
--BEGIN
  EXEC @iERROR = dbo.[RA_UNION_FORM_STRUCT] @iLINK_FORM, @iLINK_FORM_NEW, 1
--END
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RA_UNION_FORM_STRUCT',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Установка внутридокументных правил КС формы.
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#A') IS NOT NULL
BEGIN
   DROP TABLE #A
END
CREATE TABLE #A ([LINK_RULE]       INT NULL,
                 [LINK_TASK]       INT NULL,
                 [IsOutside]       TINYINT NULL,
                 [LINK_FORM]       INT NULL,
                 [OrderRule]       INT NULL,
                 [PERIOD]          SMALLINT NULL,
                 [PERIOD_NOM]      SMALLINT NULL,
                 [ORG_LEVEL]       SMALLINT NULL,
                 [IsSvod]          SMALLINT NULL,
                 [STR_RULE]        VARCHAR (6000) NULL,
                 [IsDoschet]       TINYINT NULL,
                 [CALC_ORDERS]     INT NULL,
                 [IsSystemsRule]   TINYINT NULL ,
                 [MODIFY_DATE]     DATETIME NULL,
                 [ROWS]            VARCHAR(1000),
                 [COLS]            VARCHAR(250),
                 [ROWS_DESC]       VARCHAR (250),
                 [CODE_FORM]       VARCHAR (250),
                 [START_DATE_FORM] VARCHAR (250),
                 [REGION]				VARCHAR (100),
                 [SIGN_SR]         CHAR(2)      NOT NULL,
                 [ALGORITHM]       TINYINT      NOT NULL,
                 [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                 [COMMENT]         VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #A',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #A'
INSERT #A VALUES(1,NULL,0,NULL,1,7,0,0,0,'т.2гр.24 =  т.2гр.15 -  т.2гр.19',1,0,1,'20141220','','','','ND_TN','20140101','','=',3,'','')
INSERT #A VALUES(2,NULL,0,NULL,2,7,0,0,0,'т.1стр.Блокгр.3 =  т.2гр.24',1,1,1,'20141220','','','','ND_TN','20140101','','=',0,'','')
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO
IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #A) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #A',0)
END

IF OBJECT_ID('tempdb..#B') IS NOT NULL
BEGIN
   DROP TABLE #B
END

CREATE TABLE #B ([LINK_RULE]       INT NULL,
                 [OrderRow]        INT NULL,
                 [VAL_TYPE]        TINYINT NULL,
                 [SIGN]            CHAR(2) NULL,
                 [LINK_FORM]       INT NULL,
                 [LINK_TABLE]      INT NULL,
                 [LINK_COL]        INT NULL,
                 [LINK_ROW]        INT NULL,
                 [PERIOD_FORM]     SMALLINT NULL,
                 [FACTOR]          FLOAT NULL,
                 [EXEC_PROC]       VARCHAR(250) NULL,
                 [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                 [CODE_ROW]        VARCHAR(250) NULL,
                 [FILTER]          VARCHAR(1000) NULL,
                 [FILTER_DESC]     VARCHAR(250) NULL,
                 [MASKA]           VARCHAR(250) NULL,
                 [MASKA_DESC]      VARCHAR(250) NULL,
                 [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                 [COL]             VARCHAR(100) NULL,
                 [ROW]             VARCHAR(100) NULL,
                 [TABLE]           VARCHAR(25)  NULL,
                 [START_DATE_FORM] DATETIME     NULL,
                 [PERIOD_YEAR]     SMALLINT     NULL,
                 [ATR_CODE]        VARCHAR(254) NOT NULL,
                 [PART]            TINYINT      NOT NULL,
                 [BEGIN_DATE]      DATETIME     NULL,
                 [PX]              FLOAT(53)    NOT NULL,
                 [PX_COMMENT]              VARCHAR(254)    NULL,
                 [Property]				TINYINT    DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #B',@iERROR)
END

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
PRINT 'INSERT #B'
INSERT #B VALUES(1,1,3,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','24','','2',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(1,2,3,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','15','','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(1,3,3,'-',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','19','','2',NULL,NULL,'',1,NULL,1,'',0)
INSERT #B VALUES(2,1,0,'+',NULL,NULL,NULL,NULL,0,0,'','','','','','','','','3','Блок','1',NULL,NULL,'',0,NULL,1,'',0)
INSERT #B VALUES(2,2,4,'+',NULL,NULL,NULL,NULL,0,0,'','','','Code <> ''итого''','','','','','24','','2',NULL,NULL,'',1,NULL,1,'',0)
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #B) <> 5
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #B',0)
END

CREATE INDEX #IX_tabROWS ON #B([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #A([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#A', '#B', 1
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
END -- IF NOT EXISTS(SELECT * FROM #tabStop)
GO

GO

IF NOT EXISTS(SELECT * FROM #tabStop) BEGIN
DECLARE @iERROR INT, @iLINK_FORM INT, @iTABLE_LINK INT, @tTABLE_ORDER TINYINT, @iGF_LINK INT

SELECT @iLINK_FORM = [LINK_FORM]
FROM #tabInfo


-- Обновление связей с группами форм.

DELETE dbo.[REPORT_FORM_GROUPS_REF]
WHERE [LINK_FORM] = @iLINK_FORM

-- Переформирование процедур RI_PROC_T.
DECLARE curTable CURSOR FOR
SELECT [LINK_TABLE],
       [ORDERS]
FROM [REPORT_TABLES]
WHERE [LINK_FORM] = @iLINK_FORM

OPEN curTable

FETCH NEXT
FROM curTable
INTO @iTABLE_LINK,
     @tTABLE_ORDER

WHILE @@FETCH_STATUS = 0
BEGIN
   EXEC @iERROR = dbo.[I_REPORT_CREATE_PROC] @iTABLE_LINK
   IF @iERROR <> 0
   BEGIN
      INSERT #tabErrorLog VALUES ('I_REPORT_CREATE_PROC',@iERROR)
   END
   FETCH NEXT
   FROM curTable
   INTO @iTABLE_LINK,
        @tTABLE_ORDER
END
CLOSE curTable
DEALLOCATE curTable

EXEC dbo.[I_CONTROL_RULES_ACTION] 3, @iLINK_FORM


UPDATE dbo.[REPORT_FORMS] SET [UPDATE_DATE] = CONVERT(DATETIME,'2014-12-24 08:18:34.350',121) WHERE [LINK_FORM]=@iLINK_FORM

END -- IF NOT EXISTS(SELECT * FROM #tabStop)
ELSE BEGIN
	DECLARE @vcMessage VARCHAR(8000)
	SELECT @vcMessage = [CURRENT_DATE] FROM #tabStop
	IF @vcMessage = '2014-12-24 08:18:34.350'
	BEGIN
		SELECT @vcMessage = 'Форма ND_TN с версией от ' + @vcMessage + ' уже существует. Обновление отклонено.'
	END
	ELSE BEGIN
		SELECT @vcMessage = 'Форма ND_TN с версией от ' + @vcMessage + ' не может быть обновлена версией от 2014-12-24 08:18:34.350. Обновление отклонено.'
	END

	 IF OBJECT_ID('tempdb..#tabUpdateMessages') IS NOT NULL
	 BEGIN
		 INSERT #tabUpdateMessages([TXT]) VALUES (@vcMessage)
	 END
	 SELECT @vcMessage
END
GO

IF OBJECT_ID('tempdb..#tabInfo') IS NOT NULL DROP TABLE #tabInfo
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog
DROP TABLE #tabStop

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 16 2015  4:23:32:933PM)
-- Выгружены следующие группы междокументных КС:
-- 1228 - Заполнение: 0503164G - 0503127G (16 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1228' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1228'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,544572,7,0,0,0,'ф.0503164Gт.3стр.52001000000000000000гр.3 =  ф.0503127Gт.3стр.52001000000000000000гр.4',1,4,0,'20121226','','','','',NULL,'ks                                                                                                  ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,544573,7,0,0,0,'ф.0503164Gт.3стр.52001000000000000000гр.4 =  ф.0503127Gт.3стр.52001000000000000000гр.8',1,4,0,'20121226','','','','',NULL,'ks                                                                                                  ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,544574,7,0,0,0,'ф.0503164Gт.3стр.62002000000000000000гр.4 =  ф.0503127Gт.3стр.62002000000000000000гр.8',1,4,0,'20121226','','','','',NULL,'ks                                                                                                  ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,544575,7,0,0,0,'ф.0503164Gт.3стр.62002000000000000000гр.3 =  ф.0503127Gт.3стр.62002000000000000000гр.4',1,4,0,'20121226','','','','',NULL,'ks                                                                                                  ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,544600,7,0,0,0,'ф.0503164Gт.1гр.3 =  ф.0503127Gт.1гр.4',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,544601,7,0,0,0,'ф.0503164Gт.1гр.4 =  ф.0503127Gт.1гр.8',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,544602,7,0,0,0,'ф.0503164Gт.2гр.3 =  ф.0503127Gт.2гр.4',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,544603,7,0,0,0,'ф.0503164Gт.2гр.4 =  ф.0503127Gт.2гр.9',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,544604,7,0,0,0,'ф.0503164Gт.3гр.3 =  ф.0503127Gт.3гр.4',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,544605,7,0,0,0,'ф.0503164Gт.3гр.4 =  ф.0503127Gт.3гр.8',1,2,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,544606,7,0,0,0,'ф.0503164Gт.2гр.3 =  ф.0503164Gт.2гр.3',1,3,1,'20140116','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,544607,7,0,0,0,'ф.0503164Gт.2гр.4 =  ф.0503164Gт.2гр.4',1,3,1,'20140116','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,544608,7,0,0,0,'ф.0503164Gт.1гр.3 =  ф.0503164Gт.1гр.3',1,3,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,544609,7,0,0,0,'ф.0503164Gт.1гр.4 =  ф.0503164Gт.1гр.4',1,3,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,544610,7,0,0,0,'ф.0503164Gт.3гр.3 =  ф.0503164Gт.3гр.3',1,3,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,544611,7,0,0,0,'ф.0503164Gт.3гр.4 =  ф.0503164Gт.3гр.4',1,3,1,'20121226','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 16
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','((substring(code,11,4)<>''0000''  or (substring(code,11,4)=''0000'' and not exists(select top 1 * from #report_dinamics RD1 where RD1.Link_SF = A.LSF and LEFT(RD1.Code_Row,10) = LEFT(CODE,10) and RD1.Link_Table = RD.Link_Table and substring(RD1.Code_Row,11,4) <> ''0000'') and code not in (select CD from dbo.RO_SELECT_FORM_TOTALS_DOH_17(0,$ОТЧЕТ$,1) where link_table=$ТАБЛИЦА$)))  and isnull(COL(4),0)<>0) OR SUBSTRING(CODE,1,8)=''85000000''','','LEFT(CODE,10)+''0000000''','',8,'     ','4','','1','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','((substring(code,11,4)<>''0000''  or (substring(code,11,4)=''0000'' and not exists(select top 1 * from #report_dinamics RD1 where RD1.Link_SF = A.LSF and LEFT(RD1.Code_Row,10) = LEFT(CODE,10) and RD1.Link_Table = RD.Link_Table and substring(RD1.Code_Row,11,4) <> ''0000'') and code not in (select CD from dbo.RO_SELECT_FORM_TOTALS_DOH_17(0,$ОТЧЕТ$,1) where link_table=$ТАБЛИЦА$)))  and isnull(COL(4),0)<>0) OR SUBSTRING(CODE,1,8)=''85000000''','','LEFT(CODE,10)+''0000000''','',8,'     ','8','','1','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','(right(rtrim(code),3) not in (''200'',''000'',''210'',''220'',''230'',''240'',''250'',''260'',''300'',''500'',''600'' )and isnull(COL(4),0)<>0) OR (SUBSTRING(CODE,1,11) in (''96000000000'', ''79000000000''))','','LEFT(CODE,11)+''000000''','',8,'     ','7','','2','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','(right(rtrim(code),3) not in (''200'',''000'',''210'',''220'',''230'',''240'',''250'',''260'',''300'',''500'',''600'' )and isnull(COL(4),0)<>0) OR (SUBSTRING(CODE,1,11) in (''96000000000'', ''79000000000''))','','LEFT(CODE,11)+''000000''','',8,'     ','12','','2','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,3,'+ ',0,0,'','','52001000000000000000','','','','',8,'     ','4','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,3,'+ ',0,0,'','','52001000000000000000','','','','',8,'     ','8','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,3,'+ ',0,0,'','','62002000000000000000','','','','',8,'     ','8','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,3,'+ ',0,0,'','','62002000000000000000','','','','',8,'     ','4','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','(code not in (select CD from dbo.RO_SELECT_FORM_TOTALS_IST_20(0,$ОТЧЕТ$,1) where link_table=$ТАБЛИЦА$) and isnull(COL(4),0)<>0  and COL(2) not in (''700'',''720'',''710''))  or code=''50090000000000000000''','','CODE','',8,'     ','8','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','(code not in (select CD from dbo.RO_SELECT_FORM_TOTALS_IST_20(0,$ОТЧЕТ$,1) where link_table=$ТАБЛИЦА$) and isnull(COL(4),0)<>0  and COL(2) not in (''700'',''720'',''710''))  or code=''50090000000000000000''','','CODE','',8,'     ','4','','3','0503127G            ','20111231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and substring(code,1,3)<>''850''','','CODE','',8,'     ','3','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and substring(code,1,3)<>''850''','','CODE','',8,'     ','3','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and substring(code,1,3)<>''850''','','CODE','',8,'     ','4','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and substring(code,1,3)<>''850''','','CODE','',8,'     ','4','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,4,'+ ',0,0,'','','','','','LEFT(CODE,10)+''0000000''','',8,'     ','3','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,4,'+ ',0,0,'','','','','','LEFT(CODE,10)+''0000000''','',8,'     ','4','','1','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,4,'+ ',0,0,'','','','','','LEFT(CODE,11)+''000000''','',8,'     ','4','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,4,'+ ',0,0,'','','','','','LEFT(CODE,11)+''000000''','',8,'     ','5','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,4,'+ ',0,0,'','','','substring(code,1,4) not in (''9600'',''7900'') and abs(isnull(COL(5),0)-isnull(COL(4),0)) = 0','','CODE','',8,'     ','4','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','substring(code,1,4) not in (''9600'',''7900'') and abs(isnull(COL(5),0)-isnull(COL(4),0)) = 0','','CODE','',8,'     ','4','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,4,'+ ',0,0,'','','','substring(code,1,4) not in (''9600'',''7900'') and abs(isnull(COL(5),0)-isnull(COL(4),0)) = 0','','CODE','',8,'     ','5','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','substring(code,1,4) not in (''9600'',''7900'') and abs(isnull(COL(5),0)-isnull(COL(4),0)) =0','','CODE','',8,'     ','5','','2','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,4,'+ ',0,0,'','','','','','CODE','',8,'     ','4','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,3,'+ ',0,0,'','','52001000000000000000','','','','',8,'     ','3','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and code not in (''50090000000000000000'')','','CODE','',8,'     ','3','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and code not in (''50090000000000000000'')','','CODE','',8,'     ','3','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and code not in (''50090000000000000000'')','','CODE','',8,'     ','4','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','','(isnull(COL(3),0) = isnull(COL(4),0))and code not in (''50090000000000000000'')','','CODE','',8,'     ','4','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,4,'+ ',0,0,'','','','','','CODE','',8,'     ','3','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,3,'+ ',0,0,'','','62002000000000000000','','','','',8,'     ','3','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,3,'+ ',0,0,'','','62002000000000000000','','','','',8,'     ','4','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,3,'+ ',0,0,'','','52001000000000000000','','','','',8,'     ','4','','3','0503164G            ','20121231',NULL,'REPORTS_ATR_ADM',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1228')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1228')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 16
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1228'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1228' , 'Заполнение: 0503164G - 0503127G', 2, 0, '20121231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:34:18:440AM)
-- Выгружены следующие группы междокументных КС:
-- 1237_1 - Проверка 0503730G - 0503771G (6 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1237_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1237_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567689,7,0,0,0,'ф.0503730G_BUт.1стр.211гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 220420000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567690,7,0,0,0,'ф.0503730G_BUт.1стр.212гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 220430000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567691,7,0,0,0,'ф.0503730G_BUт.1стр.213гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 220450000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567692,7,0,0,0,'ф.0503730G_BUт.1стр.371гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 221520000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567693,7,0,0,0,'ф.0503730G_BUт.1стр.372гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 221530000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567694,7,0,0,0,'ф.0503730G_BUт.1стр.373гр.8 =  ф.0503771Gт.1гр.2Фильтр:Счет 221550000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','RTRIM(CODE)  like ''22042[1,2,3]000''','Счет 220420000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','RTRIM(CODE)  like ''22043[1,2,3,4]000''','Счет 220430000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','RTRIM(CODE)  like ''22045[1,2,3]000''','Счет 220450000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','RTRIM(CODE)  like ''22152[1,2,3]000''','Счет 221520000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','RTRIM(CODE)  like ''22153[1,2,3]000''','Счет 221530000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','RTRIM(CODE) like ''22155[1,2,3]000''','Счет 221550000','','',8,'     ','2','','1','0503771G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 12
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1237_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1237_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1237_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1237_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1237_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1237_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1237_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1237_1' , 'Проверка 0503730G - 0503771G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:34:30:923AM)
-- Выгружены следующие группы междокументных КС:
-- 1272_1 - Проверка 0503769G - 0503730G (71 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1272_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1272_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567696,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567697,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567698,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567699,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567700,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567701,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567702,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567703,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567704,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567705,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567706,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567707,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567708,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.9 =  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567709,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.9 =  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567710,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567711,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567712,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567713,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567714,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567715,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567716,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567717,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567718,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567719,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567720,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567721,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567722,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567723,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567724,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567725,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567726,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567727,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567728,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567729,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567730,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567731,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.5 =  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567732,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.5 =  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567733,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567734,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567735,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567736,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567737,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567738,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567739,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567740,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567741,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567742,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567743,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567744,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567745,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567746,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030301000 +  ф.0503769G_Kт.1гр.4Фильтр:030301000 +  ф.0503769G_Kт.1гр.4Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567747,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567748,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567749,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567750,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567751,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567752,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567753,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567754,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567755,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,567756,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,567757,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,567758,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,567759,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (65,1,567760,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (66,1,567761,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (67,1,567762,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (68,1,567763,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (69,1,567764,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (70,1,567765,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (71,1,567766,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 71
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 301
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (65,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (66,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (67,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (68,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (69,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (70,'1272_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (71,'1272_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 71
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1272_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1272_1' , 'Проверка 0503769G - 0503730G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:34:39:497AM)
-- Выгружены следующие группы междокументных КС:
-- 1276_1 - Проверка:0503730G, 0503721G,0503725G (36 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1276_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1276_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567768,7,0,0,0,'ф.0503721Gт.1стр.540гр.4 =  ф.0503730G_BUт.1стр.490гр.7 -  ф.0503730G_BUт.1стр.490гр.3 +  ф.0503730G_BUт.1стр.510гр.7 -  ф.0503730G_BUт.1стр.510гр.3 +  ф.0503730G_BUт.1стр.530гр.7 -  ф.0503730G_BUт.1стр.530гр.3 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567769,7,0,0,0,'ф.0503721Gт.1стр.310гр.4 =  ф.0503730G_BUт.1стр.150гр.7 -  ф.0503730G_BUт.1стр.150гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567770,7,0,0,0,'ф.0503721Gт.1стр.470гр.4 =  ф.0503730G_BUт.1стр.213гр.7 -  ф.0503730G_BUт.1стр.213гр.3 +  ф.0503730G_BUт.1стр.373гр.7 -  ф.0503730G_BUт.1стр.373гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567771,7,0,0,0,'ф.0503721Gт.1стр.420гр.4 =  ф.0503730G_BUт.1стр.211гр.7 -  ф.0503730G_BUт.1стр.211гр.3 +  ф.0503730G_BUт.1стр.371гр.7 -  ф.0503730G_BUт.1стр.371гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567772,7,0,0,0,'ф.0503721Gт.1стр.460гр.4 =  ф.0503730G_BUт.1стр.290гр.7 -  ф.0503730G_BUт.1стр.290гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567773,7,0,0,0,'ф.0503721Gт.1стр.520гр.4 +  ф.0503721Gт.1стр.530гр.4 =  ф.0503730G_BUт.1стр.470гр.7 -  ф.0503730G_BUт.1стр.470гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567774,7,0,0,0,'ф.0503721Gт.1стр.540гр.5 =  ф.0503730G_BUт.1стр.490гр.8 -  ф.0503730G_BUт.1стр.490гр.4 +  ф.0503730G_BUт.1стр.510гр.8 -  ф.0503730G_BUт.1стр.510гр.4 +  ф.0503730G_BUт.1стр.530гр.8 -  ф.0503730G_BUт.1стр.530гр.4 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567775,7,0,0,0,'ф.0503721Gт.1стр.540гр.6 =  ф.0503730G_BUт.1стр.490гр.9 -  ф.0503730G_BUт.1стр.490гр.5 +  ф.0503730G_BUт.1стр.510гр.9 -  ф.0503730G_BUт.1стр.510гр.5 +  ф.0503730G_BUт.1стр.530гр.9 -  ф.0503730G_BUт.1стр.530гр.5 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567776,7,0,0,0,'ф.0503721Gт.1стр.520гр.5 +  ф.0503721Gт.1стр.530гр.5 =  ф.0503730G_BUт.1стр.470гр.8 -  ф.0503730G_BUт.1стр.470гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567777,7,0,0,0,'ф.0503721Gт.1стр.520гр.6 +  ф.0503721Gт.1стр.530гр.6 =  ф.0503730G_BUт.1стр.470гр.9 -  ф.0503730G_BUт.1стр.470гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567778,7,0,0,0,'ф.0503721Gт.1стр.470гр.5 =  ф.0503730G_BUт.1стр.213гр.8 -  ф.0503730G_BUт.1стр.213гр.4 +  ф.0503730G_BUт.1стр.373гр.8 -  ф.0503730G_BUт.1стр.373гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567779,7,0,0,0,'ф.0503721Gт.1стр.470гр.6 =  ф.0503730G_BUт.1стр.213гр.9 -  ф.0503730G_BUт.1стр.213гр.5 +  ф.0503730G_BUт.1стр.373гр.9 -  ф.0503730G_BUт.1стр.373гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567780,7,0,0,0,'ф.0503721Gт.1стр.460гр.5 =  ф.0503730G_BUт.1стр.290гр.8 -  ф.0503730G_BUт.1стр.290гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567781,7,0,0,0,'ф.0503721Gт.1стр.460гр.6 =  ф.0503730G_BUт.1стр.290гр.9 -  ф.0503730G_BUт.1стр.290гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567782,7,0,0,0,'ф.0503721Gт.1стр.420гр.5 =  ф.0503730G_BUт.1стр.211гр.8 -  ф.0503730G_BUт.1стр.211гр.4 +  ф.0503730G_BUт.1стр.371гр.8 -  ф.0503730G_BUт.1стр.371гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567783,7,0,0,0,'ф.0503721Gт.1стр.420гр.6 =  ф.0503730G_BUт.1стр.211гр.9 -  ф.0503730G_BUт.1стр.211гр.5 +  ф.0503730G_BUт.1стр.371гр.9 -  ф.0503730G_BUт.1стр.371гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567784,7,0,0,0,'ф.0503721Gт.1стр.310гр.5 =  ф.0503730G_BUт.1стр.150гр.8 -  ф.0503730G_BUт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567785,7,0,0,0,'ф.0503721Gт.1стр.310гр.6 =  ф.0503730G_BUт.1стр.150гр.9 -  ф.0503730G_BUт.1стр.150гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567786,7,0,0,0,'ф.0503721Gт.1стр.300гр.4 =  ф.0503730G_BUт.1стр.620гр.7 -  ф.0503730G_BUт.1стр.620гр.3 -  ф.0503730G_BUт.1стр.6231гр.7 +  ф.0503730G_BUт.1стр.6231гр.3 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567787,7,0,0,0,'ф.0503721Gт.1стр.300гр.5 =  ф.0503730G_BUт.1стр.620гр.8 -  ф.0503730G_BUт.1стр.620гр.4 -  ф.0503730G_BUт.1стр.6231гр.8 +  ф.0503730G_BUт.1стр.6231гр.4 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567788,7,0,0,0,'ф.0503721Gт.1стр.300гр.6 =  ф.0503730G_BUт.1стр.620гр.9 -  ф.0503730G_BUт.1стр.620гр.5 -  ф.0503730G_BUт.1стр.6231гр.9 +  ф.0503730G_BUт.1стр.6231гр.5 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567789,7,0,0,0,'ф.0503721Gт.1стр.390гр.4 =  ф.0503730G_BUт.1стр.400гр.7 -  ф.0503730G_BUт.1стр.400гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567790,7,0,0,0,'ф.0503721Gт.1стр.390гр.5 =  ф.0503730G_BUт.1стр.400гр.8 -  ф.0503730G_BUт.1стр.400гр.4 -  ф.0503730G_BUт.1стр.337гр.8 +  ф.0503730G_BUт.1стр.337гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567791,7,0,0,0,'ф.0503721Gт.1стр.390гр.6 =  ф.0503730G_BUт.1стр.400гр.9 -  ф.0503730G_BUт.1стр.400гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567792,7,0,0,0,'ф.0503721Gт.1стр.440гр.4 =  ф.0503730G_BUт.1стр.212гр.7 -  ф.0503730G_BUт.1стр.212гр.3 +  ф.0503730G_BUт.1стр.372гр.7 -  ф.0503730G_BUт.1стр.372гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567793,7,0,0,0,'ф.0503721Gт.1стр.440гр.5 =  ф.0503730G_BUт.1стр.212гр.8 -  ф.0503730G_BUт.1стр.212гр.4 +  ф.0503730G_BUт.1стр.372гр.8 -  ф.0503730G_BUт.1стр.372гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567794,7,0,0,0,'ф.0503721Gт.1стр.440гр.6 =  ф.0503730G_BUт.1стр.212гр.9 -  ф.0503730G_BUт.1стр.212гр.5 +  ф.0503730G_BUт.1стр.372гр.9 -  ф.0503730G_BUт.1стр.372гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567795,7,0,0,0,'ф.0503721Gт.1стр.480гр.4 =  ф.0503730G_BUт.1стр.230гр.7 -  ф.0503730G_BUт.1стр.230гр.3 +  ф.0503730G_BUт.1стр.260гр.7 -  ф.0503730G_BUт.1стр.260гр.3 +  ф.0503730G_BUт.1стр.310гр.7 -  ф.0503730G_BUт.1стр.310гр.3 +  ф.0503730G_BUт.1стр.320гр.7 -  ф.0503730G_BUт.1стр.320гр.3 +  ф.0503730G_BUт.1стр.330гр.7 -  ф.0503730G_BUт.1стр.330гр.3 -  ф.0503730G_BUт.1стр.337гр.7 +  ф.0503730G_BUт.1стр.337гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567796,7,0,0,0,'ф.0503721Gт.1стр.480гр.5 =  ф.0503730G_BUт.1стр.230гр.8 -  ф.0503730G_BUт.1стр.230гр.4 +  ф.0503730G_BUт.1стр.260гр.8 -  ф.0503730G_BUт.1стр.260гр.4 +  ф.0503730G_BUт.1стр.310гр.8 -  ф.0503730G_BUт.1стр.310гр.4 +  ф.0503730G_BUт.1стр.320гр.8 -  ф.0503730G_BUт.1стр.320гр.4 +  ф.0503730G_BUт.1стр.330гр.8 -  ф.0503730G_BUт.1стр.330гр.4 -  ф.0503730G_BUт.1стр.337гр.8 +  ф.0503730G_BUт.1стр.337гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567797,7,0,0,0,'ф.0503721Gт.1стр.480гр.6 =  ф.0503730G_BUт.1стр.230гр.9 -  ф.0503730G_BUт.1стр.230гр.5 +  ф.0503730G_BUт.1стр.260гр.9 -  ф.0503730G_BUт.1стр.260гр.5 +  ф.0503730G_BUт.1стр.310гр.9 -  ф.0503730G_BUт.1стр.310гр.5 +  ф.0503730G_BUт.1стр.320гр.9 -  ф.0503730G_BUт.1стр.320гр.5 +  ф.0503730G_BUт.1стр.330гр.9 -  ф.0503730G_BUт.1стр.330гр.5 -  ф.0503730G_BUт.1стр.337гр.9 +  ф.0503730G_BUт.1стр.337гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567798,7,0,0,0,'ф.0503721Gт.1стр.510гр.4 =  ф.0503730G_BUт.1стр.600гр.7 -  ф.0503730G_BUт.1стр.600гр.3 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567799,7,0,0,0,'ф.0503721Gт.1стр.510гр.5 =  ф.0503730G_BUт.1стр.600гр.8 -  ф.0503730G_BUт.1стр.600гр.4 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567800,7,0,0,0,'ф.0503721Gт.1стр.510гр.6 =  ф.0503730G_BUт.1стр.600гр.9 -  ф.0503730G_BUт.1стр.600гр.5 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567801,7,0,0,0,'ф.0503721Gт.1стр.370гр.4 =  ф.0503730G_BUт.1стр.140гр.7 -  ф.0503730G_BUт.1стр.140гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567802,7,0,0,0,'ф.0503721Gт.1стр.370гр.5 =  ф.0503730G_BUт.1стр.140гр.8 -  ф.0503730G_BUт.1стр.140гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567803,7,0,0,0,'ф.0503721Gт.1стр.370гр.6 =  ф.0503730G_BUт.1стр.140гр.9 -  ф.0503730G_BUт.1стр.140гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 36
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'- ',0,0,'','','','','','','',8,'     ','3','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'- ',0,0,'','','','','','','',8,'     ','3','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'- ',0,0,'','','','','','','',8,'     ','4','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'- ',0,0,'','','','','','','',8,'     ','4','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'- ',0,0,'','','','','','','',8,'     ','4','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'- ',0,0,'','','','','','','',8,'     ','5','490','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,0,'- ',0,0,'','','','','','','',8,'     ','5','510','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,6,0,'+ ',0,0,'','','','','','','',8,'     ','9','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,7,0,'- ',0,0,'','','','','','','',8,'     ','5','530','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,0,'- ',0,0,'','','','','','','',8,'     ','4','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,0,'- ',0,0,'','','','','','','',8,'     ','4','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,0,'- ',0,0,'','','','','','','',8,'     ','4','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,0,'+ ',0,0,'','','','','','','',8,'     ','9','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,0,'- ',0,0,'','','','','','','',8,'     ','5','470','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'- ',0,0,'','','','','','','',8,'     ','4','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'- ',0,0,'','','','','','','',8,'     ','4','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,0,'- ',0,0,'','','','','','','',8,'     ','4','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'- ',0,0,'','','','','','','',8,'     ','5','290','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'- ',0,0,'','','','','','','',8,'     ','4','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,0,'- ',0,0,'','','','','','','',8,'     ','3','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,0,'- ',0,0,'','','','','','','',8,'     ','7','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,0,'- ',0,0,'','','','','','','',8,'     ','4','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,0,'- ',0,0,'','','','','','','',8,'     ','8','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,0,'- ',0,0,'','','','','','','',8,'     ','5','620','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,4,0,'- ',0,0,'','','','','','','',8,'     ','9','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','6231','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'- ',0,0,'','','','','','','',8,'     ','5','150','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,0,'- ',0,0,'','','','','','','',8,'     ','8','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,5,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,0,'- ',0,0,'','','','','','','',8,'     ','4','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,5,0,'- ',0,0,'','','','','','','',8,'     ','4','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,11,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,12,0,'- ',0,0,'','','','','','','',8,'     ','7','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,13,0,'+ ',0,0,'','','','','','','',8,'     ','3','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,0,'- ',0,0,'','','','','','','',8,'     ','4','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,0,'- ',0,0,'','','','','','','',8,'     ','4','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,7,0,'- ',0,0,'','','','','','','',8,'     ','4','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,9,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,11,0,'- ',0,0,'','','','','','','',8,'     ','4','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,12,0,'- ',0,0,'','','','','','','',8,'     ','8','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,13,0,'+ ',0,0,'','','','','','','',8,'     ','4','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,6,0,'+ ',0,0,'','','','','','','',8,'     ','9','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,7,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,8,0,'+ ',0,0,'','','','','','','',8,'     ','9','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,9,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,10,0,'+ ',0,0,'','','','','','','',8,'     ','9','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,11,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,12,0,'- ',0,0,'','','','','','','',8,'     ','9','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,13,0,'+ ',0,0,'','','','','','','',8,'     ','5','337','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,5,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,0,'- ',0,0,'','','','','','','',8,'     ','5','400','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'- ',0,0,'','','','','','','',8,'     ','3','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'- ',0,0,'','','','','','','',8,'     ','4','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'- ',0,0,'','','','','','','',8,'     ','5','600','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'- ',0,0,'','','','','','','',8,'     ','3','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'- ',0,0,'','','','','','','',8,'     ','4','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'- ',0,0,'','','','','','','',8,'     ','5','140','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 179
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1276_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1276_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 36
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1276_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1276_1' , 'Проверка:0503730G, 0503721G,0503725G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:34:47:017AM)
-- Выгружены следующие группы междокументных КС:
-- 1277_1 - Проверка: 0503730G_BU - 0503776G (9 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1277_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1277_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567805,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.3 =  ф.0503776Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567806,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.4 =  ф.0503776Gт.1стр.010гр.5',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567807,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.6 =  ф.0503776Gт.1стр.010гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567808,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.7 -  ф.0503730G_BUт.1стр.320гр.3 =  ф.0503776Gт.1стр.020гр.4 -  ф.0503776Gт.1стр.040гр.4 -  ф.0503776Gт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567809,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.10 -  ф.0503730G_BUт.1стр.320гр.6 =  ф.0503776Gт.1стр.020гр.3 -  ф.0503776Gт.1стр.040гр.3 -  ф.0503776Gт.1стр.050гр.3',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567810,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.8 -  ф.0503730G_BUт.1стр.320гр.4 =  ф.0503776Gт.1стр.020гр.5 -  ф.0503776Gт.1стр.040гр.5 -  ф.0503776Gт.1стр.050гр.5',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567811,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.7 =  ф.0503776Gт.1стр.060гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567812,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.8 =  ф.0503776Gт.1стр.060гр.5',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567813,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.10 =  ф.0503776Gт.1стр.060гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 9
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'- ',0,0,'','','','','','','',8,'     ','4','040','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'- ',0,0,'','','','','','','',8,'     ','4','050','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','020','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,0,'- ',0,0,'','','','','','','',8,'     ','3','040','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,0,'- ',0,0,'','','','','','','',8,'     ','3','050','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','020','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'- ',0,0,'','','','','','','',8,'     ','5','040','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,0,'- ',0,0,'','','','','','','',8,'     ','5','050','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','3','010','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','060','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','060','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','3','060','1','0503776G            ','20121231',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','10','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','10','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'- ',0,0,'','','','','','','',8,'     ','6','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 27
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1277_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1277_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 9
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1277_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1277_1' , 'Проверка: 0503730G_BU - 0503776G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:34:57:110AM)
-- Выгружены следующие группы междокументных КС:
-- 1281_1 - Проверка: 0503768G - 0503730G_BU (97 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1281_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1281_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567815,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.4 =  ф.0503768Gт.1стр.010гр.4 +  ф.0503768Gт.1стр.010гр.4 +  ф.0503768Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567816,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.4 =  ф.0503768Gт.1стр.050гр.4 +  ф.0503768Gт.1стр.050гр.4 +  ф.0503768Gт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567817,7,0,0,0,'ф.0503730G_BUт.1стр.040гр.4 =  ф.0503768Gт.1стр.110гр.4 +  ф.0503768Gт.1стр.110гр.4 +  ф.0503768Gт.1стр.110гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567818,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.4 =  ф.0503768Gт.1стр.120гр.4 +  ф.0503768Gт.1стр.120гр.4 +  ф.0503768Gт.1стр.120гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567819,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.4 =  ф.0503768Gт.1стр.150гр.4 +  ф.0503768Gт.1стр.150гр.4 +  ф.0503768Gт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567820,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.4 =  ф.0503768Gт.1стр.190гр.4 +  ф.0503768Gт.1стр.190гр.4 +  ф.0503768Gт.1стр.190гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567821,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.3 =  ф.0503768Gт.1стр.010гр.4 +  ф.0503768Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567822,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.3 =  ф.0503768Gт.1стр.050гр.4 +  ф.0503768Gт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567823,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.3 =  ф.0503768Gт.1стр.120гр.4 +  ф.0503768Gт.1стр.120гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567824,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.3 =  ф.0503768Gт.1стр.150гр.4 +  ф.0503768Gт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567825,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.3 =  ф.0503768Gт.1стр.190гр.4 +  ф.0503768Gт.1стр.190гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567826,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.5 =  ф.0503768Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567827,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.5 =  ф.0503768Gт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567828,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.5 =  ф.0503768Gт.1стр.120гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567829,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.5 =  ф.0503768Gт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567830,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.5 =  ф.0503768Gт.1стр.190гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567831,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.7 =  ф.0503768Gт.1стр.010гр.7 +  ф.0503768Gт.1стр.010гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567832,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.7 =  ф.0503768Gт.1стр.050гр.7 +  ф.0503768Gт.1стр.050гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567833,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.7 =  ф.0503768Gт.1стр.120гр.7 +  ф.0503768Gт.1стр.120гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567834,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.7 =  ф.0503768Gт.1стр.150гр.7 +  ф.0503768Gт.1стр.150гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567835,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.7 =  ф.0503768Gт.1стр.190гр.7 +  ф.0503768Gт.1стр.190гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567836,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.8 =  ф.0503768Gт.1стр.010гр.7 +  ф.0503768Gт.1стр.010гр.7 +  ф.0503768Gт.1стр.010гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567837,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.8 =  ф.0503768Gт.1стр.050гр.7 +  ф.0503768Gт.1стр.050гр.7 +  ф.0503768Gт.1стр.050гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567838,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.8 =  ф.0503768Gт.1стр.120гр.7 +  ф.0503768Gт.1стр.120гр.7 +  ф.0503768Gт.1стр.120гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567839,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.8 =  ф.0503768Gт.1стр.150гр.7 +  ф.0503768Gт.1стр.150гр.7 +  ф.0503768Gт.1стр.150гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567840,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.8 =  ф.0503768Gт.1стр.190гр.7 +  ф.0503768Gт.1стр.190гр.7 +  ф.0503768Gт.1стр.190гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567841,7,0,0,0,'ф.0503730G_BUт.1стр.010гр.9 =  ф.0503768Gт.1стр.010гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567842,7,0,0,0,'ф.0503730G_BUт.1стр.020гр.9 =  ф.0503768Gт.1стр.050гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567843,7,0,0,0,'ф.0503730G_BUт.1стр.050гр.9 =  ф.0503768Gт.1стр.120гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567844,7,0,0,0,'ф.0503730G_BUт.1стр.070гр.9 =  ф.0503768Gт.1стр.150гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567845,7,0,0,0,'ф.0503730G_BUт.1стр.080гр.9 =  ф.0503768Gт.1стр.190гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567846,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.7 =  ф.0503768Gт.1стр.311гр.7 +  ф.0503768Gт.1стр.311гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567847,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.7 =  ф.0503768Gт.1стр.312гр.7 +  ф.0503768Gт.1стр.312гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567848,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.7 =  ф.0503768Gт.1стр.321гр.7 +  ф.0503768Gт.1стр.321гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567849,7,0,0,0,'ф.0503730G_BUт.1стр.022гр.7 =  ф.0503768Gт.1стр.322гр.7 +  ф.0503768Gт.1стр.322гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567850,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.7 =  ф.0503768Gт.1стр.362гр.7 +  ф.0503768Gт.1стр.362гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567851,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.7 =  ф.0503768Gт.1стр.412гр.7 +  ф.0503768Gт.1стр.412гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567852,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.3 =  ф.0503768Gт.1стр.311гр.4 +  ф.0503768Gт.1стр.311гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567853,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.3 =  ф.0503768Gт.1стр.312гр.4 +  ф.0503768Gт.1стр.312гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567854,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.3 =  ф.0503768Gт.1стр.321гр.4 +  ф.0503768Gт.1стр.321гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567855,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.3 =  ф.0503768Gт.1стр.362гр.4 +  ф.0503768Gт.1стр.362гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567856,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.3 =  ф.0503768Gт.1стр.412гр.4 +  ф.0503768Gт.1стр.412гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567857,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.8 =  ф.0503768Gт.1стр.311гр.7 +  ф.0503768Gт.1стр.311гр.7 +  ф.0503768Gт.1стр.311гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567858,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.8 =  ф.0503768Gт.1стр.312гр.7 +  ф.0503768Gт.1стр.312гр.7 +  ф.0503768Gт.1стр.312гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567859,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.8 =  ф.0503768Gт.1стр.321гр.7 +  ф.0503768Gт.1стр.321гр.7 +  ф.0503768Gт.1стр.321гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567860,7,0,0,0,'ф.0503730G_BUт.1стр.022гр.8 =  ф.0503768Gт.1стр.322гр.7 +  ф.0503768Gт.1стр.322гр.7 +  ф.0503768Gт.1стр.322гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567861,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.8 =  ф.0503768Gт.1стр.362гр.7 +  ф.0503768Gт.1стр.362гр.7 +  ф.0503768Gт.1стр.362гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567862,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.8 =  ф.0503768Gт.1стр.412гр.7 +  ф.0503768Gт.1стр.412гр.7 +  ф.0503768Gт.1стр.412гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567863,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.4 =  ф.0503768Gт.1стр.311гр.4 +  ф.0503768Gт.1стр.311гр.4 +  ф.0503768Gт.1стр.311гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567864,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.4 =  ф.0503768Gт.1стр.312гр.4 +  ф.0503768Gт.1стр.312гр.4 +  ф.0503768Gт.1стр.312гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567865,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.4 =  ф.0503768Gт.1стр.321гр.4 +  ф.0503768Gт.1стр.321гр.4 +  ф.0503768Gт.1стр.321гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567866,7,0,0,0,'ф.0503730G_BUт.1стр.022гр.4 =  ф.0503768Gт.1стр.322гр.4 +  ф.0503768Gт.1стр.322гр.4 +  ф.0503768Gт.1стр.322гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567867,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.4 =  ф.0503768Gт.1стр.362гр.4 +  ф.0503768Gт.1стр.362гр.4 +  ф.0503768Gт.1стр.362гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567868,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.4 =  ф.0503768Gт.1стр.412гр.4 +  ф.0503768Gт.1стр.412гр.4 +  ф.0503768Gт.1стр.412гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567869,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.9 =  ф.0503768Gт.1стр.311гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567870,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.9 =  ф.0503768Gт.1стр.312гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567871,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.9 =  ф.0503768Gт.1стр.321гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567872,7,0,0,0,'ф.0503730G_BUт.1стр.022гр.9 =  ф.0503768Gт.1стр.322гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567873,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.9 =  ф.0503768Gт.1стр.362гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567874,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.9 =  ф.0503768Gт.1стр.412гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,567875,7,0,0,0,'ф.0503730G_BUт.1стр.011гр.5 =  ф.0503768Gт.1стр.311гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,567876,7,0,0,0,'ф.0503730G_BUт.1стр.012гр.5 =  ф.0503768Gт.1стр.312гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,567877,7,0,0,0,'ф.0503730G_BUт.1стр.021гр.5 =  ф.0503768Gт.1стр.321гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,567878,7,0,0,0,'ф.0503730G_BUт.1стр.022гр.5 =  ф.0503768Gт.1стр.322гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (65,1,567879,7,0,0,0,'ф.0503730G_BUт.1стр.051гр.5 =  ф.0503768Gт.1стр.362гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (66,1,567880,7,0,0,0,'ф.0503730G_BUт.1стр.081гр.5 =  ф.0503768Gт.1стр.412гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (67,1,567881,7,0,0,0,'ф.0503730G_BUт.1стр.040гр.3 =  ф.0503768Gт.1стр.110гр.4 +  ф.0503768Gт.1стр.110гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (68,1,567882,7,0,0,0,'ф.0503730G_BUт.1стр.040гр.7 =  ф.0503768Gт.1стр.110гр.7 +  ф.0503768Gт.1стр.110гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (69,1,567883,7,0,0,0,'ф.0503730G_BUт.1стр.040гр.8 =  ф.0503768Gт.1стр.110гр.7 +  ф.0503768Gт.1стр.110гр.7 +  ф.0503768Gт.1стр.110гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (70,1,567884,7,0,0,0,'ф.0503730G_BUт.1стр.091гр.3 =  ф.0503768Gт.1стр.331гр.4 +  ф.0503768Gт.1стр.331гр.4 +  ф.0503768Gт.1стр.390гр.4 +  ф.0503768Gт.1стр.390гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (71,1,567885,7,0,0,0,'ф.0503730G_BUт.1стр.091гр.4 =  ф.0503768Gт.1стр.331гр.4 +  ф.0503768Gт.1стр.331гр.4 +  ф.0503768Gт.1стр.390гр.4 +  ф.0503768Gт.1стр.390гр.4 +  ф.0503768Gт.1стр.331гр.4 +  ф.0503768Gт.1стр.390гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (72,1,567886,7,0,0,0,'ф.0503730G_BUт.1стр.091гр.7 =  ф.0503768Gт.1стр.331гр.7 +  ф.0503768Gт.1стр.331гр.7 +  ф.0503768Gт.1стр.390гр.7 +  ф.0503768Gт.1стр.390гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (73,1,567887,7,0,0,0,'ф.0503730G_BUт.1стр.091гр.8 =  ф.0503768Gт.1стр.331гр.7 +  ф.0503768Gт.1стр.331гр.7 +  ф.0503768Gт.1стр.390гр.7 +  ф.0503768Gт.1стр.390гр.7 +  ф.0503768Gт.1стр.331гр.7 +  ф.0503768Gт.1стр.390гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (74,1,567888,7,0,0,0,'ф.0503730G_BUт.1стр.092гр.3 =  ф.0503768Gт.1стр.332гр.4 +  ф.0503768Gт.1стр.372гр.4 +  ф.0503768Gт.1стр.422гр.4 +  ф.0503768Gт.1стр.332гр.4 +  ф.0503768Gт.1стр.372гр.4 +  ф.0503768Gт.1стр.422гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (75,1,567889,7,0,0,0,'ф.0503730G_BUт.1стр.092гр.4 =  ф.0503768Gт.1стр.332гр.4 +  ф.0503768Gт.1стр.372гр.4 +  ф.0503768Gт.1стр.422гр.4 +  ф.0503768Gт.1стр.332гр.4 +  ф.0503768Gт.1стр.372гр.4 +  ф.0503768Gт.1стр.422гр.4 +  ф.0503768Gт.1стр.332гр.4 +  ф.0503768Gт.1стр.372гр.4 +  ф.0503768Gт.1стр.422гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (76,1,567890,7,0,0,0,'ф.0503730G_BUт.1стр.092гр.7 =  ф.0503768Gт.1стр.332гр.7 +  ф.0503768Gт.1стр.372гр.7 +  ф.0503768Gт.1стр.422гр.7 +  ф.0503768Gт.1стр.332гр.7 +  ф.0503768Gт.1стр.372гр.7 +  ф.0503768Gт.1стр.422гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (77,1,567891,7,0,0,0,'ф.0503730G_BUт.1стр.092гр.8 =  ф.0503768Gт.1стр.332гр.7 +  ф.0503768Gт.1стр.372гр.7 +  ф.0503768Gт.1стр.422гр.7 +  ф.0503768Gт.1стр.332гр.7 +  ф.0503768Gт.1стр.372гр.7 +  ф.0503768Gт.1стр.422гр.7 +  ф.0503768Gт.1стр.332гр.7 +  ф.0503768Gт.1стр.372гр.7 +  ф.0503768Gт.1стр.422гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (78,1,567892,7,0,0,0,'ф.0503730G_BUт.1стр.101гр.3 =  ф.0503768Gт.1стр.341гр.4 +  ф.0503768Gт.1стр.341гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (79,1,567893,7,0,0,0,'ф.0503730G_BUт.1стр.101гр.4 =  ф.0503768Gт.1стр.341гр.4 +  ф.0503768Gт.1стр.341гр.4 +  ф.0503768Gт.1стр.341гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (80,1,567894,7,0,0,0,'ф.0503730G_BUт.1стр.101гр.7 =  ф.0503768Gт.1стр.341гр.7 +  ф.0503768Gт.1стр.341гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (81,1,567895,7,0,0,0,'ф.0503730G_BUт.1стр.101гр.8 =  ф.0503768Gт.1стр.341гр.7 +  ф.0503768Gт.1стр.341гр.7 +  ф.0503768Gт.1стр.341гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (82,1,567896,7,0,0,0,'ф.0503730G_BUт.1стр.102гр.3 =  ф.0503768Gт.1стр.342гр.4 +  ф.0503768Gт.1стр.432гр.4 +  ф.0503768Gт.1стр.342гр.4 +  ф.0503768Gт.1стр.432гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (83,1,567897,7,0,0,0,'ф.0503730G_BUт.1стр.102гр.4 =  ф.0503768Gт.1стр.342гр.4 +  ф.0503768Gт.1стр.432гр.4 +  ф.0503768Gт.1стр.342гр.4 +  ф.0503768Gт.1стр.432гр.4 +  ф.0503768Gт.1стр.342гр.4 +  ф.0503768Gт.1стр.432гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (84,1,567898,7,0,0,0,'ф.0503730G_BUт.1стр.102гр.7 =  ф.0503768Gт.1стр.342гр.7 +  ф.0503768Gт.1стр.432гр.7 +  ф.0503768Gт.1стр.342гр.7 +  ф.0503768Gт.1стр.432гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (85,1,567899,7,0,0,0,'ф.0503730G_BUт.1стр.102гр.8 =  ф.0503768Gт.1стр.342гр.7 +  ф.0503768Gт.1стр.432гр.7 +  ф.0503768Gт.1стр.342гр.7 +  ф.0503768Gт.1стр.432гр.7 +  ф.0503768Gт.1стр.342гр.7 +  ф.0503768Gт.1стр.432гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (86,1,567900,7,0,0,0,'ф.0503730G_BUт.1стр.041гр.3 =  ф.0503768Gт.1стр.352гр.4 +  ф.0503768Gт.1стр.352гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (87,1,567901,7,0,0,0,'ф.0503730G_BUт.1стр.041гр.4 =  ф.0503768Gт.1стр.352гр.4 +  ф.0503768Gт.1стр.352гр.4 +  ф.0503768Gт.1стр.352гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (88,1,567902,7,0,0,0,'ф.0503730G_BUт.1стр.041гр.7 =  ф.0503768Gт.1стр.352гр.7 +  ф.0503768Gт.1стр.352гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (89,1,567903,7,0,0,0,'ф.0503730G_BUт.1стр.041гр.8 =  ф.0503768Gт.1стр.352гр.7 +  ф.0503768Gт.1стр.352гр.7 +  ф.0503768Gт.1стр.352гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (90,1,567904,7,0,0,0,'ф.0503730G_BUт.1стр.090гр.3 =  ф.0503768Gт.1стр.070гр.4 +  ф.0503768Gт.1стр.130гр.4 +  ф.0503768Gт.1стр.170гр.4 +  ф.0503768Gт.1стр.230гр.4 +  ф.0503768Gт.1стр.070гр.4 +  ф.0503768Gт.1стр.130гр.4 +  ф.0503768Gт.1стр.170гр.4 +  ф.0503768Gт.1стр.230гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (91,1,567905,7,0,0,0,'ф.0503730G_BUт.1стр.090гр.4 =  ф.0503768Gт.1стр.070гр.4 +  ф.0503768Gт.1стр.130гр.4 +  ф.0503768Gт.1стр.170гр.4 +  ф.0503768Gт.1стр.230гр.4 +  ф.0503768Gт.1стр.070гр.4 +  ф.0503768Gт.1стр.130гр.4 +  ф.0503768Gт.1стр.170гр.4 +  ф.0503768Gт.1стр.230гр.4 +  ф.0503768Gт.1стр.070гр.4 +  ф.0503768Gт.1стр.130гр.4 +  ф.0503768Gт.1стр.170гр.4 +  ф.0503768Gт.1стр.230гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (92,1,567906,7,0,0,0,'ф.0503730G_BUт.1стр.090гр.7 =  ф.0503768Gт.1стр.070гр.7 +  ф.0503768Gт.1стр.130гр.7 +  ф.0503768Gт.1стр.170гр.7 +  ф.0503768Gт.1стр.230гр.7 +  ф.0503768Gт.1стр.070гр.7 +  ф.0503768Gт.1стр.130гр.7 +  ф.0503768Gт.1стр.170гр.7 +  ф.0503768Gт.1стр.230гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (93,1,567907,7,0,0,0,'ф.0503730G_BUт.1стр.090гр.8 =  ф.0503768Gт.1стр.070гр.7 +  ф.0503768Gт.1стр.130гр.7 +  ф.0503768Gт.1стр.170гр.7 +  ф.0503768Gт.1стр.230гр.7 +  ф.0503768Gт.1стр.070гр.7 +  ф.0503768Gт.1стр.130гр.7 +  ф.0503768Gт.1стр.170гр.7 +  ф.0503768Gт.1стр.230гр.7 +  ф.0503768Gт.1стр.070гр.7 +  ф.0503768Gт.1стр.130гр.7 +  ф.0503768Gт.1стр.170гр.7 +  ф.0503768Gт.1стр.230гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (94,1,567908,7,0,0,0,'ф.0503730G_BUт.1стр.100гр.3 =  ф.0503768Gт.1стр.080гр.4 +  ф.0503768Gт.1стр.250гр.4 +  ф.0503768Gт.1стр.080гр.4 +  ф.0503768Gт.1стр.250гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (95,1,567909,7,0,0,0,'ф.0503730G_BUт.1стр.100гр.4 =  ф.0503768Gт.1стр.080гр.4 +  ф.0503768Gт.1стр.250гр.4 +  ф.0503768Gт.1стр.080гр.4 +  ф.0503768Gт.1стр.250гр.4 +  ф.0503768Gт.1стр.080гр.4 +  ф.0503768Gт.1стр.250гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (96,1,567910,7,0,0,0,'ф.0503730G_BUт.1стр.100гр.7 =  ф.0503768Gт.1стр.080гр.7 +  ф.0503768Gт.1стр.250гр.7 +  ф.0503768Gт.1стр.080гр.7 +  ф.0503768Gт.1стр.250гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (97,1,567911,7,0,0,0,'ф.0503730G_BUт.1стр.100гр.8 =  ф.0503768Gт.1стр.080гр.7 +  ф.0503768Gт.1стр.250гр.7 +  ф.0503768Gт.1стр.080гр.7 +  ф.0503768Gт.1стр.250гр.7 +  ф.0503768Gт.1стр.080гр.7 +  ф.0503768Gт.1стр.250гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 97
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','322','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','322','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','322','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','311','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','312','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','321','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','322','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','362','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','412','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','311','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','312','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','321','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','322','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','362','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','412','1','0503768G            ','20110101',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (72,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (72,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (72,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','390','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (72,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','390','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','390','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','390','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','390','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','332','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','372','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','422','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','332','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','372','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','422','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','332','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,9,0,'+ ',0,0,'','','','','','','',8,'     ','4','372','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','422','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','332','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','372','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','422','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','332','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','372','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','422','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','332','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','422','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','332','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','422','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','332','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','422','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','332','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','422','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','332','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,9,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','422','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (78,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','341','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (78,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','341','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (79,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','341','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (79,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','341','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (79,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','341','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (81,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','341','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (81,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','341','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (81,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','341','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (82,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','342','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (82,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','432','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (82,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','342','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (82,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','432','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','342','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','432','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','342','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','432','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','342','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','432','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (84,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','342','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (84,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','432','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (84,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','342','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (84,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','432','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','342','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','432','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','342','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','432','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','342','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','432','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (80,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','341','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (80,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','341','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (86,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','352','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (86,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','352','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (87,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','352','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (87,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','352','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (87,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','352','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (89,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','352','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (89,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','352','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (89,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','352','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,9,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,9,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,11,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,12,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,13,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,9,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,9,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,11,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,12,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,13,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (94,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (94,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','250','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (94,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (94,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','250','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','250','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','250','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','250','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (96,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (96,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','250','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (96,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (96,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','250','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','250','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','250','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','250','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (88,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','352','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (88,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','352','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (89,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','041','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (97,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','100','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (96,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','100','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (95,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','100','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (94,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','100','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (93,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','090','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (92,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','090','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (91,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','090','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (90,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','090','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (88,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','041','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (87,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','041','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (81,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','101','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (86,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','041','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (85,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','102','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (84,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','102','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (83,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','102','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (82,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','102','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (80,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','101','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (79,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','101','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','040','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (78,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','101','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (77,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','092','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (75,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','092','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (76,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','092','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (74,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','092','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (73,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','091','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (72,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','091','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','091','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','091','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','040','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','040','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','022','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','022','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','022','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','022','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','081','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','051','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','022','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','021','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','012','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','011','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','010','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','040','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 387
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (65,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (66,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (67,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (68,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (69,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (70,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (71,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (72,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (73,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (74,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (75,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (76,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (77,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (78,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (79,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (80,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (81,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (82,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (83,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (84,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (85,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (86,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (87,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (88,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (89,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (90,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (91,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (92,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (93,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (94,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (95,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (96,'1281_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (97,'1281_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 97
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1281_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1281_1' , 'Проверка: 0503768G - 0503730G_BU', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:35:04:230AM)
-- Выгружены следующие группы междокументных КС:
-- 1285_1 - Проверка форм 0503737G - 0503730G (2 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1285_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1285_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567913,7,0,0,0,'-  ф.0503737Gт.1стр.700гр.9(код вида 5) субсидии на иные цели -  ф.0503737Gт.1стр.700гр.9(код вида 6) бюджетные инвестиции =  ф.0503730G_BUт.1стр.171гр.7 -  ф.0503730G_BUт.1стр.171гр.3 +  ф.0503730G_BUт.1стр.172гр.7 -  ф.0503730G_BUт.1стр.172гр.3 +  ф.0503730G_BUт.1стр.173гр.7 -  ф.0503730G_BUт.1стр.173гр.3 +  ф.0503730G_BUт.1стр.174гр.7 -  ф.0503730G_BUт.1стр.174гр.3 +  ф.0503730G_BUт.1стр.176гр.7 -  ф.0503730G_BUт.1стр.176гр.3 +  ф.0503730G_BUт.1стр.177гр.7 -  ф.0503730G_BUт.1стр.177гр.3 +  ф.0503730G_BUт.1стр.179гр.7 -  ф.0503730G_BUт.1стр.179гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567914,7,0,0,0,'-  ф.0503737Gт.1стр.700гр.9(код вида 2) собственные доходы учреждения -  ф.0503737Gт.1стр.700гр.9(код вида 4) субсидия на выполнение государственного (муниципального) задания -  ф.0503737Gт.1стр.700гр.9(код вида 7)  средства по обязательному медицинскому страхованию =  ф.0503730G_BUт.1стр.171гр.8 -  ф.0503730G_BUт.1стр.171гр.4 +  ф.0503730G_BUт.1стр.172гр.8 -  ф.0503730G_BUт.1стр.172гр.4 +  ф.0503730G_BUт.1стр.173гр.8 -  ф.0503730G_BUт.1стр.173гр.4 +  ф.0503730G_BUт.1стр.174гр.8 -  ф.0503730G_BUт.1стр.174гр.4 +  ф.0503730G_BUт.1стр.176гр.8 -  ф.0503730G_BUт.1стр.176гр.4 +  ф.0503730G_BUт.1стр.177гр.8 -  ф.0503730G_BUт.1стр.177гр.4 +  ф.0503730G_BUт.1стр.179гр.8 -  ф.0503730G_BUт.1стр.179гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'- ',0,0,'','','','','','','',8,'     ','9','700','1','0503737G            ','20121231',NULL,'#5',0,NULL,1,'(код вида 5) субсидии на иные цели',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'- ',0,0,'','','','','','','',8,'     ','9','700','1','0503737G            ','20121231',NULL,'#6',0,NULL,1,'(код вида 6) бюджетные инвестиции',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'- ',0,0,'','','','','','','',8,'     ','9','700','1','0503737G            ','20121231',NULL,'#2',0,NULL,1,'(код вида 2) собственные доходы учреждения',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'- ',0,0,'','','','','','','',8,'     ','9','700','1','0503737G            ','20121231',NULL,'#4',0,NULL,1,'(код вида 4) субсидия на выполнение государственного (муниципального) задания',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'- ',0,0,'','','','','','','',8,'     ','9','700','1','0503737G            ','20121231',NULL,'#7',0,NULL,1,'(код вида 7)  средства по обязательному медицинскому страхованию',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','171','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'- ',0,0,'','','','','','','',8,'     ','4','171','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','172','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'- ',0,0,'','','','','','','',8,'     ','4','172','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','173','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,0,'- ',0,0,'','','','','','','',8,'     ','4','173','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','174','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,11,0,'- ',0,0,'','','','','','','',8,'     ','4','174','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,12,0,'+ ',0,0,'','','','','','','',8,'     ','8','176','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,13,0,'- ',0,0,'','','','','','','',8,'     ','4','176','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,14,0,'+ ',0,0,'','','','','','','',8,'     ','8','177','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,15,0,'- ',0,0,'','','','','','','',8,'     ','4','177','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,16,0,'+ ',0,0,'','','','','','','',8,'     ','8','179','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,17,0,'- ',0,0,'','','','','','','',8,'     ','4','179','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','171','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'- ',0,0,'','','','','','','',8,'     ','3','171','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','172','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'- ',0,0,'','','','','','','',8,'     ','3','172','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','173','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,0,'- ',0,0,'','','','','','','',8,'     ','3','173','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,0,'+ ',0,0,'','','','','','','',8,'     ','7','174','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,0,'- ',0,0,'','','','','','','',8,'     ','3','174','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,0,'+ ',0,0,'','','','','','','',8,'     ','7','176','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,0,'- ',0,0,'','','','','','','',8,'     ','3','176','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,0,'+ ',0,0,'','','','','','','',8,'     ','7','177','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,0,'- ',0,0,'','','','','','','',8,'     ','3','177','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,0,'+ ',0,0,'','','','','','','',8,'     ','7','179','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,16,0,'- ',0,0,'','','','','','','',8,'     ','3','179','1','0503730G_BU         ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 33
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1285_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1285_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1285_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1285_1' , 'Проверка форм 0503737G - 0503730G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:36:19:293AM)
-- Выгружены следующие группы междокументных КС:
-- 1292_1 - Проверка 0503768G - 0503721G (8 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1292_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1292_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,568108,7,0,0,0,'ф.0503721Gт.1стр.320гр.4 =  ф.0503768Gт.1стр.010гр.5 -  ф.0503768Gт.1стр.010гр.6 -  ф.0503768Gт.1стр.050гр.6 +  ф.0503768Gт.1стр.070гр.5 -  ф.0503768Gт.1стр.070гр.6 +  ф.0503768Gт.1стр.080гр.5 -  ф.0503768Gт.1стр.080гр.6 +  ф.0503768Gт.1стр.010гр.5 -  ф.0503768Gт.1стр.010гр.6 -  ф.0503768Gт.1стр.050гр.6 +  ф.0503768Gт.1стр.070гр.5 -  ф.0503768Gт.1стр.070гр.6 +  ф.0503768Gт.1стр.080гр.5 -  ф.0503768Gт.1стр.080гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,568109,7,0,0,0,'ф.0503721Gт.1стр.320гр.5 =  ф.0503768Gт.1стр.010гр.5 -  ф.0503768Gт.1стр.010гр.6 -  ф.0503768Gт.1стр.050гр.6 +  ф.0503768Gт.1стр.070гр.5 -  ф.0503768Gт.1стр.070гр.6 +  ф.0503768Gт.1стр.080гр.5 -  ф.0503768Gт.1стр.080гр.6 +  ф.0503768Gт.1стр.010гр.5 -  ф.0503768Gт.1стр.010гр.6 -  ф.0503768Gт.1стр.050гр.6 +  ф.0503768Gт.1стр.070гр.5 -  ф.0503768Gт.1стр.070гр.6 +  ф.0503768Gт.1стр.080гр.5 -  ф.0503768Gт.1стр.080гр.6 +  ф.0503768Gт.1стр.010гр.5 -  ф.0503768Gт.1стр.010гр.6 -  ф.0503768Gт.1стр.050гр.6 +  ф.0503768Gт.1стр.070гр.5 +  ф.0503768Gт.1стр.080гр.5 -  ф.0503768Gт.1стр.080гр.6 -  ф.0503768Gт.1стр.070гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,568110,7,0,0,0,'ф.0503721Gт.1стр.330гр.4 =  ф.0503768Gт.1стр.110гр.5 -  ф.0503768Gт.1стр.110гр.6 -  ф.0503768Gт.1стр.120гр.6 +  ф.0503768Gт.1стр.130гр.5 -  ф.0503768Gт.1стр.130гр.6 +  ф.0503768Gт.1стр.110гр.5 -  ф.0503768Gт.1стр.110гр.6 -  ф.0503768Gт.1стр.120гр.6 +  ф.0503768Gт.1стр.130гр.5 -  ф.0503768Gт.1стр.130гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,568111,7,0,0,0,'ф.0503721Gт.1стр.330гр.5 =  ф.0503768Gт.1стр.110гр.5 -  ф.0503768Gт.1стр.110гр.6 -  ф.0503768Gт.1стр.120гр.6 +  ф.0503768Gт.1стр.130гр.5 -  ф.0503768Gт.1стр.130гр.6 +  ф.0503768Gт.1стр.110гр.5 -  ф.0503768Gт.1стр.110гр.6 -  ф.0503768Gт.1стр.120гр.6 +  ф.0503768Gт.1стр.130гр.5 -  ф.0503768Gт.1стр.130гр.6 +  ф.0503768Gт.1стр.110гр.5 -  ф.0503768Gт.1стр.110гр.6 -  ф.0503768Gт.1стр.120гр.6 +  ф.0503768Gт.1стр.130гр.5 -  ф.0503768Gт.1стр.130гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,568112,7,0,0,0,'ф.0503721Gт.1стр.350гр.4 =  ф.0503768Gт.1стр.150гр.5 -  ф.0503768Gт.1стр.150гр.6 +  ф.0503768Gт.1стр.170гр.5 -  ф.0503768Gт.1стр.170гр.6 +  ф.0503768Gт.1стр.150гр.5 -  ф.0503768Gт.1стр.150гр.6 +  ф.0503768Gт.1стр.170гр.5 -  ф.0503768Gт.1стр.170гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,568113,7,0,0,0,'ф.0503721Gт.1стр.350гр.5 =  ф.0503768Gт.1стр.150гр.5 -  ф.0503768Gт.1стр.150гр.6 +  ф.0503768Gт.1стр.170гр.5 -  ф.0503768Gт.1стр.170гр.6 +  ф.0503768Gт.1стр.150гр.5 -  ф.0503768Gт.1стр.150гр.6 +  ф.0503768Gт.1стр.170гр.5 -  ф.0503768Gт.1стр.170гр.6 +  ф.0503768Gт.1стр.150гр.5 -  ф.0503768Gт.1стр.150гр.6 +  ф.0503768Gт.1стр.170гр.5 -  ф.0503768Gт.1стр.170гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,568114,7,0,0,0,'ф.0503721Gт.1стр.360гр.4 =  ф.0503768Gт.1стр.190гр.5 -  ф.0503768Gт.1стр.190гр.6 +  ф.0503768Gт.1стр.230гр.5 -  ф.0503768Gт.1стр.230гр.6 +  ф.0503768Gт.1стр.250гр.5 -  ф.0503768Gт.1стр.250гр.6 +  ф.0503768Gт.1стр.190гр.5 -  ф.0503768Gт.1стр.190гр.6 +  ф.0503768Gт.1стр.230гр.5 -  ф.0503768Gт.1стр.230гр.6 +  ф.0503768Gт.1стр.250гр.5 -  ф.0503768Gт.1стр.250гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,568115,7,0,0,0,'ф.0503721Gт.1стр.360гр.5 =  ф.0503768Gт.1стр.190гр.5 -  ф.0503768Gт.1стр.190гр.6 +  ф.0503768Gт.1стр.230гр.5 -  ф.0503768Gт.1стр.230гр.6 +  ф.0503768Gт.1стр.250гр.5 -  ф.0503768Gт.1стр.250гр.6 +  ф.0503768Gт.1стр.190гр.5 -  ф.0503768Gт.1стр.190гр.6 +  ф.0503768Gт.1стр.230гр.5 -  ф.0503768Gт.1стр.230гр.6 +  ф.0503768Gт.1стр.250гр.5 -  ф.0503768Gт.1стр.250гр.6 +  ф.0503768Gт.1стр.190гр.5 -  ф.0503768Gт.1стр.190гр.6 +  ф.0503768Gт.1стр.230гр.5 -  ф.0503768Gт.1стр.230гр.6 +  ф.0503768Gт.1стр.250гр.5 -  ф.0503768Gт.1стр.250гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,10,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,11,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,13,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,14,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,15,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,16,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,17,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,18,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,19,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,20,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,21,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,22,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,8,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,9,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,11,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,11,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,13,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,14,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,15,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,16,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,9,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,7,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,9,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,11,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,13,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,7,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503768G            ','20110101',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,9,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,11,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,13,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503768G            ','20110101',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,14,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,15,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,16,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,17,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,18,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,19,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503768G            ','20110101',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503768G            ','20110101',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,9,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,11,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,12,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,13,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503768G            ','20110101',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','360','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','360','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','350','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','350','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','330','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','320','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','330','1','0503721G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 118
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1292_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1292_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1292_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1292_1' , 'Проверка 0503768G - 0503721G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:35:11:440AM)
-- Выгружены следующие группы междокументных КС:
-- 1293_1 - Проверка 0503730G- 0503779G (60 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1293_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1293_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567916,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.7 =  ф.0503779Gт.1гр.5Фильтр:Счета 520121000, 620121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567917,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.7 =  ф.0503779Gт.2гр.5Фильтр:Счета 520111000,620111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567918,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.7 =  ф.0503779Gт.1гр.5Фильтр:Счета 520126000, 620126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567919,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.7 =  ф.0503779Gт.1гр.5Фильтр:Счета 520127000, 620127000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567920,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.7 =  ф.0503779Gт.1гр.5Фильтр:Счета 520122000, 620122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567921,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.3 =  ф.0503779Gт.1гр.3Фильтр:Счета 520121000, 620121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567922,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.3 =  ф.0503779Gт.2гр.3Фильтр:520111000,620111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567923,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.3 =  ф.0503779Gт.1гр.3Фильтр:Счета 520126000, 620126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567924,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.3 =  ф.0503779Gт.1гр.3Фильтр:Счета 520127000, 620127000',8,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',5,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567925,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.3 =  ф.0503779Gт.1гр.3Фильтр:Счета 520122000, 620122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567926,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.4 =  ф.0503779Gт.2гр.3Фильтр:Счета 220111000, 420111000, 720111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567927,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.8 =  ф.0503779Gт.2гр.5Фильтр:Счета 220111000,420111000,720111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567928,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.4 =  ф.0503779Gт.1гр.3Фильтр:Счета 220121000, 420121000, 720121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567929,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.8 =  ф.0503779Gт.1гр.5Фильтр:Счета 220121000, 420121000, 720121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567930,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.4 =  ф.0503779Gт.1гр.3Фильтр:Счета 220126000, 420126000, 720126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567931,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.8 =  ф.0503779Gт.1гр.5Фильтр:Счета 220126000, 420126000, 720126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567932,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.4 =  ф.0503779Gт.1гр.3Фильтр:Счета 220127000, 420127000, 720127000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567933,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.8 =  ф.0503779Gт.1гр.5Фильтр:Счета 220127000, 420127000, 720127000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567934,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.4 =  ф.0503779Gт.1гр.3Фильтр:Счета 220122000, 420122000, 720122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567935,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.8 =  ф.0503779Gт.1гр.5Фильтр:Счета 220122000, 420122000, 720122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567936,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.5 =  ф.0503779Gт.2гр.3Фильтр:Счет 320111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567937,7,0,0,0,'ф.0503730G_BUт.1стр.171гр.9 =  ф.0503779Gт.2гр.5Фильтр:320111000 Комментарий: Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','Сумма остатков на счетах в финансовом органе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567938,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.5 =  ф.0503779Gт.1гр.3Фильтр:320121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567939,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.9 =  ф.0503779Gт.1гр.5Фильтр:320121000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567940,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.5 =  ф.0503779Gт.1гр.3Фильтр:320126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567941,7,0,0,0,'ф.0503730G_BUт.1стр.175гр.9 =  ф.0503779Gт.1гр.5Фильтр:320126000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567942,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.5 =  ф.0503779Gт.1гр.3Фильтр:320127000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567943,7,0,0,0,'ф.0503730G_BUт.1стр.176гр.9 =  ф.0503779Gт.1гр.5Фильтр:320127000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567944,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.5 =  ф.0503779Gт.1гр.3Фильтр:320122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567945,7,0,0,0,'ф.0503730G_BUт.1стр.179гр.9 =  ф.0503779Gт.1гр.5Фильтр:320122000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567946,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.3 +  ф.0503730G_BUт.1стр.175гр.3 +  ф.0503730G_BUт.1стр.176гр.3 +  ф.0503730G_BUт.1стр.179гр.3 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567947,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.3 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567948,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.4 +  ф.0503730G_BUт.1стр.175гр.4 +  ф.0503730G_BUт.1стр.176гр.4 +  ф.0503730G_BUт.1стр.179гр.4 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части дея-тельности по оказанию услуг (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части дея-тельности по оказанию услуг (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567949,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.4 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567950,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.5 +  ф.0503730G_BUт.1стр.175гр.5 +  ф.0503730G_BUт.1стр.176гр.5 +  ф.0503730G_BUт.1стр.179гр.5 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части дея-тельности со средствами во временном распоряжении (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части дея-тельности со средствами во временном распоряжении (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567951,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.5 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567952,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.7 +  ф.0503730G_BUт.1стр.175гр.7 +  ф.0503730G_BUт.1стр.176гр.7 +  ф.0503730G_BUт.1стр.179гр.7 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567953,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.7 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567954,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.8 +  ф.0503730G_BUт.1стр.175гр.8 +  ф.0503730G_BUт.1стр.176гр.8 +  ф.0503730G_BUт.1стр.179гр.8 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567955,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.8 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в кредитной органи-зации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец го-да) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной органи-зации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец го-да) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567956,7,0,0,0,'ф.0503730G_BUт.1стр.173гр.9 +  ф.0503730G_BUт.1стр.175гр.9 +  ф.0503730G_BUт.1стр.176гр.9 +  ф.0503730G_BUт.1стр.179гр.9 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567957,7,0,0,0,'ф.0503730G_BUт.1стр.174гр.9 =  ф.0503779Gт.1стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в кредитной организации в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567958,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.3 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567959,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.4 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567960,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.5 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.4 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567961,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.7 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567962,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.8 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567963,7,0,0,0,'ф.0503730G_BUт.1стр.172гр.9 =  ф.0503779Gт.2стр.88888888888888888888888888888888888гр.6 Комментарий: Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустим',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков на счетах в финансовом органе в пути по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недопустим')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567964,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.3 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на начало года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567965,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.4 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на начало года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567966,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.5 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.3 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во вре-менном распоряжении (на начало года) - недо-пустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во вре-менном распоряжении (на начало года) - недо-пустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567967,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.7 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности с целевыми средствами (на конец года)  - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567968,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.8 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности по оказанию услуг (на конец года) - недопустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567969,7,0,0,0,'ф.0503730G_BUт.1стр.177гр.9 =  ф.0503779Gт.3стр.88888888888888888888888888888888888гр.5 Комментарий: Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недо-пустимо',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Сумма остатков в кассе по ф. 0503779 не соответствует идентичному показателю в балансе в части деятельности со средствами во временном распоряжении (на конец года) - недо-пустимо')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567970,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.3 =  ф.0503779Gт.2гр.3Фильтр:5 210 03 000,6 210 03 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567971,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.4 =  ф.0503779Gт.2гр.3Фильтр:421003000,221003000,721003000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567972,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.5 =  ф.0503779Gт.2гр.3Фильтр:3 210 03 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567973,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.7 =  ф.0503779Gт.2гр.5Фильтр:5 210 03 000,6 210 03 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567974,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.8 =  ф.0503779Gт.2гр.5Фильтр:421003000,221003000,721003000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567975,7,0,0,0,'ф.0503730G_BUт.1стр.333гр.9 =  ф.0503779Gт.2гр.5Фильтр:3 210 03 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 60
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520121000'',''620121000'')','Счета 520121000, 620121000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520126000'',''620126000'')','Счета 520126000, 620126000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520127000'',''620127000'')','Счета 520127000, 620127000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520122000'',''620122000'')','Счета 520122000, 620122000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)  in (''520121000'',''620121000'')','Счета 520121000, 620121000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520126000'',''620126000'')','Счета 520126000, 620126000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520127000'',''620127000'')','Счета 520127000, 620127000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520122000'',''620122000'')','Счета 520122000, 620122000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220121000'',''420121000'',''720121000'')','Счета 220121000, 420121000, 720121000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220121000'',''420121000'',''720121000'')','Счета 220121000, 420121000, 720121000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220126000'',''420126000'',''720126000'')','Счета 220126000, 420126000, 720126000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220126000'',''420126000'',''720126000'')','Счета 220126000, 420126000, 720126000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220127000'',''420127000'',''720127000'')','Счета 220127000, 420127000, 720127000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,4,'+ ',0,0,'','','','
SUBSTRING(CODE,1,9) in (''220127000'',''420127000'',''720127000'')','Счета 220127000, 420127000, 720127000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220122000'',''420122000'',''720122000'')','Счета 220122000, 420122000, 720122000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220122000'',''420122000'',''720122000'')','Счета 220122000, 420122000, 720122000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320121000''','320121000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320121000''','320121000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320126000''','320126000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320126000''','320126000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320127000''','320127000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320127000''','320127000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320122000''','320122000','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320122000''','320122000','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,5,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','1','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''521003000'',''621003000'')','5 210 03 000,6 210 03 000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''221003000'',''421003000'',''721003000'')','421003000,221003000,721003000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''321003000'')','3 210 03 000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''521003000'',''621003000'')','5 210 03 000,6 210 03 000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320111000''','Счет 320111000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''320111000''','320111000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220111000'',''420111000'',''720111000'')','Счета 220111000, 420111000, 720111000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''220111000'',''420111000'',''720111000'')','Счета 220111000,420111000,720111000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''520111000'',''620111000'')','520111000,620111000','','',8,'     ','3','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)  in (''520111000'',''620111000'')','Счета 520111000,620111000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''221003000'',''421003000'',''721003000'')','421003000,221003000,721003000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9) in (''321003000'')','3 210 03 000','','',8,'     ','5','','2','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=t',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=b',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','3','0503779G            ','20110101',NULL,'#REPORTS_ATR_VID_773=v',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','177','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','172','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,0,'+ ',0,0,'','','','','','','',8,'     ','9','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','171','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','174','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','3','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,0,'+ ',0,0,'','','','','','','',8,'     ','3','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','179','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','176','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','175','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','173','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','333','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 138
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'1293_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'1293_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 60
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1293_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1293_1' , 'Проверка 0503730G- 0503779G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:35:21:147AM)
-- Выгружены следующие группы междокументных КС:
-- 1360_1 - Проверка:0503730G, 0503721G,0503710G (2 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1360_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1360_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567977,7,0,0,0,'ф.0503721Gт.1стр.300гр.4 =  ф.0503730G_BUт.1стр.623гр.7 -  ф.0503730G_BUт.1стр.623гр.3 +  ф.0503730G_BUт.1стр.624гр.7 -  ф.0503730G_BUт.1стр.624гр.3 +  ф.0503730G_BUт.1стр.625гр.7 -  ф.0503730G_BUт.1стр.625гр.3 +  ф.0503710Gт.1стр.530406000гр.2 -  ф.0503710Gт.1стр.530406000гр.3 +  ф.0503710Gт.1стр.630406000гр.2 -  ф.0503710Gт.1стр.630406000гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567978,7,0,0,0,'ф.0503721Gт.1стр.300гр.5 =  ф.0503730G_BUт.1стр.623гр.8 -  ф.0503730G_BUт.1стр.623гр.4 +  ф.0503730G_BUт.1стр.624гр.8 -  ф.0503730G_BUт.1стр.624гр.4 +  ф.0503730G_BUт.1стр.625гр.8 -  ф.0503730G_BUт.1стр.625гр.4 +  ф.0503710Gт.1стр.230406000гр.4 -  ф.0503710Gт.1стр.230406000гр.5 +  ф.0503710Gт.1стр.430406000гр.4 -  ф.0503710Gт.1стр.430406000гр.5 +  ф.0503710Gт.1стр.730406000гр.4 -  ф.0503710Gт.1стр.730406000гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,3,'+ ',0,0,'','','530406000','','','','',8,'     ','2','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,3,'- ',0,0,'','','530406000','','','','',8,'     ','3','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,3,'+ ',0,0,'','','630406000','','','','',8,'     ','2','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,3,'- ',0,0,'','','630406000','','','','',8,'     ','3','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,3,'+ ',0,0,'','','230406000','','','','',8,'     ','4','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,3,'- ',0,0,'','','230406000','','','','',8,'     ','5','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,10,3,'+ ',0,0,'','','430406000','','','','',8,'     ','4','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,11,3,'- ',0,0,'','','430406000','','','','',8,'     ','5','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,12,3,'+ ',0,0,'','','730406000','','','','',8,'     ','4','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,13,3,'- ',0,0,'','','730406000','','','','',8,'     ','5','','1','0503710G            ','20111231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','623','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'- ',0,0,'','','','','','','',8,'     ','4','623','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','624','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'- ',0,0,'','','','','','','',8,'     ','4','624','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','625','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'- ',0,0,'','','','','','','',8,'     ','4','625','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','623','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'- ',0,0,'','','','','','','',8,'     ','3','623','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','624','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'- ',0,0,'','','','','','','',8,'     ','3','624','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','625','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'- ',0,0,'','','','','','','',8,'     ','3','625','1','0503730G_BU         ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 24
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1360_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1360_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1360_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1360_1' , 'Проверка:0503730G, 0503721G,0503710G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:36:27:840AM)
-- Выгружены следующие группы междокументных КС:
-- 1402_1 - Проверка:0503830G, 0503721G,0503725G (36 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1402_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1402_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,568117,7,0,0,0,'ф.0503721Gт.1стр.540гр.4 =  ф.0503830Gт.1стр.490гр.7 -  ф.0503830Gт.1стр.490гр.3 +  ф.0503830Gт.1стр.510гр.7 -  ф.0503830Gт.1стр.510гр.3 +  ф.0503830Gт.1стр.530гр.7 -  ф.0503830Gт.1стр.530гр.3 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,568118,7,0,0,0,'ф.0503721Gт.1стр.310гр.4 =  ф.0503830Gт.1стр.150гр.7 -  ф.0503830Gт.1стр.150гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,568119,7,0,0,0,'ф.0503721Gт.1стр.470гр.4 =  ф.0503830Gт.1стр.213гр.7 -  ф.0503830Gт.1стр.213гр.3 +  ф.0503830Gт.1стр.373гр.7 -  ф.0503830Gт.1стр.373гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,568120,7,0,0,0,'ф.0503721Gт.1стр.420гр.4 =  ф.0503830Gт.1стр.211гр.7 -  ф.0503830Gт.1стр.211гр.3 +  ф.0503830Gт.1стр.371гр.7 -  ф.0503830Gт.1стр.371гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,568121,7,0,0,0,'ф.0503721Gт.1стр.460гр.4 =  ф.0503830Gт.1стр.290гр.7 -  ф.0503830Gт.1стр.290гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,568122,7,0,0,0,'ф.0503721Gт.1стр.520гр.4 +  ф.0503721Gт.1стр.530гр.4 =  ф.0503830Gт.1стр.470гр.7 -  ф.0503830Gт.1стр.470гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,568123,7,0,0,0,'ф.0503721Gт.1стр.540гр.5 =  ф.0503830Gт.1стр.490гр.8 -  ф.0503830Gт.1стр.490гр.4 +  ф.0503830Gт.1стр.510гр.8 -  ф.0503830Gт.1стр.510гр.4 +  ф.0503830Gт.1стр.530гр.8 -  ф.0503830Gт.1стр.530гр.4 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,568124,7,0,0,0,'ф.0503721Gт.1стр.540гр.6 =  ф.0503830Gт.1стр.490гр.9 -  ф.0503830Gт.1стр.490гр.5 +  ф.0503830Gт.1стр.510гр.9 -  ф.0503830Gт.1стр.510гр.5 +  ф.0503830Gт.1стр.530гр.9 -  ф.0503830Gт.1стр.530гр.5 Комментарий: Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Чистое увеличение прочей кредиторской за-долженности за отчетный год по ф. 0503721 не соответствует изменению остатков по ф. 0503730 в части деятельности с целевыми средствами -  допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,568125,7,0,0,0,'ф.0503721Gт.1стр.520гр.5 +  ф.0503721Gт.1стр.530гр.5 =  ф.0503830Gт.1стр.470гр.8 -  ф.0503830Gт.1стр.470гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,568126,7,0,0,0,'ф.0503721Gт.1стр.520гр.6 +  ф.0503721Gт.1стр.530гр.6 =  ф.0503830Gт.1стр.470гр.9 -  ф.0503830Gт.1стр.470гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,568127,7,0,0,0,'ф.0503721Gт.1стр.470гр.5 =  ф.0503830Gт.1стр.213гр.8 -  ф.0503830Gт.1стр.213гр.4 +  ф.0503830Gт.1стр.373гр.8 -  ф.0503830Gт.1стр.373гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,568128,7,0,0,0,'ф.0503721Gт.1стр.470гр.6 =  ф.0503830Gт.1стр.213гр.9 -  ф.0503830Gт.1стр.213гр.5 +  ф.0503830Gт.1стр.373гр.9 -  ф.0503830Gт.1стр.373гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,568129,7,0,0,0,'ф.0503721Gт.1стр.460гр.5 =  ф.0503830Gт.1стр.290гр.8 -  ф.0503830Gт.1стр.290гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,568130,7,0,0,0,'ф.0503721Gт.1стр.460гр.6 =  ф.0503830Gт.1стр.290гр.9 -  ф.0503830Gт.1стр.290гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,568131,7,0,0,0,'ф.0503721Gт.1стр.420гр.5 =  ф.0503830Gт.1стр.211гр.8 -  ф.0503830Gт.1стр.211гр.4 +  ф.0503830Gт.1стр.371гр.8 -  ф.0503830Gт.1стр.371гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,568132,7,0,0,0,'ф.0503721Gт.1стр.420гр.6 =  ф.0503830Gт.1стр.211гр.9 -  ф.0503830Gт.1стр.211гр.5 +  ф.0503830Gт.1стр.371гр.9 -  ф.0503830Gт.1стр.371гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,568133,7,0,0,0,'ф.0503721Gт.1стр.310гр.5 =  ф.0503830Gт.1стр.150гр.8 -  ф.0503830Gт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,568134,7,0,0,0,'ф.0503721Gт.1стр.310гр.6 =  ф.0503830Gт.1стр.150гр.9 -  ф.0503830Gт.1стр.150гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,568135,7,0,0,0,'ф.0503721Gт.1стр.300гр.4 =  ф.0503830Gт.1стр.620гр.7 -  ф.0503830Gт.1стр.620гр.3 -  ф.0503830Gт.1стр.6231гр.7 +  ф.0503830Gт.1стр.6231гр.3 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,568136,7,0,0,0,'ф.0503721Gт.1стр.300гр.5 =  ф.0503830Gт.1стр.620гр.8 -  ф.0503830Gт.1стр.620гр.4 -  ф.0503830Gт.1стр.6231гр.8 +  ф.0503830Gт.1стр.6231гр.4 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,568137,7,0,0,0,'ф.0503721Gт.1стр.300гр.6 =  ф.0503830Gт.1стр.620гр.9 -  ф.0503830Gт.1стр.620гр.5 -  ф.0503830Gт.1стр.6231гр.9 +  ф.0503830Gт.1стр.6231гр.5 Комментарий: Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Финансовый результат по счетам баланса не соответствует идентичному показателю в ф. 0503721- допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,568138,7,0,0,0,'ф.0503721Gт.1стр.390гр.4 =  ф.0503830Gт.1стр.400гр.7 -  ф.0503830Gт.1стр.400гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,568139,7,0,0,0,'ф.0503721Gт.1стр.390гр.5 =  ф.0503830Gт.1стр.400гр.8 -  ф.0503830Gт.1стр.400гр.4 -  ф.0503830Gт.1стр.337гр.8 +  ф.0503830Gт.1стр.337гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,568140,7,0,0,0,'ф.0503721Gт.1стр.390гр.6 =  ф.0503830Gт.1стр.400гр.9 -  ф.0503830Gт.1стр.400гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,568141,7,0,0,0,'ф.0503721Gт.1стр.440гр.4 =  ф.0503830Gт.1стр.212гр.7 -  ф.0503830Gт.1стр.212гр.3 +  ф.0503830Gт.1стр.372гр.7 -  ф.0503830Gт.1стр.372гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,568142,7,0,0,0,'ф.0503721Gт.1стр.440гр.5 =  ф.0503830Gт.1стр.212гр.8 -  ф.0503830Gт.1стр.212гр.4 +  ф.0503830Gт.1стр.372гр.8 -  ф.0503830Gт.1стр.372гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,568143,7,0,0,0,'ф.0503721Gт.1стр.440гр.6 =  ф.0503830Gт.1стр.212гр.9 -  ф.0503830Gт.1стр.212гр.5 +  ф.0503830Gт.1стр.372гр.9 -  ф.0503830Gт.1стр.372гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,568144,7,0,0,0,'ф.0503721Gт.1стр.480гр.4 =  ф.0503830Gт.1стр.230гр.7 -  ф.0503830Gт.1стр.230гр.3 +  ф.0503830Gт.1стр.260гр.7 -  ф.0503830Gт.1стр.260гр.3 +  ф.0503830Gт.1стр.310гр.7 -  ф.0503830Gт.1стр.310гр.3 +  ф.0503830Gт.1стр.320гр.7 -  ф.0503830Gт.1стр.320гр.3 +  ф.0503830Gт.1стр.330гр.7 -  ф.0503830Gт.1стр.330гр.3 -  ф.0503830Gт.1стр.337гр.7 +  ф.0503830Gт.1стр.337гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,568145,7,0,0,0,'ф.0503721Gт.1стр.480гр.5 =  ф.0503830Gт.1стр.230гр.8 -  ф.0503830Gт.1стр.230гр.4 +  ф.0503830Gт.1стр.260гр.8 -  ф.0503830Gт.1стр.260гр.4 +  ф.0503830Gт.1стр.310гр.8 -  ф.0503830Gт.1стр.310гр.4 +  ф.0503830Gт.1стр.320гр.8 -  ф.0503830Gт.1стр.320гр.4 +  ф.0503830Gт.1стр.330гр.8 -  ф.0503830Gт.1стр.330гр.4 -  ф.0503830Gт.1стр.337гр.8 +  ф.0503830Gт.1стр.337гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,568146,7,0,0,0,'ф.0503721Gт.1стр.480гр.6 =  ф.0503830Gт.1стр.230гр.9 -  ф.0503830Gт.1стр.230гр.5 +  ф.0503830Gт.1стр.260гр.9 -  ф.0503830Gт.1стр.260гр.5 +  ф.0503830Gт.1стр.310гр.9 -  ф.0503830Gт.1стр.310гр.5 +  ф.0503830Gт.1стр.320гр.9 -  ф.0503830Gт.1стр.320гр.5 +  ф.0503830Gт.1стр.330гр.9 -  ф.0503830Gт.1стр.330гр.5 -  ф.0503830Gт.1стр.337гр.9 +  ф.0503830Gт.1стр.337гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,568147,7,0,0,0,'ф.0503721Gт.1стр.510гр.4 =  ф.0503830Gт.1стр.600гр.7 -  ф.0503830Gт.1стр.600гр.3 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,568148,7,0,0,0,'ф.0503721Gт.1стр.510гр.5 =  ф.0503830Gт.1стр.600гр.8 -  ф.0503830Gт.1стр.600гр.4 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,568149,7,0,0,0,'ф.0503721Gт.1стр.510гр.6 =  ф.0503830Gт.1стр.600гр.9 -  ф.0503830Gт.1стр.600гр.5 Комментарий: Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','Операции с обязательствами за отчетный год по ф. 0503721 не соответствует изменению ос-татков по ф. 0503730 в части деятельности с целевыми средствами - допустимо на сумму оборотов по счету 0 304 06 000')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,568150,7,0,0,0,'ф.0503721Gт.1стр.370гр.4 =  ф.0503830Gт.1стр.140гр.7 -  ф.0503830Gт.1стр.140гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,568151,7,0,0,0,'ф.0503721Gт.1стр.370гр.5 =  ф.0503830Gт.1стр.140гр.8 -  ф.0503830Gт.1стр.140гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,568152,7,0,0,0,'ф.0503721Gт.1стр.370гр.6 =  ф.0503830Gт.1стр.140гр.9 -  ф.0503830Gт.1стр.140гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 36
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'- ',0,0,'','','','','','','',8,'     ','3','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'- ',0,0,'','','','','','','',8,'     ','3','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'- ',0,0,'','','','','','','',8,'     ','4','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'- ',0,0,'','','','','','','',8,'     ','4','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'- ',0,0,'','','','','','','',8,'     ','4','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'- ',0,0,'','','','','','','',8,'     ','5','490','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,0,'- ',0,0,'','','','','','','',8,'     ','5','510','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,6,0,'+ ',0,0,'','','','','','','',8,'     ','9','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,7,0,'- ',0,0,'','','','','','','',8,'     ','5','530','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,0,'- ',0,0,'','','','','','','',8,'     ','4','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,0,'- ',0,0,'','','','','','','',8,'     ','4','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,0,'- ',0,0,'','','','','','','',8,'     ','4','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,0,'+ ',0,0,'','','','','','','',8,'     ','9','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,0,'- ',0,0,'','','','','','','',8,'     ','5','470','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'- ',0,0,'','','','','','','',8,'     ','4','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'- ',0,0,'','','','','','','',8,'     ','4','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,0,'- ',0,0,'','','','','','','',8,'     ','4','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'- ',0,0,'','','','','','','',8,'     ','5','290','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'- ',0,0,'','','','','','','',8,'     ','4','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,0,'- ',0,0,'','','','','','','',8,'     ','3','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,0,'- ',0,0,'','','','','','','',8,'     ','7','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,0,'- ',0,0,'','','','','','','',8,'     ','4','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,0,'- ',0,0,'','','','','','','',8,'     ','8','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,0,'- ',0,0,'','','','','','','',8,'     ','5','620','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,4,0,'- ',0,0,'','','','','','','',8,'     ','9','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','6231','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'- ',0,0,'','','','','','','',8,'     ','5','150','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,0,'- ',0,0,'','','','','','','',8,'     ','8','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,5,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,0,'- ',0,0,'','','','','','','',8,'     ','4','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,5,0,'- ',0,0,'','','','','','','',8,'     ','4','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,11,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,12,0,'- ',0,0,'','','','','','','',8,'     ','7','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,13,0,'+ ',0,0,'','','','','','','',8,'     ','3','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,0,'- ',0,0,'','','','','','','',8,'     ','4','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,0,'- ',0,0,'','','','','','','',8,'     ','4','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,7,0,'- ',0,0,'','','','','','','',8,'     ','4','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,9,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,11,0,'- ',0,0,'','','','','','','',8,'     ','4','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,12,0,'- ',0,0,'','','','','','','',8,'     ','8','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,13,0,'+ ',0,0,'','','','','','','',8,'     ','4','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,6,0,'+ ',0,0,'','','','','','','',8,'     ','9','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,7,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,8,0,'+ ',0,0,'','','','','','','',8,'     ','9','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,9,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,10,0,'+ ',0,0,'','','','','','','',8,'     ','9','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,11,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,12,0,'- ',0,0,'','','','','','','',8,'     ','9','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,13,0,'+ ',0,0,'','','','','','','',8,'     ','5','337','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,0,'+ ',0,0,'','','','','','','',8,'     ','9','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,5,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,0,'- ',0,0,'','','','','','','',8,'     ','5','400','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'- ',0,0,'','','','','','','',8,'     ','3','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'- ',0,0,'','','','','','','',8,'     ','4','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'- ',0,0,'','','','','','','',8,'     ','5','600','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'- ',0,0,'','','','','','','',8,'     ','3','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'- ',0,0,'','','','','','','',8,'     ','4','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','9','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'- ',0,0,'','','','','','','',8,'     ','5','140','1','0503830G            ','20130101',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','370','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','510','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','480','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','300','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','540','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','520','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','530','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','460','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503721G            ','20141231',NULL,'''Тип организации: ''+RTRIM(REPORTS_ATR_TYPE_ORG)',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 179
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1402_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1402_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 36
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1402_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1402_1' , 'Проверка:0503830G, 0503721G,0503725G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:40:087PM)
-- Выгружены следующие группы междокументных КС:
-- 1405_1 - Проверка: 0503230G - 0503169М (БД, БК) (32 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1405_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1405_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567593,7,0,0,0,'ф.0503230Gт.1стр.230гр.3 =  ф.0503169M_БДт.1стр.00000000000000000120500000гр.2 +  ф.0503169M_БДт.2стр.00000000000000000120500000гр.2 +  ф.0503169M_БДт.3стр.00000000000000000120500000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567594,7,0,0,0,'ф.0503230Gт.1стр.260гр.3 =  ф.0503169M_БДт.1стр.00000000000000000120600000гр.2 +  ф.0503169M_БДт.2стр.00000000000000000120600000гр.2 +  ф.0503169M_БДт.3стр.00000000000000000120600000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567595,7,0,0,0,'ф.0503230Gт.1стр.310гр.3 =  ф.0503169M_БДт.1стр.00000000000000000120800000гр.2 +  ф.0503169M_БДт.2стр.00000000000000000120800000гр.2 +  ф.0503169M_БДт.3стр.00000000000000000120800000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567596,7,0,0,0,'ф.0503230Gт.1стр.320гр.3 =  ф.0503169M_БДт.1стр.00000000000000000120900000гр.2 +  ф.0503169M_БДт.2стр.00000000000000000120900000гр.2 +  ф.0503169M_БДт.3стр.00000000000000000120900000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567597,7,0,0,0,'ф.0503230Gт.1стр.331гр.3 =  ф.0503169M_БДт.1стр.00000000000000000121001000гр.2 +  ф.0503169M_БДт.2стр.00000000000000000121001000гр.2 +  ф.0503169M_БДт.3стр.00000000000000000121001000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567598,7,0,0,0,'ф.0503230Gт.1стр.534гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130404000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130404000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130404000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567599,7,0,0,0,'ф.0503230Gт.1стр.490гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130200000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130200000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130200000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567600,7,0,0,0,'ф.0503230Gт.1стр.533гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130403000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130403000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130403000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567601,7,0,0,0,'ф.0503230Gт.1стр.510гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130300000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130300000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130300000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567602,7,0,0,0,'ф.0503230Gт.1стр.532гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130402000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130402000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130402000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567603,7,0,0,0,'ф.0503230Gт.1стр.511гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130301000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130301000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130301000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567604,7,0,0,0,'ф.0503230Gт.1стр.512гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130302000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130306000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130302000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130306000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130302000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130306000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567605,7,0,0,0,'ф.0503230Gт.1стр.513гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130303000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130303000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130303000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567606,7,0,0,0,'ф.0503230Gт.1стр.514гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130304000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130304000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130304000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567607,7,0,0,0,'ф.0503230Gт.1стр.515гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130305000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130312000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130313000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130305000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130312000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130313000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130305000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130312000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130313000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567608,7,0,0,0,'ф.0503230Gт.1стр.516гр.3 =  ф.0503169M_БКт.1стр.00000000000000000130307000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130308000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130309000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130310000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130311000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130307000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130308000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130309000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130310000гр.2 +  ф.0503169M_БКт.2стр.00000000000000000130311000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130307000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130308000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130309000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130310000гр.2 +  ф.0503169M_БКт.3стр.00000000000000000130311000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567609,7,0,0,0,'ф.0503230Gт.1стр.230гр.6 =  ф.0503169M_БДт.1стр.00000000000000000120500000гр.4 +  ф.0503169M_БДт.2стр.00000000000000000120500000гр.4 +  ф.0503169M_БДт.3стр.00000000000000000120500000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567610,7,0,0,0,'ф.0503230Gт.1стр.260гр.6 =  ф.0503169M_БДт.1стр.00000000000000000120600000гр.4 +  ф.0503169M_БДт.2стр.00000000000000000120600000гр.4 +  ф.0503169M_БДт.3стр.00000000000000000120600000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567611,7,0,0,0,'ф.0503230Gт.1стр.310гр.6 =  ф.0503169M_БДт.1стр.00000000000000000120800000гр.4 +  ф.0503169M_БДт.2стр.00000000000000000120800000гр.4 +  ф.0503169M_БДт.3стр.00000000000000000120800000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567612,7,0,0,0,'ф.0503230Gт.1стр.320гр.6 =  ф.0503169M_БДт.1стр.00000000000000000120900000гр.4 +  ф.0503169M_БДт.2стр.00000000000000000120900000гр.4 +  ф.0503169M_БДт.3стр.00000000000000000120900000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567613,7,0,0,0,'ф.0503230Gт.1стр.331гр.6 =  ф.0503169M_БДт.1стр.00000000000000000121001000гр.4 +  ф.0503169M_БДт.2стр.00000000000000000121001000гр.4 +  ф.0503169M_БДт.3стр.00000000000000000121001000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567614,7,0,0,0,'ф.0503230Gт.1стр.490гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130200000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130200000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130200000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567615,7,0,0,0,'ф.0503230Gт.1стр.510гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130300000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130300000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130300000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567616,7,0,0,0,'ф.0503230Gт.1стр.511гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130301000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130301000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130301000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567617,7,0,0,0,'ф.0503230Gт.1стр.512гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130302000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130306000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130302000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130306000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130302000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130306000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567618,7,0,0,0,'ф.0503230Gт.1стр.513гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130303000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130303000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130303000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567619,7,0,0,0,'ф.0503230Gт.1стр.514гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130304000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130304000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130304000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567620,7,0,0,0,'ф.0503230Gт.1стр.515гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130305000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130312000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130313000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130305000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130312000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130313000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130305000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130312000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130313000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567621,7,0,0,0,'ф.0503230Gт.1стр.516гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130307000гр.2 +  ф.0503169M_БКт.1стр.00000000000000000130308000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130309000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130310000гр.4 +  ф.0503169M_БКт.1стр.00000000000000000130311000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130307000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130308000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130309000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130310000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130311000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130307000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130308000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130309000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130310000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130311000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567622,7,0,0,0,'ф.0503230Gт.1стр.532гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130402000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130402000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130402000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567623,7,0,0,0,'ф.0503230Gт.1стр.533гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130403000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130403000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130403000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567624,7,0,0,0,'ф.0503230Gт.1стр.534гр.6 =  ф.0503169M_БКт.1стр.00000000000000000130404000гр.4 +  ф.0503169M_БКт.2стр.00000000000000000130404000гр.4 +  ф.0503169M_БКт.3стр.00000000000000000130404000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','4','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','1','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','8','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','8','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','8','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','8','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','8','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','2','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','4','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,4,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','3','0503169M_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,6,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','4','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,6,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','1','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,7,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,8,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,9,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,10,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,11,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,7,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,7,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,8,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,9,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,10,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,11,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,5,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','8','','2','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,6,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,7,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,10,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,12,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,13,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,14,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,15,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,16,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,8,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,9,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,10,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','4','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,12,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,13,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,14,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,15,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,16,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','3','0503169M_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','230','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','534','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','533','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','515','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','532','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','516','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','515','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','514','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','513','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','512','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','511','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','532','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','510','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','533','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','490','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','534','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','331','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','310','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','260','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','331','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','516','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','514','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','513','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','512','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','511','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 170
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1405_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1405_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1405_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1405_1' , 'Проверка: 0503230G - 0503169М (БД, БК)', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  4:59:16:740PM)
-- Выгружены следующие группы междокументных КС:
-- 1407_1 - Проверка: 0503121G - 0503120G-0503125G (18 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1407_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1407_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,566979,7,0,0,0,'ф.0503120Gт.1стр.150гр.6 -  ф.0503120Gт.1стр.150гр.3 =  ф.0503121Gт.1стр.310гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,566980,7,0,0,0,'ф.0503120Gт.1стр.150гр.8 -  ф.0503120Gт.1стр.150гр.5 =  ф.0503121Gт.1стр.310гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,566981,7,0,0,0,'ф.0503120Gт.1стр.170гр.6 -  ф.0503120Gт.1стр.170гр.3 +  ф.0503120Gт.1стр.190гр.6 -  ф.0503120Gт.1стр.190гр.3 +  ф.0503120Gт.1стр.180гр.6 -  ф.0503120Gт.1стр.180гр.3 +  ф.0503120Gт.1стр.200гр.6 -  ф.0503120Gт.1стр.200гр.3 =  ф.0503121Gт.1стр.410гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,566982,7,0,0,0,'ф.0503120Gт.1стр.170гр.8 -  ф.0503120Gт.1стр.170гр.5 +  ф.0503120Gт.1стр.190гр.8 -  ф.0503120Gт.1стр.190гр.5 +  ф.0503120Gт.1стр.180гр.8 -  ф.0503120Gт.1стр.180гр.5 +  ф.0503120Gт.1стр.200гр.8 -  ф.0503120Gт.1стр.200гр.5 =  ф.0503121Gт.1стр.410гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,566983,7,0,0,0,'ф.0503120Gт.1стр.213гр.6 -  ф.0503120Gт.1стр.213гр.3 +  ф.0503120Gт.1стр.373гр.6 -  ф.0503120Gт.1стр.373гр.3 =  ф.0503121Gт.1стр.470гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,566984,7,0,0,0,'ф.0503120Gт.1стр.213гр.8 -  ф.0503120Gт.1стр.213гр.5 +  ф.0503120Gт.1стр.373гр.8 -  ф.0503120Gт.1стр.373гр.5 =  ф.0503121Gт.1стр.470гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,566985,7,0,0,0,'ф.0503120Gт.1стр.212гр.6 -  ф.0503120Gт.1стр.212гр.3 +  ф.0503120Gт.1стр.372гр.6 -  ф.0503120Gт.1стр.372гр.3 =  ф.0503121Gт.1стр.440гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,566986,7,0,0,0,'ф.0503120Gт.1стр.212гр.8 -  ф.0503120Gт.1стр.212гр.5 +  ф.0503120Gт.1стр.372гр.8 -  ф.0503120Gт.1стр.372гр.5 =  ф.0503121Gт.1стр.440гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,566987,7,0,0,0,'ф.0503120Gт.1стр.211гр.6 -  ф.0503120Gт.1стр.211гр.3 +  ф.0503120Gт.1стр.371гр.6 -  ф.0503120Gт.1стр.371гр.3 =  ф.0503121Gт.1стр.420гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,566988,7,0,0,0,'ф.0503120Gт.1стр.211гр.8 -  ф.0503120Gт.1стр.211гр.5 +  ф.0503120Gт.1стр.371гр.8 -  ф.0503120Gт.1стр.371гр.5 =  ф.0503121Gт.1стр.420гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,566989,7,0,0,0,'ф.0503120Gт.1стр.230гр.6 -  ф.0503120Gт.1стр.230гр.3 +  ф.0503120Gт.1стр.260гр.6 -  ф.0503120Gт.1стр.260гр.3 +  ф.0503120Gт.1стр.310гр.6 -  ф.0503120Gт.1стр.310гр.3 +  ф.0503120Gт.1стр.320гр.6 -  ф.0503120Gт.1стр.320гр.3 +  ф.0503120Gт.1стр.330гр.6 -  ф.0503120Gт.1стр.330гр.3 =  ф.0503121Gт.1стр.480гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,566990,7,0,0,0,'ф.0503120Gт.1стр.230гр.8 -  ф.0503120Gт.1стр.230гр.5 +  ф.0503120Gт.1стр.260гр.8 -  ф.0503120Gт.1стр.260гр.5 +  ф.0503120Gт.1стр.310гр.8 -  ф.0503120Gт.1стр.310гр.5 +  ф.0503120Gт.1стр.320гр.8 -  ф.0503120Gт.1стр.320гр.5 +  ф.0503120Gт.1стр.330гр.8 -  ф.0503120Gт.1стр.330гр.5 =  ф.0503121Gт.1стр.480гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,566991,7,0,0,0,'ф.0503120Gт.1стр.400гр.6 -  ф.0503120Gт.1стр.400гр.3 =  ф.0503121Gт.1стр.390гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,566992,7,0,0,0,'ф.0503120Gт.1стр.400гр.7 -  ф.0503120Gт.1стр.400гр.4 =  ф.0503121Gт.1стр.390гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,566993,7,0,0,0,'ф.0503120Gт.1стр.490гр.6 -  ф.0503120Gт.1стр.490гр.3 +  ф.0503120Gт.1стр.510гр.6 -  ф.0503120Gт.1стр.510гр.3 +  ф.0503120Gт.1стр.530гр.6 -  ф.0503120Gт.1стр.530гр.3 =  ф.0503121Gт.1стр.540гр.4 +  ф.0503125Gт.4гр.6Фильтр:Итого по 130406000 -  ф.0503125Gт.4гр.7Фильтр:Итого по 130406000 +  ф.0503125Gт.4гр.6Фильтр:Итого по 730406000 -  ф.0503125Gт.4гр.7Фильтр:Итого по 730406000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,566994,7,0,0,0,'ф.0503120Gт.1стр.490гр.7 -  ф.0503120Gт.1стр.490гр.3 +  ф.0503120Gт.1стр.510гр.7 -  ф.0503120Gт.1стр.510гр.3 +  ф.0503120Gт.1стр.530гр.7 -  ф.0503120Gт.1стр.530гр.3 =  ф.0503121Gт.1стр.540гр.5 +  ф.0503125Gт.4гр.6Фильтр:Итого по 130406000 -  ф.0503125Gт.4гр.7Фильтр:Итого по 130406000 +  ф.0503125Gт.4гр.6Фильтр:Итого по 730406000 -  ф.0503125Gт.4гр.7Фильтр:Итого по 730406000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,566995,7,0,0,0,'ф.0503120Gт.1стр.610гр.6 -  ф.0503120Gт.1стр.610гр.3 =  ф.0503121Gт.1стр.290гр.4 +  ф.0503125Gт.4стр.Итогогр.6 -  ф.0503125Gт.4стр.Итогогр.7 +  ф.0503125Gт.4стр.Итогогр.6 -  ф.0503125Gт.4стр.Итогогр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,566996,7,0,0,0,'ф.0503120Gт.1стр.610гр.7 -  ф.0503120Gт.1стр.610гр.4 =  ф.0503121Gт.1стр.290гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,8,4,'+ ',0,0,'','','','CODE=''Итого''','Итого по 130406000','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,9,4,'- ',0,0,'','','','CODE=''Итого''','Итого по 130406000','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,10,4,'+ ',0,0,'','','','CODE=''Итого''','Итого по 730406000','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,11,4,'- ',0,0,'','','','CODE=''Итого''','Итого по 730406000','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,8,4,'+ ',0,0,'','','','CODE=''Итого''','Итого по 130406000','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,9,4,'- ',0,0,'','','','CODE=''Итого''','Итого по 130406000','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,10,4,'+ ',0,0,'','','','CODE=''Итого''','Итого по 730406000','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,11,4,'- ',0,0,'','','','CODE=''Итого''','Итого по 730406000','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,3,'+ ',0,0,'','','Итого','','','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,3,'- ',0,0,'','','Итого','','','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#130406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,6,3,'+ ',0,0,'','','Итого','','','','',8,'     ','6','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,7,3,'- ',0,0,'','','Итого','','','','',8,'     ','7','','4','0503125G            ','20111231',NULL,'#730406000',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','610','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'- ',0,0,'','','','','','','',8,'     ','4','610','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','610','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'- ',0,0,'','','','','','','',8,'     ','3','610','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','490','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','510','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','530','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,6,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','170','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'- ',0,0,'','','','','','','',8,'     ','3','170','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','190','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'- ',0,0,'','','','','','','',8,'     ','3','190','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','180','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,0,'- ',0,0,'','','','','','','',8,'     ','3','180','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','200','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,8,0,'- ',0,0,'','','','','','','',8,'     ','3','200','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','170','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'- ',0,0,'','','','','','','',8,'     ','5','170','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','190','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'- ',0,0,'','','','','','','',8,'     ','5','190','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'+ ',0,0,'','','','','','','',8,'     ','8','180','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,0,'- ',0,0,'','','','','','','',8,'     ','5','180','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,0,'+ ',0,0,'','','','','','','',8,'     ','8','200','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,0,'- ',0,0,'','','','','','','',8,'     ','5','200','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','150','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','150','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'- ',0,0,'','','','','','','',8,'     ','5','150','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','213','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','373','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','372','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','211','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','371','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,6,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,8,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,9,0,'+ ',0,0,'','','','','','','',8,'     ','6','330','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,10,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,8,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,9,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,10,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','400','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','390','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,11,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,11,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,0,'+ ',0,0,'','','','','','','',8,'     ','6','410','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,9,0,'+ ',0,0,'','','','','','','',8,'     ','4','410','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','540','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','290','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','290','1','0503121G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 114
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1407_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1407_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1407_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1407_1' , 'Проверка: 0503121G - 0503120G-0503125G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:47:577PM)
-- Выгружены следующие группы междокументных КС:
-- 1409_1 - Проверка: 0503230G - 0503169G (БД, БК) (32 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1409_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1409_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567626,7,0,0,0,'ф.0503230Gт.1стр.230гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120500000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120500000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120500000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567627,7,0,0,0,'ф.0503230Gт.1стр.260гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120600000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120600000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120600000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567628,7,0,0,0,'ф.0503230Gт.1стр.310гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120800000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120800000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120800000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567629,7,0,0,0,'ф.0503230Gт.1стр.320гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120900000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120900000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120900000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567630,7,0,0,0,'ф.0503230Gт.1стр.331гр.3 =  ф.0503169G_БДт.1гр.2Фильтр:Счет: 121001000 +  ф.0503169G_БДт.2гр.2Фильтр:Счет: 121001000 +  ф.0503169G_БДт.3гр.2Фильтр:Счет: 121001000',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567631,7,0,0,0,'ф.0503230Gт.1стр.534гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130404000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130404000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130404000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567632,7,0,0,0,'ф.0503230Gт.1стр.490гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130200000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130200000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130200000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567633,7,0,0,0,'ф.0503230Gт.1стр.533гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130403000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130403000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130403000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567634,7,0,0,0,'ф.0503230Gт.1стр.510гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130300000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130300000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130300000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567635,7,0,0,0,'ф.0503230Gт.1стр.532гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130402000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130402000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567636,7,0,0,0,'ф.0503230Gт.1стр.511гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130301000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130301000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130301000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567637,7,0,0,0,'ф.0503230Gт.1стр.512гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130302000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет:130306000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130302000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет:130306000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130302000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет:130306000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567638,7,0,0,0,'ф.0503230Gт.1стр.513гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130303000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130303000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130303000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567639,7,0,0,0,'ф.0503230Gт.1стр.514гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130304000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130304000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130304000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567640,7,0,0,0,'ф.0503230Gт.1стр.515гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130305000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130312000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130313000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130305000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130312000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130313000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130305000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130312000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130313000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567641,7,0,0,0,'ф.0503230Gт.1стр.516гр.3 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130307000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130308000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130309000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130310000 +  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130311000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130307000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130308000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130309000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130310000 +  ф.0503169G_БКт.2гр.2Фильтр:Счет: 130311000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130307000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130308000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130309000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130310000 +  ф.0503169G_БКт.3гр.2Фильтр:Счет: 130311000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567642,7,0,0,0,'ф.0503230Gт.1стр.230гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120500000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120500000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120500000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567643,7,0,0,0,'ф.0503230Gт.1стр.260гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120600000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120600000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120600000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567644,7,0,0,0,'ф.0503230Gт.1стр.310гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120800000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120800000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120800000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567645,7,0,0,0,'ф.0503230Gт.1стр.320гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120900000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120900000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120900000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567646,7,0,0,0,'ф.0503230Gт.1стр.331гр.6 =  ф.0503169G_БДт.1гр.4Фильтр:Счет: 121001000 +  ф.0503169G_БДт.2гр.4Фильтр:Счет: 121001000 +  ф.0503169G_БДт.3гр.4Фильтр:Счет: 121001000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567647,7,0,0,0,'ф.0503230Gт.1стр.490гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130200000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130200000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130200000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567648,7,0,0,0,'ф.0503230Gт.1стр.510гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130300000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130300000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130300000гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567649,7,0,0,0,'ф.0503230Gт.1стр.511гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130301000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130301000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567650,7,0,0,0,'ф.0503230Gт.1стр.512гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130302000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет:130306000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130302000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет:130306000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130302000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет:130306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567651,7,0,0,0,'ф.0503230Gт.1стр.513гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130303000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130303000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567652,7,0,0,0,'ф.0503230Gт.1стр.514гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130304000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130304000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567653,7,0,0,0,'ф.0503230Gт.1стр.515гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130305000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130312000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130313000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130305000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130312000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130313000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130305000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130312000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567654,7,0,0,0,'ф.0503230Gт.1стр.516гр.6 =  ф.0503169G_БКт.1гр.2Фильтр:Счет: 130307000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130308000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130309000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130310000 +  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130311000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130307000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130308000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130309000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130310000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130311000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130307000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130308000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130309000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130310000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567655,7,0,0,0,'ф.0503230Gт.1стр.532гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130402000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130402000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130402000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567656,7,0,0,0,'ф.0503230Gт.1стр.533гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130403000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130403000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130403000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567657,7,0,0,0,'ф.0503230Gт.1стр.534гр.6 =  ф.0503169G_БКт.1гр.4Фильтр:Счет: 130404000 +  ф.0503169G_БКт.2гр.4Фильтр:Счет: 130404000 +  ф.0503169G_БКт.3гр.4Фильтр:Счет: 130404000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','1210010000000','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,4,'+ ',0,0,'','','1210010000000','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''121001000''','Счет: 121001000','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','1303010000000','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','1303020000000','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','1303030000000','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,4,'+ ',0,0,'','','1303050000000','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','1303060000000','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','1304040000000','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','1304030000000','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','1304020000000','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','1303010000000','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','1303020000000','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','1303030000000','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','1303040000000','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','1303050000000','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,4,'+ ',0,0,'','','1303060000000','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,4,'+ ',0,0,'','','1303040000000','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,4,'+ ',0,0,'','','1304020000000','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,4,'+ ',0,0,'','','1304030000000','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,4,'+ ',0,0,'','','1304040000000','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130301000''','Счет: 130301000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130302000''','Счет: 130302000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130306000''','Счет:130306000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130303000''','Счет: 130303000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130305000''','Счет: 130305000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130312000''','Счет: 130312000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130313000''','Счет: 130313000','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130307000''','Счет: 130307000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130308000''','Счет: 130308000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130309000''','Счет: 130309000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130310000''','Счет: 130310000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130311000''','Счет: 130311000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130304000''','Счет: 130304000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130402000''','Счет: 130402000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130403000''','Счет: 130403000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),9)=''130404000''','Счет: 130404000','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','230','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','534','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','533','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','515','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','532','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','516','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','515','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','514','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','513','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','512','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','511','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','532','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','510','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','533','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','490','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','534','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','331','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','310','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','260','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','331','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','516','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','514','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','513','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','512','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','511','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 170
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1409_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1409_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1409_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1409_1' , 'Проверка: 0503230G - 0503169G (БД, БК)', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:56:280PM)
-- Выгружены следующие группы междокументных КС:
-- 1411_1 - Проверка: 0503230G - 0503176G (3 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1411_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1411_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567659,7,0,0,0,'ф.0503230Gт.1стр.320гр.3 =  ф.0503176Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567660,7,0,0,0,'ф.0503230Gт.1стр.320гр.7 -  ф.0503230Gт.1стр.320гр.3 =  ф.0503176Gт.1стр.020гр.4 -  ф.0503176Gт.1стр.040гр.4 -  ф.0503176Gт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567661,7,0,0,0,'ф.0503230Gт.1стр.320гр.7 =  ф.0503176Gт.1стр.060гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 3
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'- ',0,0,'','','','','','','',8,'     ','4','040','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'- ',0,0,'','','','','','','',8,'     ','4','050','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','060','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 9
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1411_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1411_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1411_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 3
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1411_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1411_1' , 'Проверка: 0503230G - 0503176G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:07:03:157PM)
-- Выгружены следующие группы междокументных КС:
-- 1412_1 - Проверка: 0503230G - 0503171G (6 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1412_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1412_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567663,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120423000 =  ф.0503230Gт.1стр.211гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567664,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220423000 =  ф.0503230Gт.1стр.211гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567665,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120434000 =  ф.0503230Gт.1стр.212гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567666,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220433000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220434000 =  ф.0503230Gт.1стр.212гр.8',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567667,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120453000 =  ф.0503230Gт.1стр.213гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567668,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220453000 =  ф.0503230Gт.1стр.213гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220421000''','Остаток по счету 220421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220422000''','Остаток по счету 220422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220423000''','Остаток по счету 220423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''','Остаток по счету 120433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220431000''','Остаток по счету 220431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220432000''','Остаток по счету 220432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''','Остаток по счету 120433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220433000''','Остаток по счету 220433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220434000''','Остаток по счету 220434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220451000''','Остаток по счету 220451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220452000''','Остаток по счету 220452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220453000''','Остаток по счету 220453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220451000''','Остаток по счету 220451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220452000''','Остаток по счету 220452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220453000''','Остаток по счету 220453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220431000''','Остаток по счету 220431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220432000''','Остаток по счету 220432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,13,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''','Остаток по счету 120433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,14,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220433000''','Остаток по счету 220433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,15,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,16,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220434000''','Остаток по счету 220434000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''','Остаток по счету 120433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220421000''','Остаток по счету 220421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220422000''','Остаток по счету 220422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220423000''','Остаток по счету 220423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,9,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,17,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 66
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1412_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1412_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1412_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1412_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1412_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1412_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1412_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1412_1' , 'Проверка: 0503230G - 0503171G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:03:58:547PM)
-- Выгружены следующие группы междокументных КС:
-- 1414_1 - Заполнение: 0503120G - 0503130G, 0503140G (8 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1414_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1414_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567324,7,0,0,0,'ф.0503120Gт.1гр.3 =  ф.0503130Gт.1гр.3 +  ф.0503140Gт.1гр.3',1,0,1,'20141230','','','','',NULL,'','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567325,7,0,0,0,'ф.0503120Gт.1гр.4 =  ф.0503130Gт.1гр.4 +  ф.0503140Gт.1гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567326,7,0,0,0,'ф.0503120Gт.1гр.5 =  ф.0503130Gт.1гр.5 +  ф.0503140Gт.1гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567327,7,0,0,0,'ф.0503120Gт.1гр.6 =  ф.0503130Gт.1гр.6 +  ф.0503140Gт.1гр.6',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567328,7,0,0,0,'ф.0503120Gт.1гр.7 =  ф.0503130Gт.1гр.7 +  ф.0503140Gт.1гр.7',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567329,7,0,0,0,'ф.0503120Gт.1гр.8 =  ф.0503130Gт.1гр.8 +  ф.0503140Gт.1гр.8',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567330,7,0,0,0,'ф.0503120Gт.2гр.4 =  ф.0503130Gт.2гр.4 +  ф.0503140Gт.2гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567331,7,0,0,0,'ф.0503120Gт.2гр.5 =  ф.0503130Gт.2гр.5 +  ф.0503140Gт.2гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,3,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,3,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503140G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 24
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1414_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1414_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1414_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1414_1' , 'Заполнение: 0503120G - 0503130G, 0503140G', 2, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:05:36:633PM)
-- Выгружены следующие группы междокументных КС:
-- 1414_M_1 - Заполнение: 0503120G - 0503130G, 0503140M (8 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1414_M_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1414_M_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567386,7,0,0,0,'ф.0503120Gт.1гр.3 =  ф.0503130Gт.1гр.3 +  ф.0503140Mт.1гр.3',1,0,1,'20141230','','','','',NULL,'','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567387,7,0,0,0,'ф.0503120Gт.1гр.4 =  ф.0503130Gт.1гр.4 +  ф.0503140Mт.1гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567388,7,0,0,0,'ф.0503120Gт.1гр.5 =  ф.0503130Gт.1гр.5 +  ф.0503140Mт.1гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567389,7,0,0,0,'ф.0503120Gт.1гр.6 =  ф.0503130Gт.1гр.6 +  ф.0503140Mт.1гр.6',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567390,7,0,0,0,'ф.0503120Gт.1гр.7 =  ф.0503130Gт.1гр.7 +  ф.0503140Mт.1гр.7',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567391,7,0,0,0,'ф.0503120Gт.1гр.8 =  ф.0503130Gт.1гр.8 +  ф.0503140Mт.1гр.8',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567392,7,0,0,0,'ф.0503120Gт.2гр.4 =  ф.0503130Gт.2гр.4 +  ф.0503140Mт.2гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567393,7,0,0,0,'ф.0503120Gт.2гр.5 =  ф.0503130Gт.2гр.5 +  ф.0503140Mт.2гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,3,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,3,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503140M            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503120G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 24
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1414_M_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1414_M_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1414_M_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1414_M_1' , 'Заполнение: 0503120G - 0503130G, 0503140M', 2, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:03:13:697PM)
-- Выгружены следующие группы междокументных КС:
-- 1423_1 - Проверка:0503120G, 0503121G,0503110G (64 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1423_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1423_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,566998,7,0,0,0,'ф.0503121Gт.1стр.020гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___101_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___101_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___103_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___103_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___104_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___104_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___105_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___105_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___106_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___106_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___107_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___107_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10909_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10909_____140110110''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,566999,7,0,0,0,'ф.0503121Gт.1стр.030гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___111_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___111_______140110120'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___112_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___112_______140110120''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567000,7,0,0,0,'ф.0503121Gт.1стр.040гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___113_______140110130'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___113_______140110130''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567001,7,0,0,0,'ф.0503121Gт.1стр.050гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___115_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___115_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___116_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___116_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1101104001140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1101104001140110140''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567002,7,0,0,0,'ф.0503121Gт.1стр.061гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___219_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___219_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___202_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___202_______140110151''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567003,7,0,0,0,'ф.0503121Gт.1стр.062гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___205_______140110152'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___205_______140110152''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567004,7,0,0,0,'ф.0503121Gт.1стр.080гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10202_____140110160'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10202_____140110160''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567005,7,0,0,0,'ф.0503121Gт.1стр.091гр.4 =  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010603____140110171'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010603____140110171''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567006,7,0,0,0,'ф.0503121Gт.1стр.092гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___114_______140110172'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___114_______140110172'''' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010502____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010502____140110172'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010601____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010601____140110172''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567007,7,0,0,0,'ф.0503121Gт.1стр.093гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1_________140110173'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1_________140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0102______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0102______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0106______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0106______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0202______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0202______140110173''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567008,7,0,0,0,'ф.0503121Gт.1стр.100гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___201_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___201_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___203_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___203_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___207_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___207_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___204_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___204_______140110180''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567009,7,0,0,0,'ф.0503121Gт.1стр.540гр.4 =  ф.0503120Gт.1стр.490гр.6 -  ф.0503120Gт.1стр.490гр.3 +  ф.0503120Gт.1стр.510гр.6 -  ф.0503120Gт.1стр.510гр.3 +  ф.0503120Gт.1стр.530гр.6 -  ф.0503120Gт.1стр.530гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.3 -  ф.0503110Gт.4стр.00000000000000000130404000гр.2 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567010,7,0,0,0,'ф.0503121Gт.1стр.540гр.6 =  ф.0503120Gт.1стр.490гр.8 -  ф.0503120Gт.1стр.490гр.5 +  ф.0503120Gт.1стр.510гр.8 -  ф.0503120Gт.1стр.510гр.5 +  ф.0503120Gт.1стр.530гр.8 -  ф.0503120Gт.1стр.530гр.5 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2 +  ф.0503110Gт.4стр.00000000000000000230406000гр.5 -  ф.0503110Gт.4стр.00000000000000000230406000гр.4 +  ф.0503110Gт.4стр.00000000000000000730406000гр.5 -  ф.0503110Gт.4стр.00000000000000000730406000гр.4',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567011,7,0,0,0,'ф.0503121Gт.1стр.410гр.4 =  ф.0503120Gт.1стр.170гр.6 -  ф.0503120Gт.1стр.170гр.3 +  ф.0503120Gт.1стр.180гр.6 -  ф.0503120Gт.1стр.180гр.3 +  ф.0503120Gт.1стр.190гр.6 -  ф.0503120Gт.1стр.190гр.3 +  ф.0503120Gт.1стр.200гр.6 -  ф.0503120Gт.1стр.200гр.3',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567012,7,0,0,0,'ф.0503121Gт.1стр.390гр.4 =  ф.0503120Gт.1стр.400гр.6 -  ф.0503120Gт.1стр.400гр.3',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567013,7,0,0,0,'ф.0503121Gт.1стр.390гр.5 =  ф.0503120Gт.1стр.400гр.7 -  ф.0503120Gт.1стр.400гр.4',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567014,7,0,0,0,'ф.0503121Gт.1стр.010гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.1гр.2Фильтр:по счетам счета 140110100 +  ф.0503110Gт.3гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.3гр.2Фильтр:по счетам счета 140110100',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567015,7,0,0,0,'ф.0503121Gт.1стр.150гр.4 -  ф.0503121Gт.1стр.280гр.4 =  ф.0503110Gт.2гр.2Фильтр:по счетам счета 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567016,7,0,0,0,'ф.0503121Gт.1стр.310гр.4 =  ф.0503120Gт.1стр.150гр.6 -  ф.0503120Gт.1стр.150гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567017,7,0,0,0,'ф.0503121Gт.1стр.231гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120251'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120251''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567018,7,0,0,0,'ф.0503121Gт.1стр.232гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120252'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120252''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567019,7,0,0,0,'ф.0503121Gт.1стр.233гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120253'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120253''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567020,7,0,0,0,'ф.0503121Gт.1стр.262гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120272'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120272''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567021,7,0,0,0,'ф.0503121Gт.1стр.263гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120273'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120273''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567022,7,0,0,0,'ф.0503121Gт.1стр.290 -  ф.0503121Gт.1стр.110 =  ф.0503110Gт.1гр.5Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.1гр.4Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.1гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.2гр.5Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.2гр.4Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.3гр.5Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.3гр.4Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 040110100, 040120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567023,7,0,0,0,'ф.0503121Gт.1стр.290гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 140110100, 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567024,7,0,0,0,'ф.0503121Gт.1стр.420 =  ф.0503120Gт.1стр.211 -  ф.0503120Gт.1стр.211гр.6 +  ф.0503120Gт.1стр.371 -  ф.0503120Gт.1стр.371гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567025,7,0,0,0,'ф.0503121Gт.1стр.470гр.4 =  ф.0503120Gт.1стр.213гр.7 -  ф.0503120Gт.1стр.213гр.3 +  ф.0503120Gт.1стр.373гр.7 -  ф.0503120Gт.1стр.373гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567026,7,0,0,0,'ф.0503121Gт.1стр.470гр.6 =  ф.0503120Gт.1стр.213 -  ф.0503120Gт.1стр.213гр.5 +  ф.0503120Gт.1стр.373 -  ф.0503120Gт.1стр.373гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567027,7,0,0,0,'ф.0503121Gт.1стр.470 =  ф.0503120Gт.1стр.213 -  ф.0503120Gт.1стр.213гр.6 +  ф.0503120Gт.1стр.373 -  ф.0503120Gт.1стр.373гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567028,7,0,0,0,'ф.0503121Gт.1стр.420гр.4 =  ф.0503120Gт.1стр.211гр.7 -  ф.0503120Gт.1стр.211гр.3 +  ф.0503120Gт.1стр.371гр.7 -  ф.0503120Gт.1стр.371гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567029,7,0,0,0,'ф.0503121Gт.1стр.420гр.6 =  ф.0503120Gт.1стр.211 -  ф.0503120Gт.1стр.211гр.5 +  ф.0503120Gт.1стр.371 -  ф.0503120Gт.1стр.371гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567030,7,0,0,0,'ф.0503121Gт.1стр.410гр.6 =  ф.0503120Gт.1стр.170 -  ф.0503120Gт.1стр.170гр.5 +  ф.0503120Gт.1стр.180 -  ф.0503120Gт.1стр.180гр.5 +  ф.0503120Gт.1стр.190 -  ф.0503120Gт.1стр.190гр.5 +  ф.0503120Gт.1стр.200 -  ф.0503120Gт.1стр.200гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567031,0,0,0,0,'ф.0503121Gт.1стр.460гр.4 =  ф.0503120Gт.1стр.290гр.7 -  ф.0503120Gт.1стр.290гр.3',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567032,0,0,0,0,'ф.0503121Gт.1стр.460 =  ф.0503120Gт.1стр.290 -  ф.0503120Gт.1стр.290гр.6',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567033,7,0,0,0,'ф.0503121Gт.1стр.520гр.4 +  ф.0503121Gт.1стр.530гр.4 =  ф.0503120Gт.1стр.470гр.7 -  ф.0503120Gт.1стр.470гр.3',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567034,7,0,0,0,'ф.0503121Gт.1стр.520 +  ф.0503121Gт.1стр.530 =  ф.0503120Gт.1стр.470 -  ф.0503120Gт.1стр.470гр.6',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567035,7,0,0,0,'ф.0503121Gт.1стр.310 =  ф.0503120Gт.1стр.150 -  ф.0503120Gт.1стр.150гр.6',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567036,7,0,0,0,'ф.0503121Gт.1стр.161гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120211'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120211''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567037,7,0,0,0,'ф.0503121Gт.1стр.162гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120212'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120212''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567038,7,0,0,0,'ф.0503121Gт.1стр.163гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120213'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120213''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567039,7,0,0,0,'ф.0503121Gт.1стр.171гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120221'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120221''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567040,7,0,0,0,'ф.0503121Gт.1стр.172гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120222'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120222''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567041,7,0,0,0,'ф.0503121Gт.1стр.173гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120223'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120223''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567042,7,0,0,0,'ф.0503121Gт.1стр.174гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120224'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120224''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567043,7,0,0,0,'ф.0503121Gт.1стр.175гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120225'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120225''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567044,7,0,0,0,'ф.0503121Gт.1стр.176гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120226'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120226''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567045,7,0,0,0,'ф.0503121Gт.1стр.191гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120231'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120231''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567046,7,0,0,0,'ф.0503121Gт.1стр.192гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120232'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120232''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567047,7,0,0,0,'ф.0503121Gт.1стр.211гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120241'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120241''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567048,7,0,0,0,'ф.0503121Gт.1стр.212гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120242'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120242''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567049,7,0,0,0,'ф.0503121Gт.1стр.241гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120261'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120261''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567050,7,0,0,0,'ф.0503121Gт.1стр.242гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120262'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567051,7,0,0,0,'ф.0503121Gт.1стр.243гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120263'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567052,7,0,0,0,'ф.0503121Gт.1стр.261гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120271'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120271''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567053,7,0,0,0,'ф.0503121Gт.1стр.270гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120290'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120290''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567054,7,0,0,0,'ф.0503121Gт.1стр.370гр.6 =  ф.0503120Gт.1стр.140гр.8 -  ф.0503120Gт.1стр.140гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567055,7,0,0,0,'ф.0503121Gт.1стр.440гр.5 =  ф.0503120Gт.1стр.212гр.7 -  ф.0503120Gт.1стр.212гр.4 +  ф.0503120Gт.1стр.372гр.7 -  ф.0503120Gт.1стр.372гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567056,7,0,0,0,'ф.0503121Gт.1стр.440гр.4 =  ф.0503120Gт.1стр.212гр.6 -  ф.0503120Gт.1стр.212гр.3 +  ф.0503120Gт.1стр.372гр.6 -  ф.0503120Gт.1стр.372гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567057,7,0,0,0,'ф.0503121Gт.1стр.440гр.6 =  ф.0503120Gт.1стр.212гр.8 -  ф.0503120Gт.1стр.212гр.5 +  ф.0503120Gт.1стр.372гр.8 -  ф.0503120Gт.1стр.372гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,567058,7,0,0,0,'ф.0503121Gт.1стр.480гр.4 =  ф.0503120Gт.1стр.230гр.6 -  ф.0503120Gт.1стр.230гр.3 +  ф.0503120Gт.1стр.260гр.6 -  ф.0503120Gт.1стр.260гр.3 +  ф.0503120Gт.1стр.310гр.6 -  ф.0503120Gт.1стр.310гр.3 +  ф.0503120Gт.1стр.320гр.6 -  ф.0503120Gт.1стр.320гр.3 +  ф.0503120Gт.1стр.330гр.6 -  ф.0503120Gт.1стр.330гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,567059,7,0,0,0,'ф.0503121Gт.1стр.480гр.5 =  ф.0503120Gт.1стр.230гр.7 -  ф.0503120Gт.1стр.230гр.4 +  ф.0503120Gт.1стр.260гр.7 -  ф.0503120Gт.1стр.260гр.4 +  ф.0503120Gт.1стр.310гр.7 -  ф.0503120Gт.1стр.310гр.4 +  ф.0503120Gт.1стр.320гр.7 -  ф.0503120Gт.1стр.320гр.4 +  ф.0503120Gт.1стр.330гр.7 -  ф.0503120Gт.1стр.330гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,567060,7,0,0,0,'ф.0503121Gт.1стр.480гр.6 =  ф.0503120Gт.1стр.230гр.8 -  ф.0503120Gт.1стр.230гр.5 +  ф.0503120Gт.1стр.260гр.8 -  ф.0503120Gт.1стр.260гр.5 +  ф.0503120Gт.1стр.310гр.8 -  ф.0503120Gт.1стр.310гр.5 +  ф.0503120Gт.1стр.320гр.8 -  ф.0503120Gт.1стр.320гр.5 +  ф.0503120Gт.1стр.330гр.8 -  ф.0503120Gт.1стр.330гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,567061,7,0,0,0,'ф.0503121Gт.1стр.110гр.4 =  ф.0503120Gт.1стр.624гр.6 -  ф.0503120Gт.1стр.624гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 64
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'- ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'- ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,4,'- ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,4,'+ ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,4,'- ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,4,'+ ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,4,'- ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,4,'+ ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,4,'- ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,4,'+ ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,4,'- ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,16,4,'+ ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,17,4,'- ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,18,4,'+ ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,19,4,'- ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,20,4,'+ ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,21,4,'- ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,22,4,'+ ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,23,4,'- ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,24,4,'+ ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,25,4,'- ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,26,4,'+ ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,27,4,'- ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,28,4,'+ ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,29,4,'- ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,30,4,'- ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,31,4,'+ ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'- ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,4,'- ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,4,'+ ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,4,'- ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,4,'+ ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,4,'- ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'- ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'- ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'- ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,4,'- ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,4,'+ ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,4,'- ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'- ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'- ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'- ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'- ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'- ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,4,'- ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,6,4,'+ ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,7,4,'- ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,8,4,'+ ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,9,4,'- ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,10,4,'+ ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,11,4,'- ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,12,4,'+ ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,13,4,'- ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,14,4,'+ ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,15,4,'- ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,16,4,'+ ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,17,4,'- ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,18,4,'+ ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,19,4,'- ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,20,4,'+ ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,21,4,'- ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,22,4,'+ ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,23,4,'- ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,4,'- ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''''','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','7','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','6','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,5,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,6,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','1','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,5,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,7,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','8','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,8,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','7','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,9,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,10,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,4,'+ ',0,0,'','','','CODE LIKE ''%1401202__''','по счетам счета 140120200','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120263''','{КОД СЧЕТА}=''140120263''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','5','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','6','','2','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,11,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','7','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,12,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','6','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,13,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,14,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,6,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,7,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,4,'+ ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,4,'- ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,6,4,'+ ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,7,4,'- ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,4,'- ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,6,4,'+ ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,7,4,'- ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,8,4,'+ ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,9,4,'- ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','5','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'- ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','4','','3','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,11,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','00000000000000000230406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,11,0,'- ',0,0,'','','','','','','',8,'     ','6','00000000000000000230406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,12,0,'+ ',0,0,'','','','','','','',8,'     ','7','00000000000000000730406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,13,0,'- ',0,0,'','','','','','','',8,'     ','6','00000000000000000730406000','4','0503110G            ','20110101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','400','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','170','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'- ',0,0,'','','','','','','',8,'     ','3','170','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','180','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,5,0,'- ',0,0,'','','','','','','',8,'     ','3','180','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','190','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,7,0,'- ',0,0,'','','','','','','',8,'     ','3','190','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','200','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,9,0,'- ',0,0,'','','','','','','',8,'     ','3','200','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'- ',0,0,'','','','','','','',8,'     ','5','490','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,5,0,'- ',0,0,'','','','','','','',8,'     ','5','510','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','530','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,7,0,'- ',0,0,'','','','','','','',8,'     ','5','530','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','150','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','140','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,3,0,'- ',0,0,'','','','','','','',8,'     ','5','140','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,3,0,'- ',0,0,'','','','','','','',8,'     ','4','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,5,0,'- ',0,0,'','','','','','','',8,'     ','4','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,3,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,5,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,3,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,5,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,3,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,5,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,7,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,9,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,10,0,'+ ',0,0,'','','','','','','',8,'     ','6','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,11,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,3,0,'- ',0,0,'','','','','','','',8,'     ','4','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,5,0,'- ',0,0,'','','','','','','',8,'     ','4','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,7,0,'- ',0,0,'','','','','','','',8,'     ','4','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,9,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,11,0,'- ',0,0,'','','','','','','',8,'     ','4','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,3,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,5,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,7,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,9,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,11,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','624','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,3,0,'- ',0,0,'','','','','','','',8,'     ','3','624','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,0,'+ ',0,0,'','','','','','','',8,'     ','','150','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','290','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'- ',0,0,'','','','','','','',8,'     ','3','290','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,3,0,'+ ',0,0,'','','','','','','',8,'     ','','470','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,4,0,'- ',0,0,'','','','','','','',8,'     ','6','470','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','','290','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'- ',0,0,'','','','','','','',8,'     ','6','290','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','470','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,4,0,'- ',0,0,'','','','','','','',8,'     ','3','470','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'+ ',0,0,'','','','','','','',8,'     ','','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,0,'- ',0,0,'','','','','','','',8,'     ','6','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,0,'+ ',0,0,'','','','','','','',8,'     ','','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,5,0,'- ',0,0,'','','','','','','',8,'     ','6','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,0,'+ ',0,0,'','','','','','','',8,'     ','','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,0,'- ',0,0,'','','','','','','',8,'     ','6','213','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,0,'+ ',0,0,'','','','','','','',8,'     ','','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,0,'- ',0,0,'','','','','','','',8,'     ','6','373','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,5,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,0,'+ ',0,0,'','','','','','','',8,'     ','','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,5,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','','170','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'- ',0,0,'','','','','','','',8,'     ','5','170','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,4,0,'+ ',0,0,'','','','','','','',8,'     ','','180','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,5,0,'- ',0,0,'','','','','','','',8,'     ','5','180','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,6,0,'+ ',0,0,'','','','','','','',8,'     ','','190','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,7,0,'- ',0,0,'','','','','','','',8,'     ','5','190','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,8,0,'+ ',0,0,'','','','','','','',8,'     ','','200','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,9,0,'- ',0,0,'','','','','','','',8,'     ','5','200','1','0503120G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,0,'+ ',0,0,'','','','','','','',8,'     ','','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','161','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','162','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','191','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','174','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','172','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','171','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','163','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','370','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','270','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','261','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','243','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','242','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','241','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','212','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','211','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','192','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','231','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'- ',0,0,'','','','','','','',8,'     ','4','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','263','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','262','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','233','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','232','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,0,'- ',0,0,'','','','','','','',8,'     ','','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','093','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','390','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','390','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','092','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','091','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','100','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','062','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','040','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','061','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','030','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 353
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'1423_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'1423_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 64
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1423_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1423_1' , 'Проверка:0503120G, 0503121G,0503110G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:05:09:600PM)
-- Выгружены следующие группы междокументных КС:
-- 1427_1 - Проверка: 0503130G - 0503169G (БД, БК) (32 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1427_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1427_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567333,7,0,0,0,'ф.0503130Gт.1стр.230гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120500000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120500000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120500000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567334,7,0,0,0,'ф.0503130Gт.1стр.260гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120600000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120600000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120600000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567335,7,0,0,0,'ф.0503130Gт.1стр.310гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120800000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120800000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120800000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567336,7,0,0,0,'ф.0503130Gт.1стр.320гр.6 =  ф.0503169G_БДт.1стр.00000000000000000120900000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000120900000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000120900000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567337,7,0,0,0,'ф.0503130Gт.1стр.331гр.6 =  ф.0503169G_БДт.1стр.00000000000000000121001000гр.4 +  ф.0503169G_БДт.2стр.00000000000000000121001000гр.4 +  ф.0503169G_БДт.3стр.00000000000000000121001000гр.4',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567338,7,0,0,0,'ф.0503130Gт.1стр.534гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130404000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130404000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130404000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567339,7,0,0,0,'ф.0503130Gт.1стр.490гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130200000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130200000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130200000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567340,7,0,0,0,'ф.0503130Gт.1стр.533гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130403000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130403000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130403000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567341,7,0,0,0,'ф.0503130Gт.1стр.510гр.6 =  ф.0503169G_БКт.2стр.00000000000000000130300000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130300000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130300000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567342,7,0,0,0,'ф.0503130Gт.1стр.532гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130402000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130402000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130402000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567343,7,0,0,0,'ф.0503130Gт.1стр.511гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130301000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130301000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130301000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567344,7,0,0,0,'ф.0503130Gт.1стр.512гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130302000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130306000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130302000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130306000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130302000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130306000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567345,7,0,0,0,'ф.0503130Gт.1стр.513гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130303000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130303000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130303000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567346,7,0,0,0,'ф.0503130Gт.1стр.514гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130304000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130304000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130304000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567347,7,0,0,0,'ф.0503130Gт.1стр.515гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130305000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130312000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130313000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130305000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130312000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130313000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130305000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130312000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130313000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567348,7,0,0,0,'ф.0503130Gт.1стр.230гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120500000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120500000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120500000гр.2',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567349,7,0,0,0,'ф.0503130Gт.1стр.260гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120600000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120600000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120600000гр.2',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567350,7,0,0,0,'ф.0503130Gт.1стр.310гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120800000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120800000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120800000гр.2',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567351,7,0,0,0,'ф.0503130Gт.1стр.320гр.3 =  ф.0503169G_БДт.1стр.00000000000000000120900000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000120900000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000120900000гр.2',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567352,7,0,0,0,'ф.0503130Gт.1стр.331гр.3 =  ф.0503169G_БДт.1стр.00000000000000000121001000гр.2 +  ф.0503169G_БДт.2стр.00000000000000000121001000гр.2 +  ф.0503169G_БДт.3стр.00000000000000000121001000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567353,7,0,0,0,'ф.0503130Gт.1стр.490гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130200000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130200000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130200000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567354,7,0,0,0,'ф.0503130Gт.1стр.533гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130403000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130403000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130403000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567355,7,0,0,0,'ф.0503130Gт.1стр.510гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130300000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130300000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130300000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567356,7,0,0,0,'ф.0503130Gт.1стр.532гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130402000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130402000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130402000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567357,7,0,0,0,'ф.0503130Gт.1стр.511гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130301000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130301000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130301000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567358,7,0,0,0,'ф.0503130Gт.1стр.512гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130302000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130306000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130302000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130306000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130302000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130306000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567359,7,0,0,0,'ф.0503130Gт.1стр.513гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130303000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130303000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130303000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567360,7,0,0,0,'ф.0503130Gт.1стр.514гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130304000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130304000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130304000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567361,7,0,0,0,'ф.0503130Gт.1стр.515гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130305000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130312000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130313000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130305000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130312000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130313000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130305000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130312000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130313000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567362,7,0,0,0,'ф.0503130Gт.1стр.516гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130307000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130308000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130309000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130310000гр.2 +  ф.0503169G_БКт.1стр.00000000000000000130311000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130307000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130308000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130309000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130310000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130311000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130307000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130308000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130309000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130310000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130311000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567363,7,0,0,0,'ф.0503130Gт.1стр.534гр.3 =  ф.0503169G_БКт.1стр.00000000000000000130404000гр.2 +  ф.0503169G_БКт.2стр.00000000000000000130404000гр.2 +  ф.0503169G_БКт.3стр.00000000000000000130404000гр.2',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567364,7,0,0,0,'ф.0503130Gт.1стр.516гр.6 =  ф.0503169G_БКт.1стр.00000000000000000130307000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130308000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130309000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130310000гр.4 +  ф.0503169G_БКт.1стр.00000000000000000130311000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130307000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130308000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130309000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130310000гр.4 +  ф.0503169G_БКт.2стр.00000000000000000130311000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130307000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130309000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130309000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130310000гр.4 +  ф.0503169G_БКт.3стр.00000000000000000130311000гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','4','','1','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','8','','2','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','6','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,3,'+ ',0,0,'','','00000000000000000120500000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,3,'+ ',0,0,'','','00000000000000000120600000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,3,'+ ',0,0,'','','00000000000000000120800000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,3,'+ ',0,0,'','','00000000000000000120900000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,3,'+ ',0,0,'','','00000000000000000121001000','','','','',8,'     ','4','','3','0503169G_БД         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,6,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','4','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,5,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,6,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','1','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,7,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,8,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,9,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,10,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,11,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,6,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,7,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,7,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','8','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,7,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,8,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,9,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,10,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,11,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,4,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,5,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','2','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,4,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,6,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,7,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,12,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,13,3,'+ ',0,0,'','','00000000000000000130308000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,14,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,15,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,16,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,3,'+ ',0,0,'','','00000000000000000130200000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,3,'+ ',0,0,'','','00000000000000000130403000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,3,'+ ',0,0,'','','00000000000000000130300000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,3,'+ ',0,0,'','','00000000000000000130402000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,3,'+ ',0,0,'','','00000000000000000130301000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,3,'+ ',0,0,'','','00000000000000000130302000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,3,'+ ',0,0,'','','00000000000000000130306000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,3,'+ ',0,0,'','','00000000000000000130303000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,8,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,9,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,10,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,8,3,'+ ',0,0,'','','00000000000000000130305000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,9,3,'+ ',0,0,'','','00000000000000000130312000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,10,3,'+ ',0,0,'','','00000000000000000130313000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,3,'+ ',0,0,'','','00000000000000000130304000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,3,'+ ',0,0,'','','00000000000000000130404000','','','','',8,'     ','4','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,12,3,'+ ',0,0,'','','00000000000000000130307000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,13,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,14,3,'+ ',0,0,'','','00000000000000000130309000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,15,3,'+ ',0,0,'','','00000000000000000130310000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,16,3,'+ ',0,0,'','','00000000000000000130311000','','','','',8,'     ','6','','3','0503169G_БК         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','516','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','515','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','516','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','230','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','515','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','514','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','513','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','512','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','511','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','532','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','533','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','534','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','331','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','534','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','514','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','513','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','512','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','511','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','532','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','510','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','533','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','490','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','331','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','310','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','260','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 170
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1427_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1427_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 32
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1427_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1427_1' , 'Проверка: 0503130G - 0503169G (БД, БК)', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:05:16:663PM)
-- Выгружены следующие группы междокументных КС:
-- 1438_1 - Проверка: 0503130, 0503173G и 0503130G прошлого года (6 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1438_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1438_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567366,7,0,0,0,'ф.0503130Gт.1гр.6[12м2013г] -  ф.0503130Gт.1гр.3 =  -  ф.0503173G_Бт.1гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567367,7,0,0,0,'ф.0503130Gт.1гр.7[12м2013г] -  ф.0503130Gт.1гр.5 =  -  ф.0503173G_СВт.1гр.5',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567368,7,0,0,0,'ф.0503130Gт.1гр.3 =  ф.0503173G_Бт.1гр.4',1,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567369,7,0,0,0,'ф.0503130Gт.1гр.4 =  ф.0503173G_СВт.1гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567370,7,0,0,0,'ф.0503130Gт.1гр.6[12м2013г] =  ф.0503173G_Бт.1гр.3',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567371,7,0,0,0,'ф.0503130Gт.1гр.7[12м2013г] =  ф.0503173G_СВт.1гр.3',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'- ',0,0,'','','','CODE not in (''180'',''181'',''182'',''183'',''190'',''191'',''192'',''193'',''200'',''201'',''202'',''203'',''600'',''610'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','5','','1','0503173G_Б          ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','code not in (''610'',''800'')','','CODE','',8,'     ','4','','1','0503173G_Б          ','20121231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','CODE not in (''180'',''181'',''182'',''183'',''190'',''191'',''192'',''193'',''200'',''201'',''202'',''203'',''600'',''610'',''690'',''800'',''900'',''410'',''400'',''512'',''515'',''516'')','','CODE','',8,'     ','3','','1','0503173G_Б          ','20121231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','code not in (''610'',''800'')','','CODE','',8,'     ','4','','1','0503173G_СВ         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','CODE not in (''180'',''181'',''182'',''183'',''190'',''191'',''192'',''193'',''200'',''201'',''202'',''203'',''600'',''610'',''690'',''800'',''900'',''410'',''400'',''512'',''515'',''516'')','','CODE','',8,'     ','3','','1','0503173G_СВ         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'- ',0,0,'','','','CODE not in (''180'',''181'',''182'',''183'',''190'',''191'',''192'',''193'',''200'',''201'',''202'',''203'',''600'',''610'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','5','','1','0503173G_СВ         ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,4,'+ ',12,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','7','','1','0503130G            ','20130101',2013,'',0,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,4,'+ ',12,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','6','','1','0503130G            ','20130101',2013,'',0,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,4,'+ ',12,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'',''512'',''515'',''516'')','','CODE','',8,'     ','6','','1','0503130G            ','20130101',2013,'',0,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,4,'+ ',12,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'',''512'',''515'',''516'')','','CODE','',8,'     ','7','','1','0503130G            ','20130101',2013,'',0,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'- ',0,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','3','','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'- ',0,0,'','','','CODE not in (''600'',''690'',''800'',''900'',''410'',''400'')','','CODE','',8,'     ','5','','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,4,'+ ',0,0,'','','','1=1','','CODE','',8,'     ','3','','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,4,'+ ',0,0,'','','','1=1','','CODE','',8,'     ','4','','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 14
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1438_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1438_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1438_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1438_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1438_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1438_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 6
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1438_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1438_1' , 'Проверка: 0503130, 0503173G и 0503130G прошлого года', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:05:23:723PM)
-- Выгружены следующие группы междокументных КС:
-- 1440_1 - Проверка: 0503130G - 0503171G (12 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1440_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1440_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567373,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120423000 =  ф.0503130Gт.1стр.211гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567374,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220421000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220422000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220421000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220422000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120423000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220423000 =  ф.0503130Gт.1стр.211гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567375,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120433000 =  ф.0503130Gт.1стр.212гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567376,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220431000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220432000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220433000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220431000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220432000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120433000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220433000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120434000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220434000 =  ф.0503130Gт.1стр.212гр.8',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567377,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120453000 =  ф.0503130Gт.1стр.213гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567378,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220451000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220452000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 220453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220451000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220452000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 120453000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 220453000 =  ф.0503130Gт.1стр.213гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567379,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121521000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121522000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121523000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121521000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121522000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121523000 =  ф.0503130Gт.1стр.371гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567380,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121521000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121522000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121523000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121521000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121522000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121523000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221521000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221522000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221523000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221521000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221522000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221523000 =  ф.0503130Gт.1стр.371гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567381,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121531000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121532000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121533000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121531000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121532000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121533000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121534000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121534000 =  ф.0503130Gт.1стр.372гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567382,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121531000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121532000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121533000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121531000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121532000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121533000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121534000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121534000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221531000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221532000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221533000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221531000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221532000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221533000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221534000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221534000 =  ф.0503130Gт.1стр.372гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567383,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121551000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121552000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121553000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121551000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121552000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121553000 =  ф.0503130Gт.1стр.373гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567384,7,0,0,0,'ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121551000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121552000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 121553000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121551000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121552000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 121553000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221551000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221552000 +  ф.0503171Gт.1гр.2Фильтр:Остаток по счету 221553000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221551000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221552000 +  ф.0503171Gт.2гр.2Фильтр:Остаток по счету 221553000 =  ф.0503130Gт.1стр.373гр.8',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 12
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220421000''','Остаток по счету 220421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220422000''','Остаток по счету 220422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220423000''','Остаток по счету 220423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''  and substring(CODE,27,2)=''  ''','Остаток по счету 120433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220431000''','Остаток по счету 220431000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220432000''','Остаток по счету 220432000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000'' and substring(CODE,27,2)=''  ''','Остаток по счету 120433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220433000''  and substring(CODE,27,2)=''  ''','Остаток по счету 220433000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220434000''','Остаток по счету 220434000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220451000''','Остаток по счету 220451000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220452000''','Остаток по счету 220452000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220453000''','Остаток по счету 220453000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121521000''','Остаток по счету 121521000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121522000''','Остаток по счету 121522000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121523000''','Остаток по счету 121523000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121521000''','Остаток по счету 121521000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121522000''','Остаток по счету 121522000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121523000''','Остаток по счету 121523000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221521000''','Остаток по счету 221521000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221522000''','Остаток по счету 221522000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221523000''','Остаток по счету 221523000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121531000''','Остаток по счету 121531000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121532000''','Остаток по счету 121532000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121533000''','Остаток по счету 121533000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121531000''','Остаток по счету 121531000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121532000''','Остаток по счету 121532000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121533000''','Остаток по счету 121533000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121534000''','Остаток по счету 121534000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121534000''','Остаток по счету 121534000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221531000''','Остаток по счету 221531000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221532000''','Остаток по счету 221532000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221533000''','Остаток по счету 221533000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121551000''','Остаток по счету 121551000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121552000''','Остаток по счету 121552000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121553000''','Остаток по счету 121553000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121551000''','Остаток по счету 121551000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121552000''','Остаток по счету 121552000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121553000''','Остаток по счету 121553000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221551000''','Остаток по счету 221551000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221552000''','Остаток по счету 221552000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221553000''','Остаток по счету 221553000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,15,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221534000''','Остаток по счету 221534000','','',8,'     ','4','','1','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,16,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221534000''','Остаток по счету 221534000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221551000''','Остаток по счету 221551000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221552000''','Остаток по счету 221552000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221553000''','Остаток по счету 221553000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121551000''','Остаток по счету 121551000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121552000''','Остаток по счету 121552000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121553000''','Остаток по счету 121553000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121551000''','Остаток по счету 121551000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121552000''','Остаток по счету 121552000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121553000''','Остаток по счету 121553000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221531000''','Остаток по счету 221531000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,13,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221532000''','Остаток по счету 221532000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,14,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221533000''','Остаток по счету 221533000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121534000''','Остаток по счету 121534000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121534000''','Остаток по счету 121534000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121531000''','Остаток по счету 121531000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121532000''','Остаток по счету 121532000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121533000''','Остаток по счету 121533000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121531000''','Остаток по счету 121531000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121532000''','Остаток по счету 121532000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121533000''','Остаток по счету 121533000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221521000''','Остаток по счету 221521000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221522000''','Остаток по счету 221522000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000221523000''','Остаток по счету 221523000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121521000''','Остаток по счету 121521000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121522000''','Остаток по счету 121522000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121523000''','Остаток по счету 121523000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121521000''','Остаток по счету 121521000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121522000''','Остаток по счету 121522000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000121523000''','Остаток по счету 121523000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220451000''','Остаток по счету 220451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220452000''','Остаток по счету 220452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220453000''','Остаток по счету 220453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120451000''','Остаток по счету 120451000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120452000''','Остаток по счету 120452000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120453000''','Остаток по счету 120453000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220431000''','Остаток по счету 220431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220432000''','Остаток по счету 220432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,13,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''  and substring(CODE,27,2)=''  ''','Остаток по счету 120433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,14,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220433000''  and substring(CODE,27,2)=''  ''','Остаток по счету 220433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,15,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120434000''','Остаток по счету 120434000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,16,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220434000''','Остаток по счету 220434000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120431000''','Остаток по счету 120431000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120432000''','Остаток по счету 120432000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120433000''  and substring(CODE,27,2)=''  ''','Остаток по счету 120433000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120421000''','Остаток по счету 120421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220421000''','Остаток по счету 220421000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120422000''','Остаток по счету 120422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,10,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220422000''','Остаток по счету 220422000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,11,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000120423000''','Остаток по счету 120423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,12,4,'+ ',0,0,'','','','SUBSTRING(CODE,4,23)=''00000000000000220423000''','Остаток по счету 220423000','','',8,'     ','6','','2','0503171G            ','20121231',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,17,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,9,0,'+ ',0,0,'','','','','','','',8,'     ','6','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,13,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,17,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 131
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1440_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1440_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 12
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1440_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1440_1' , 'Проверка: 0503130G - 0503171G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:35:30:683AM)
-- Выгружены следующие группы междокументных КС:
-- 1445_1 - Проверка 0503830G c  0503730G прошлого года (7 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1445_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1445_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567979,7,0,0,0,'ф.0503830Gт.1гр.3 =  ф.0503730G_BUт.1гр.7[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567980,7,0,0,0,'ф.0503830Gт.1гр.4 =  ф.0503730G_BUт.1гр.8[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567981,7,0,0,0,'ф.0503830Gт.1гр.5 =  ф.0503730G_BUт.1гр.9[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567982,7,0,0,0,'ф.0503830Gт.1гр.6 =  ф.0503730G_BUт.1гр.10[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567983,7,0,0,0,'ф.0503830Gт.2гр.4 =  ф.0503730G_BUт.2гр.7[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567984,7,0,0,0,'ф.0503830Gт.2гр.5 =  ф.0503730G_BUт.2гр.8[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567985,7,0,0,0,'ф.0503830Gт.2гр.6 =  ф.0503730G_BUт.2гр.9[12м2013г]',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',3,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 7
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',12,0,'','','','','','','',8,'     ','7','','1','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',12,0,'','','','','','','',8,'     ','8','','1','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',12,0,'','','','','','','',8,'     ','9','','1','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',12,0,'','','','','','','',8,'     ','10','','1','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',12,0,'','','','','','','',8,'     ','7','','2','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',12,0,'','','','','','','',8,'     ','8','','2','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',12,0,'','','','','','','',8,'     ','9','','2','0503730G_BU         ','20121231',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','','1','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','','1','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','1','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','1','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','','2','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','','2','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','','2','0503830G            ','20130101',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 14
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1445_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1445_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 7
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1445_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1445_1' , 'Проверка 0503830G c  0503730G прошлого года', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:35:38:370AM)
-- Выгружены следующие группы междокументных КС:
-- 1459_1 - Проверка 0503769M - 0503730G (71 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '1459_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '1459_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567987,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567988,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567989,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567990,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567991,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000 +  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567992,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000 +  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567993,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000 +  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567994,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000 +  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567995,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567996,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567997,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567998,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.9 =  ф.0503769G_Dт.1гр.4Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567999,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.9 =  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,568000,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.9 =  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,568001,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,568002,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,568003,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030200000 +  ф.0503769G_Kт.1гр.4Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,568004,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030300000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,568005,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.7 =  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,568006,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.8 =  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000 +  ф.0503769G_Dт.1гр.4Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,568007,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,568008,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000 +  ф.0503769G_Kт.1гр.4Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,568009,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,568010,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000 +  ф.0503769G_Kт.1гр.4Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,568011,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,568012,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,568013,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,568014,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,568015,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000 +  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,568016,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000 +  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,568017,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000 +  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,568018,7,0,0,0,'ф.0503730G_BUт.1стр.230гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020500000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,568019,7,0,0,0,'ф.0503730G_BUт.1стр.260гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020600000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,568020,7,0,0,0,'ф.0503730G_BUт.1стр.310гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020800000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,568021,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.5 =  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,568022,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.5 =  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,568023,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.5 =  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,568024,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,568025,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,568026,7,0,0,0,'ф.0503730G_BUт.1стр.490гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030200000 +  ф.0503769G_Kт.1гр.2Фильтр:030200000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,568027,7,0,0,0,'ф.0503730G_BUт.1стр.510гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030300000 +  ф.0503769G_Kт.1гр.2Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,568028,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.3 =  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,568029,7,0,0,0,'ф.0503730G_BUт.1стр.331гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000 +  ф.0503769G_Dт.1гр.2Фильтр:021001000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,568030,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,568031,7,0,0,0,'ф.0503730G_BUт.1стр.532гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000 +  ф.0503769G_Kт.1гр.2Фильтр:030402000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,568032,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,568033,7,0,0,0,'ф.0503730G_BUт.1стр.533гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000 +  ф.0503769G_Kт.1гр.2Фильтр:030403000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,568034,7,0,0,0,'ф.0503730G_BUт.1стр.320гр.4 =  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000 +  ф.0503769G_Dт.1гр.2Фильтр:020900000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,568035,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,568036,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000 +  ф.0503769G_Kт.1гр.2Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,568037,7,0,0,0,'ф.0503730G_BUт.1стр.511гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030301000 +  ф.0503769G_Kт.1гр.4Фильтр:030301000 +  ф.0503769G_Kт.1гр.4Фильтр:030301000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,568038,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,568039,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030302000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000 +  ф.0503769G_Kт.1гр.2Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,568040,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,568041,7,0,0,0,'ф.0503730G_BUт.1стр.512гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030302000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000 +  ф.0503769G_Kт.1гр.4Фильтр:030306000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,568042,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,568043,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000 +  ф.0503769G_Kт.1гр.2Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,568044,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030300000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,568045,7,0,0,0,'ф.0503730G_BUт.1стр.513гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030303000 +  ф.0503769G_Kт.1гр.4Фильтр:030303000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,568046,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,568047,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000 +  ф.0503769G_Kт.1гр.2Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,568048,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,568049,7,0,0,0,'ф.0503730G_BUт.1стр.514гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000 +  ф.0503769G_Kт.1гр.4Фильтр:030304000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,568050,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (65,1,568051,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030305000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030312000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000 +  ф.0503769G_Kт.1гр.2Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (66,1,568052,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (67,1,568053,7,0,0,0,'ф.0503730G_BUт.1стр.515гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030305000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030312000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000 +  ф.0503769G_Kт.1гр.4Фильтр:030313000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (68,1,568054,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.3 =  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (69,1,568055,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.4 =  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030307000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030308000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030309000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030310000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000 +  ф.0503769G_Kт.1гр.2Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (70,1,568056,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.7 =  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (71,1,568057,7,0,0,0,'ф.0503730G_BUт.1стр.516гр.8 =  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030307000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030308000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030309000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030310000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000 +  ф.0503769G_Kт.1гр.4Фильтр:030311000',0,0,1,'20141230','','','','',NULL,'','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 71
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','4','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20500000''','020500000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20600000''','020600000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20800000''','020800000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''21001000''','021001000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''20900000''','020900000','','',8,'     ','2','','1','0503769G_D          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30302000''','030302000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30306000''','030306000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30301000''','030301000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30303000''','030303000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30307000''','030307000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30308000''','030308000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,8,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,9,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,10,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30309000''','030309000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,11,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,12,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,13,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30310000''','030310000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,14,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,15,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,16,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30311000''','030311000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30305000''','030305000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,5,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30312000''','030312000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,6,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,7,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30313000''','030313000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30304000''','030304000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','2','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30402000''','030402000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30403000''','030403000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#3',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#2',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#4',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#7',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30200000''','030200000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#5',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,4,'+ ',0,0,'','','','RIGHT(RTRIM(CODE),8)=''30300000''','030300000','','',8,'     ','4','','1','0503769G_K          ','20121231',NULL,'#6',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','9','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','310','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','260','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','490','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','510','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','331','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','533','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','532','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (67,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (71,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (70,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (69,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (68,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','516','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (66,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','515','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','514','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','513','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','512','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','511','1','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 301
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (65,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (66,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (67,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (68,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (69,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (70,'1459_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (71,'1459_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 71
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '1459_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '1459_1' , 'Проверка 0503769M - 0503730G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:03:23:957PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_1 - Проверка: 0503121G -0503168G_БД (4 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567063,7,0,0,0,'ф.0503121Gт.1стр.320гр.4 =  ф.0503168G_БДт.1стр.010гр.5 +  ф.0503168G_БДт.1стр.080гр.5 +  ф.0503168G_БДт.1стр.070гр.5 +  ф.0503168G_БДт.1стр.320гр.5 +  ф.0503168G_БДт.1стр.360гр.5 +  ф.0503168G_БДт.1стр.380гр.5 -  ф.0503168G_БДт.1стр.010гр.6 -  ф.0503168G_БДт.1стр.070гр.6 -  ф.0503168G_БДт.1стр.080гр.6 -  ф.0503168G_БДт.1стр.320гр.6 -  ф.0503168G_БДт.1стр.360гр.6 -  ф.0503168G_БДт.1стр.380гр.6 -  ф.0503168G_БДт.1стр.050гр.6 -  ф.0503168G_БДт.1стр.330гр.6 -  ф.0503168G_БДт.1стр.370гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567064,7,0,0,0,'ф.0503121Gт.1стр.330гр.4 =  ф.0503168G_БДт.1стр.110гр.5 +  ф.0503168G_БДт.1стр.130гр.5 +  ф.0503168G_БДт.1стр.420гр.5 -  ф.0503168G_БДт.1стр.110гр.6 -  ф.0503168G_БДт.1стр.130гр.6 -  ф.0503168G_БДт.1стр.420гр.6 -  ф.0503168G_БДт.1стр.120гр.6 -  ф.0503168G_БДт.1стр.430гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567065,7,0,0,0,'ф.0503121Gт.1стр.350гр.4 =  ф.0503168G_БДт.1стр.150гр.5 +  ф.0503168G_БДт.1стр.170гр.5 +  ф.0503168G_БДт.1стр.440гр.5 -  ф.0503168G_БДт.1стр.150гр.6 -  ф.0503168G_БДт.1стр.170гр.6 -  ф.0503168G_БДт.1стр.440гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567066,7,0,0,0,'ф.0503121Gт.1стр.360гр.4 =  ф.0503168G_БДт.1стр.190гр.5 +  ф.0503168G_БДт.1стр.450гр.5 -  ф.0503168G_БДт.1стр.190гр.6 -  ф.0503168G_БДт.1стр.450гр.6 +  ф.0503168G_БДт.1стр.230гр.5 -  ф.0503168G_БДт.1стр.230гр.6 +  ф.0503168G_БДт.1стр.250гр.5 -  ф.0503168G_БДт.1стр.250гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','080','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,0,'- ',0,0,'','','','','','','',8,'     ','6','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,0,'- ',0,0,'','','','','','','',8,'     ','6','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,0,'- ',0,0,'','','','','','','',8,'     ','6','080','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,0,'- ',0,0,'','','','','','','',8,'     ','6','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,0,'- ',0,0,'','','','','','','',8,'     ','6','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,0,'- ',0,0,'','','','','','','',8,'     ','6','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,0,'- ',0,0,'','','','','','','',8,'     ','6','050','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,0,'- ',0,0,'','','','','','','',8,'     ','6','330','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,16,0,'- ',0,0,'','','','','','','',8,'     ','6','370','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'- ',0,0,'','','','','','','',8,'     ','6','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'- ',0,0,'','','','','','','',8,'     ','6','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,0,'- ',0,0,'','','','','','','',8,'     ','6','120','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,0,'- ',0,0,'','','','','','','',8,'     ','6','430','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'- ',0,0,'','','','','','','',8,'     ','6','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'- ',0,0,'','','','','','','',8,'     ','6','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,0,'- ',0,0,'','','','','','','',8,'     ','6','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','250','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,0,'- ',0,0,'','','','','','','',8,'     ','6','250','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'- ',0,0,'','','','','','','',8,'     ','6','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,0,'- ',0,0,'','','','','','','',8,'     ','6','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,0,'- ',0,0,'','','','','','','',8,'     ','6','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','360','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','350','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','330','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 41
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_1' , 'Проверка: 0503121G -0503168G_БД', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:20:770PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_10 - Проверка: 0503130G - 0503178G (Б, СВ) (18 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_10' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_10'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567422,7,0,0,0,'ф.0503178G_СВт.3стр.88888888888888888888888888888888888гр.3 +  ф.0503178G_СВт.3стр.88888888888888888888888888888888888гр.4 =  ф.0503130Gт.1стр.171гр.5 +  ф.0503130Gт.1стр.172гр.5 +  ф.0503130Gт.1стр.173гр.5 +  ф.0503130Gт.1стр.174гр.5 +  ф.0503130Gт.1стр.175гр.5 +  ф.0503130Gт.1стр.176гр.5 +  ф.0503130Gт.1стр.179гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567423,7,0,0,0,'ф.0503178G_СВт.3стр.88888888888888888888888888888888888гр.5 +  ф.0503178G_СВт.3стр.88888888888888888888888888888888888гр.6 =  ф.0503130Gт.1стр.171гр.7 +  ф.0503130Gт.1стр.172гр.7 +  ф.0503130Gт.1стр.173гр.7 +  ф.0503130Gт.1стр.175гр.7 +  ф.0503130Gт.1стр.176гр.7 +  ф.0503130Gт.1стр.179гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567424,7,0,0,0,'ф.0503178G_Бт.3стр.88888888888888888888888888888888888гр.5 +  ф.0503178G_Бт.3стр.88888888888888888888888888888888888гр.6 =  ф.0503130Gт.1стр.172гр.6 +  ф.0503130Gт.1стр.173гр.6 +  ф.0503130Gт.1стр.174гр.6 +  ф.0503130Gт.1стр.175гр.6 +  ф.0503130Gт.1стр.176гр.6 +  ф.0503130Gт.1стр.179гр.6 +  ф.0503130Gт.1стр.179гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567425,7,0,0,0,'ф.0503178G_Бт.3стр.88888888888888888888888888888888888гр.3 +  ф.0503178G_Бт.3стр.88888888888888888888888888888888888гр.4 =  ф.0503130Gт.1стр.171гр.3 +  ф.0503130Gт.1стр.172гр.3 +  ф.0503130Gт.1стр.173гр.3 +  ф.0503130Gт.1стр.174гр.3 +  ф.0503130Gт.1стр.175гр.3 +  ф.0503130Gт.1стр.176гр.3 +  ф.0503130Gт.1стр.179гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567426,7,0,0,0,'ф.0503178G_СВт.1стр.88888888888888888888888888888888888гр.3 +  ф.0503178G_СВт.1стр.88888888888888888888888888888888888гр.4 =  ф.0503130Gт.1стр.173гр.4 +  ф.0503130Gт.1стр.174гр.4 +  ф.0503130Gт.1стр.175гр.4 +  ф.0503130Gт.1стр.176гр.4 +  ф.0503130Gт.1стр.179гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567427,7,0,0,0,'ф.0503178G_СВт.1стр.88888888888888888888888888888888888гр.5 +  ф.0503178G_СВт.1стр.88888888888888888888888888888888888гр.6 =  ф.0503130Gт.1стр.173гр.7 +  ф.0503130Gт.1стр.174гр.7 +  ф.0503130Gт.1стр.175гр.7 +  ф.0503130Gт.1стр.176гр.7 +  ф.0503130Gт.1стр.179гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567428,7,0,0,0,'ф.0503178G_Бт.1стр.88888888888888888888888888888888888гр.5 +  ф.0503178G_Бт.1стр.88888888888888888888888888888888888гр.6 =  ф.0503130Gт.1стр.173гр.6 +  ф.0503130Gт.1стр.174гр.6 +  ф.0503130Gт.1стр.175гр.6 +  ф.0503130Gт.1стр.176гр.6 +  ф.0503130Gт.1стр.179гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567429,7,0,0,0,'ф.0503178G_Бт.1стр.88888888888888888888888888888888888гр.3 +  ф.0503178G_Бт.1стр.88888888888888888888888888888888888гр.4 =  ф.0503130Gт.1стр.173гр.3 +  ф.0503130Gт.1стр.174гр.3 +  ф.0503130Gт.1стр.175гр.3 +  ф.0503130Gт.1стр.176гр.3 +  ф.0503130Gт.1стр.179гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567430,7,0,0,0,'ф.0503178G_Бт.1гр.3Фильтр:120121000 +  ф.0503178G_Бт.1гр.4Фильтр:120121000 =  ф.0503130Gт.1стр.173гр.3',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567431,7,0,0,0,'ф.0503178G_Бт.1гр.5Фильтр:120121000 +  ф.0503178G_Бт.1гр.6Фильтр:120121000 =  ф.0503130Gт.1стр.173гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567432,7,0,0,0,'ф.0503178G_Бт.1гр.3Фильтр:120122000 +  ф.0503178G_Бт.1гр.4Фильтр:120122000 =  ф.0503130Gт.1стр.179гр.3',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567433,7,0,0,0,'ф.0503178G_Бт.1гр.5Фильтр:120122000 +  ф.0503178G_Бт.1гр.6Фильтр:120122000 =  ф.0503130Gт.1стр.179гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567434,7,0,0,0,'ф.0503178G_Бт.1гр.3Фильтр:120126000 +  ф.0503178G_Бт.1гр.4Фильтр:120126000 =  ф.0503130Gт.1стр.175гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567435,7,0,0,0,'ф.0503178G_Бт.1гр.5Фильтр:120126000 +  ф.0503178G_Бт.1гр.6Фильтр:120126000 =  ф.0503130Gт.1стр.175гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567436,7,0,0,0,'ф.0503178G_Бт.1гр.3Фильтр:120127000 +  ф.0503178G_Бт.1гр.4Фильтр:120127000 =  ф.0503130Gт.1стр.176гр.3',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567437,7,0,0,0,'ф.0503178G_Бт.1гр.5Фильтр:120127000 +  ф.0503178G_Бт.1гр.6Фильтр:120126000 =  ф.0503130Gт.1стр.176гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567438,7,0,0,0,'ф.0503178G_Бт.1гр.3Фильтр:120123000 +  ф.0503178G_Бт.1гр.4Фильтр:120123000 =  ф.0503130Gт.1стр.174гр.3',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567439,7,0,0,0,'ф.0503178G_Бт.1гр.5Фильтр:120123000 +  ф.0503178G_Бт.1гр.6Фильтр:120126000 =  ф.0503130Gт.1стр.174гр.6',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120121000''','120121000','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120121000''','120121000','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120121000''','120121000','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120121000''','120121000','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120122000''','120122000','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120122000''','120122000','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120122000''','120122000','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120122000''','120122000','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120127000''','120127000','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120127000''','120127000','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120127000''','120127000','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120123000''','120123000','','',8,'     ','3','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120123000''','120123000','','',8,'     ','4','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,4,'+ ',0,0,'','','88888888888888888888888888888888888','SUBSTRING(CODE,1,9)=''120123000''','120123000','','',8,'     ','5','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,1,9)=''120126000''','120126000','','',8,'     ','6','','1','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','88888888888888888888888888888888888','3','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','88888888888888888888888888888888888','3','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','88888888888888888888888888888888888','3','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','88888888888888888888888888888888888','3','0503178G_Б          ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','3','','1','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','4','','1','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','5','','1','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,3,'+ ',0,0,'','','88888888888888888888888888888888888','','','','',8,'     ','6','','1','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','88888888888888888888888888888888888','3','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','88888888888888888888888888888888888','3','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','88888888888888888888888888888888888','3','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','88888888888888888888888888888888888','3','0503178G_СВ         ','20130101',NULL,'',0,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','171','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','172','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','5','171','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','172','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,0,'+ ',0,0,'','','','','','','',8,'     ','5','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,0,'+ ',0,0,'','','','','','','',8,'     ','5','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','171','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'+ ',0,0,'','','','','','','',8,'     ','3','172','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,0,'+ ',0,0,'','','','','','','',8,'     ','3','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,0,'+ ',0,0,'','','','','','','',8,'     ','3','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,0,'+ ',0,0,'','','','','','','',8,'     ','3','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,0,'+ ',0,0,'','','','','','','',8,'     ','3','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','172','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,9,0,'+ ',0,0,'','','','','','','',8,'     ','6','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,4,0,'+ ',0,0,'','','','','','','',8,'     ','3','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,6,0,'+ ',0,0,'','','','','','','',8,'     ','3','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,7,0,'+ ',0,0,'','','','','','','',8,'     ','3','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','176','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','175','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','179','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','173','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'+ ',0,0,'','','','','','','',8,'     ','3','174','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 93
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'2014_10')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'2014_10')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_10'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_10' , 'Проверка: 0503130G - 0503178G (Б, СВ)', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:29:060PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_16 - Проверка: 0503130G - 0503172G (16 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_16' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_16'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567441,7,0,0,0,'ф.0503130Gт.1стр.471гр.8 =  ф.0503172Gт.1гр.3Фильтр:1 301 13 000 +  ф.0503172Gт.1гр.3Фильтр:1 301 12 000 +  ф.0503172Gт.1гр.3Фильтр:1 301 11 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 13 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 12 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 11 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567442,7,0,0,0,'ф.0503130Gт.1стр.472гр.8 =  ф.0503172Gт.1гр.3Фильтр:1 301 24 000 +  ф.0503172Gт.1гр.3Фильтр:1 301 21 000 +  ф.0503172Gт.1гр.3Фильтр:1 301 22 000 +  ф.0503172Gт.1гр.3Фильтр:1 301 23 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 24 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 21 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 22 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 23 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567443,7,0,0,0,'ф.0503130Gт.1стр.291гр.3 =  ф.0503172Gт.1гр.2Фильтр:1 207 11 000 +  ф.0503172Gт.1гр.2Фильтр:1 207 13 000 +  ф.0503172Gт.1гр.2Фильтр:1 207 14 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567444,7,0,0,0,'ф.0503130Gт.1стр.291гр.6 =  ф.0503172Gт.1гр.3Фильтр:1 207 11 000 +  ф.0503172Gт.1гр.3Фильтр:1 207 13 000 +  ф.0503172Gт.1гр.3Фильтр:1 207 14 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567445,7,0,0,0,'ф.0503130Gт.1стр.292гр.3 =  ф.0503172Gт.1гр.2Фильтр:1 207 21 000 +  ф.0503172Gт.1гр.2Фильтр:1 207 23 000 +  ф.0503172Gт.1гр.2Фильтр:1 207 24 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567446,7,0,0,0,'ф.0503130Gт.1стр.292гр.6 =  ф.0503172Gт.1гр.3Фильтр:1 207 21 000 +  ф.0503172Gт.1гр.3Фильтр:1 207 23 000 +  ф.0503172Gт.1гр.3Фильтр:1 207 24 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567447,7,0,0,0,'ф.0503130Gт.1стр.293гр.3 =  ф.0503172Gт.1гр.2Фильтр:1 207 31 000 +  ф.0503172Gт.1гр.2Фильтр:1 207 33 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567448,7,0,0,0,'ф.0503130Gт.1стр.293гр.6 =  ф.0503172Gт.1гр.3Фильтр:1 207 31 000 +  ф.0503172Gт.1гр.3Фильтр:1 207 33 00',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567449,7,0,0,0,'ф.0503130Gт.1стр.471гр.3 =  ф.0503172Gт.2гр.2Фильтр:1 301 11 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 12 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 13 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 14 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567450,7,0,0,0,'ф.0503130Gт.1стр.471гр.6 =  ф.0503172Gт.2гр.3Фильтр:1 301 11 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 12 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 13 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 14 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567451,7,0,0,0,'ф.0503130Gт.1стр.472гр.3 =  ф.0503172Gт.2гр.2Фильтр:1 301 21 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 23 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 24 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567452,7,0,0,0,'ф.0503130Gт.1стр.472гр.6 =  ф.0503172Gт.2гр.3Фильтр:1 301 21 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 23 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 24 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567453,7,0,0,0,'ф.0503130Gт.1стр.473гр.3 =  ф.0503172Gт.2гр.2Фильтр:1 301 31 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 33 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567454,7,0,0,0,'ф.0503130Gт.1стр.473гр.6 =  ф.0503172Gт.2гр.3Фильтр:1 301 31 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 33 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567455,7,0,0,0,'ф.0503130Gт.1стр.474гр.3 =  ф.0503172Gт.2гр.2Фильтр:1 301 42 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 43 000 +  ф.0503172Gт.2гр.2Фильтр:1 301 44 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567456,7,0,0,0,'ф.0503130Gт.1стр.474гр.6 =  ф.0503172Gт.2гр.3Фильтр:1 301 42 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 43 000 +  ф.0503172Gт.2гр.3Фильтр:1 301 44 000',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 16
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','00000000000000000130124000','RIGHT(RTRIM(CODE),9)=''130124000''','1 301 24 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'+ ',0,0,'','','00000000000000000130121000','RIGHT(RTRIM(CODE),9)=''130121000''','1 301 21 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','00000000000000000130122000','RIGHT(RTRIM(CODE),9)=''130122000''','1 301 22 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'+ ',0,0,'','','00000000000000000130123000','RIGHT(RTRIM(CODE),9)=''130123000''','1 301 23 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','00000000000000000130113000','RIGHT(RTRIM(CODE),9)=''130113000''','1 301 13 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'+ ',0,0,'','','00000000000000000130112000','RIGHT(RTRIM(CODE),9)=''130112000''','1 301 12 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','00000000000000000130111000','RIGHT(RTRIM(CODE),9)=''130111000''','1 301 11 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','00000000000000000120711000','RIGHT(RTRIM(CODE),9)=''120711000''','1 207 11 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'+ ',0,0,'','','00000000000000000120713000','RIGHT(RTRIM(CODE),9)=''120713000''','1 207 13 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,4,4,'+ ',0,0,'','','00000000000000000120714000','RIGHT(RTRIM(CODE),9)=''120714000''','1 207 14 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','00000000000000000120711000','RIGHT(RTRIM(CODE),9)=''120711000''','1 207 11 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'+ ',0,0,'','','00000000000000000120713000','RIGHT(RTRIM(CODE),9)=''120713000''','1 207 13 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','00000000000000000120714000','RIGHT(RTRIM(CODE),9)=''120714000''','1 207 14 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','00000000000000000120721000','RIGHT(RTRIM(CODE),9)=''120721000''','1 207 21 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'+ ',0,0,'','','00000000000000000120723000','RIGHT(RTRIM(CODE),9)=''120723000''','1 207 23 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','00000000000000000120724000','RIGHT(RTRIM(CODE),9)=''120724000''','1 207 24 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','00000000000000000120721000','RIGHT(RTRIM(CODE),9)=''120721000''','1 207 21 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'+ ',0,0,'','','00000000000000000120723000','RIGHT(RTRIM(CODE),9)=''120723000''','1 207 23 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,4,4,'+ ',0,0,'','','00000000000000000120724000','RIGHT(RTRIM(CODE),9)=''120724000''','1 207 24 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','00000000000000000120731000','RIGHT(RTRIM(CODE),9)=''120731000''','1 207 31 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'+ ',0,0,'','','00000000000000000120733000','RIGHT(RTRIM(CODE),9)=''120733000''','1 207 33 000','','',8,'     ','4','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','00000000000000000120731000','RIGHT(RTRIM(CODE),9)=''120731000''','1 207 31 000','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'+ ',0,0,'','','00000000000000000120733000','RIGHT(RTRIM(CODE),9)=''120733000''','1 207 33 00','','',8,'     ','5','','1','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'+ ',0,0,'','','00000000000000000130113000','RIGHT(RTRIM(CODE),9)=''130113000''','1 301 13 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','00000000000000000130112000','RIGHT(RTRIM(CODE),9)=''130112000''','1 301 12 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,4,'+ ',0,0,'','','00000000000000000130111000','RIGHT(RTRIM(CODE),9)=''130111000''','1 301 11 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,4,'+ ',0,0,'','','00000000000000000130124000','RIGHT(RTRIM(CODE),9)=''130124000''','1 301 24 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,4,'+ ',0,0,'','','00000000000000000130121000','RIGHT(RTRIM(CODE),9)=''130121000''','1 301 21 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,8,4,'+ ',0,0,'','','00000000000000000130122000','RIGHT(RTRIM(CODE),9)=''130122000''','1 301 22 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,9,4,'+ ',0,0,'','','00000000000000000130123000','RIGHT(RTRIM(CODE),9)=''130123000''','1 301 23 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','00000000000000000130111000','RIGHT(RTRIM(CODE),9)=''130111000''','1 301 11 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,4,'+ ',0,0,'','','00000000000000000130112000','RIGHT(RTRIM(CODE),9)=''130112000''','1 301 12 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,4,'+ ',0,0,'','','00000000000000000130113000','RIGHT(RTRIM(CODE),9)=''130113000''','1 301 13 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,4,'+ ',0,0,'','','00000000000000000130114000','RIGHT(RTRIM(CODE),9)=''130114000''','1 301 14 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','00000000000000000130111000','RIGHT(RTRIM(CODE),9)=''130111000''','1 301 11 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'+ ',0,0,'','','00000000000000000130112000','RIGHT(RTRIM(CODE),9)=''130112000''','1 301 12 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','00000000000000000130113000','RIGHT(RTRIM(CODE),9)=''130113000''','1 301 13 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,4,'+ ',0,0,'','','00000000000000000130114000','RIGHT(RTRIM(CODE),9)=''130114000''','1 301 14 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','00000000000000000130121000','RIGHT(RTRIM(CODE),9)=''130121000''','1 301 21 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'+ ',0,0,'','','00000000000000000130123000','RIGHT(RTRIM(CODE),9)=''130123000''','1 301 23 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','00000000000000000130124000','RIGHT(RTRIM(CODE),9)=''130124000''','1 301 24 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,4,'+ ',0,0,'','','00000000000000000130121000','RIGHT(RTRIM(CODE),9)=''130121000''','1 301 21 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,4,'+ ',0,0,'','','00000000000000000130123000','RIGHT(RTRIM(CODE),9)=''130123000''','1 301 23 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,4,'+ ',0,0,'','','00000000000000000130124000','RIGHT(RTRIM(CODE),9)=''130124000''','1 301 24 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,4,'+ ',0,0,'','','00000000000000000130131000','RIGHT(RTRIM(CODE),9)=''130131000''','1 301 31 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,4,'+ ',0,0,'','','00000000000000000130133000','RIGHT(RTRIM(CODE),9)=''130133000''','1 301 33 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,4,'+ ',0,0,'','','00000000000000000130131000','RIGHT(RTRIM(CODE),9)=''130131000''','1 301 31 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,4,'+ ',0,0,'','','00000000000000000130133000','RIGHT(RTRIM(CODE),9)=''130133000''','1 301 33 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,4,'+ ',0,0,'','','00000000000000000130142000','RIGHT(RTRIM(CODE),9)=''130142000''','1 301 42 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,4,'+ ',0,0,'','','00000000000000000130143000','RIGHT(RTRIM(CODE),9)=''130143000''','1 301 43 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,4,'+ ',0,0,'','','00000000000000000130144000','RIGHT(RTRIM(CODE),9)=''130144000''','1 301 44 000','','',8,'     ','4','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,4,'+ ',0,0,'','','00000000000000000130142000','RIGHT(RTRIM(CODE),9)=''130142000''','1 301 42 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,4,'+ ',0,0,'','','00000000000000000130143000','RIGHT(RTRIM(CODE),9)=''130143000''','1 301 43 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,4,'+ ',0,0,'','','00000000000000000130144000','RIGHT(RTRIM(CODE),9)=''130144000''','1 301 44 000','','',8,'     ','5','','2','0503172G            ','20121231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','471','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','474','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','474','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','473','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','473','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','472','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','472','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','471','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','291','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','472','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','291','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','471','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','293','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','293','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','292','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','292','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 70
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_16')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_16')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 16
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_16'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_16' , 'Проверка: 0503130G - 0503172G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:03:46:827PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_17 - Проверка:0503230G, 0503121G,0503110G (65 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_17' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_17'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567527,7,0,0,0,'ф.0503121Gт.1стр.020гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___101_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___101_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___103_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___103_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___104_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___104_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___105_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___105_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___106_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___106_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___107_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___107_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10909_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10909_____140110110''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567528,7,0,0,0,'ф.0503121Gт.1стр.030гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___111_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___111_______140110120'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___112_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___112_______140110120''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567529,7,0,0,0,'ф.0503121Gт.1стр.040гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___113_______140110130'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___113_______140110130''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567530,7,0,0,0,'ф.0503121Gт.1стр.050гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___115_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___115_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___116_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___116_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1101104001140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1101104001140110140''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567531,7,0,0,0,'ф.0503121Gт.1стр.061гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___219_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___219_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___202_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___202_______140110151''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567532,7,0,0,0,'ф.0503121Gт.1стр.062гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___205_______140110152'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___205_______140110152''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567533,7,0,0,0,'ф.0503121Gт.1стр.080гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10202_____140110160'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10202_____140110160''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567534,7,0,0,0,'ф.0503121Gт.1стр.091гр.4 =  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010603____140110171'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010603____140110171''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567535,7,0,0,0,'ф.0503121Gт.1стр.092гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___114_______140110172'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___114_______140110172'''' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010502____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010502____140110172'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010601____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010601____140110172''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567536,7,0,0,0,'ф.0503121Gт.1стр.093гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1_________140110173'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1_________140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0102______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0102______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0106______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0106______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0202______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0202______140110173''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567537,7,0,0,0,'ф.0503121Gт.1стр.100гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___201_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___201_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___203_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___203_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___207_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___207_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___204_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___204_______140110180''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567538,7,0,0,0,'ф.0503121Gт.1стр.540гр.4 =  ф.0503230Gт.1стр.490гр.6 -  ф.0503230Gт.1стр.490гр.3 +  ф.0503230Gт.1стр.510гр.6 -  ф.0503230Gт.1стр.510гр.3 +  ф.0503230Gт.1стр.530гр.6 -  ф.0503230Gт.1стр.530гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.3 -  ф.0503110Gт.4стр.00000000000000000130404000гр.2 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567539,7,0,0,0,'ф.0503121Gт.1стр.540гр.6 =  ф.0503230Gт.1стр.490гр.8 -  ф.0503230Gт.1стр.490гр.5 +  ф.0503230Gт.1стр.510гр.8 -  ф.0503230Gт.1стр.510гр.5 +  ф.0503230Gт.1стр.530гр.8 -  ф.0503230Gт.1стр.530гр.5 +  ф.0503110Gт.4стр.00000000000000000130404000гр.3 -  ф.0503110Gт.4стр.00000000000000000130404000гр.2 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567540,7,0,0,0,'ф.0503121Gт.1стр.410гр.4 =  ф.0503230Gт.1стр.170гр.6 -  ф.0503230Gт.1стр.170гр.3 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567541,7,0,0,0,'ф.0503121Gт.1стр.410гр.6 =  ф.0503230Gт.1стр.170гр.8 -  ф.0503230Gт.1стр.170гр.5 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567542,7,0,0,0,'ф.0503121Gт.1стр.380гр.4 =  ф.0503230Gт.1стр.400гр.6 -  ф.0503230Gт.1стр.400гр.3 -  ф.0503230Gт.1стр.600гр.6 +  ф.0503230Gт.1стр.600гр.3 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.2 -  ф.0503110Gт.4стр.00000000000000000130404000гр.3 +  ф.0503110Gт.4стр.00000000000000000130406000гр.2 -  ф.0503110Gт.4стр.00000000000000000130406000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567543,7,0,0,0,'ф.0503121Gт.1стр.380гр.6 =  ф.0503230Gт.1стр.400гр.8 -  ф.0503230Gт.1стр.400гр.5 -  ф.0503230Gт.1стр.600гр.8 +  ф.0503230Gт.1стр.600гр.5 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.2 -  ф.0503110Gт.4стр.00000000000000000130404000гр.3 +  ф.0503110Gт.4стр.00000000000000000130406000гр.2 -  ф.0503110Gт.4стр.00000000000000000130406000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567544,7,0,0,0,'ф.0503121Gт.1стр.380гр.5 =  ф.0503230Gт.1стр.400гр.7 -  ф.0503230Gт.1стр.400гр.4 -  ф.0503230Gт.1стр.600гр.4 +  ф.0503230Gт.1стр.600гр.7',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567545,7,0,0,0,'ф.0503121Gт.1стр.010гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.1гр.2Фильтр:по счетам счета 140110100 +  ф.0503110Gт.3гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.3гр.2Фильтр:по счетам счета 140110100',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567546,7,0,0,0,'ф.0503121Gт.1стр.150гр.4 -  ф.0503121Gт.1стр.280гр.4 =  ф.0503110Gт.2гр.2Фильтр:по счетам счета 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567547,7,0,0,0,'ф.0503121Gт.1стр.310гр.4 =  ф.0503230Gт.1стр.150гр.6 -  ф.0503230Gт.1стр.150гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567548,7,0,0,0,'ф.0503121Gт.1стр.231гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120251'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120251''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567549,7,0,0,0,'ф.0503121Gт.1стр.232гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120252'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120252''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567550,7,0,0,0,'ф.0503121Gт.1стр.233гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120253'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120253''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567551,7,0,0,0,'ф.0503121Gт.1стр.262гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120272'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120272''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567552,7,0,0,0,'ф.0503121Gт.1стр.263гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120273'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120273''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567553,7,0,0,0,'ф.0503121Gт.1стр.290гр.6 -  ф.0503121Gт.1стр.110гр.6 +  ф.0503121Gт.1стр.280гр.6 =  ф.0503110Gт.1гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 040110100, 040120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567554,7,0,0,0,'ф.0503121Gт.1стр.290гр.4 +  ф.0503121Gт.1стр.280гр.4 -  ф.0503121Gт.1стр.110гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 140110100, 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567555,7,0,0,0,'ф.0503121Gт.1стр.420гр.6 =  ф.0503230Gт.1стр.211гр.8 -  ф.0503230Gт.1стр.211гр.5 +  ф.0503230Gт.1стр.371гр.8 -  ф.0503230Gт.1стр.371гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567556,7,0,0,0,'ф.0503121Gт.1стр.470гр.4 =  ф.0503230Gт.1стр.213гр.6 -  ф.0503230Gт.1стр.213гр.3 +  ф.0503230Gт.1стр.373гр.6 -  ф.0503230Gт.1стр.373гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567557,7,0,0,0,'ф.0503121Gт.1стр.470гр.5 =  ф.0503230Gт.1стр.213гр.7 -  ф.0503230Gт.1стр.213гр.4 +  ф.0503230Gт.1стр.373гр.7 -  ф.0503230Gт.1стр.373гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567558,7,0,0,0,'ф.0503121Gт.1стр.470гр.6 =  ф.0503230Gт.1стр.213гр.8 -  ф.0503230Gт.1стр.213гр.5 +  ф.0503230Gт.1стр.373гр.8 -  ф.0503230Gт.1стр.373гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567559,7,0,0,0,'ф.0503121Gт.1стр.420гр.4 =  ф.0503230Gт.1стр.211гр.6 -  ф.0503230Gт.1стр.211гр.3 +  ф.0503230Gт.1стр.371гр.6 -  ф.0503230Gт.1стр.371гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567560,7,0,0,0,'ф.0503121Gт.1стр.420гр.5 =  ф.0503230Gт.1стр.211гр.7 -  ф.0503230Gт.1стр.211гр.4 +  ф.0503230Gт.1стр.371гр.7 -  ф.0503230Gт.1стр.371гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567561,7,0,0,0,'ф.0503121Gт.1стр.410гр.5 =  ф.0503230Gт.1стр.170гр.7 -  ф.0503230Gт.1стр.170гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567562,7,0,0,0,'ф.0503121Gт.1стр.460гр.4 =  ф.0503230Gт.1стр.290гр.6 -  ф.0503230Gт.1стр.290гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567563,7,0,0,0,'ф.0503121Gт.1стр.460гр.6 =  ф.0503230Gт.1стр.290гр.8 -  ф.0503230Gт.1стр.290гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567564,7,0,0,0,'ф.0503121Gт.1стр.520гр.4 +  ф.0503121Gт.1стр.530гр.4 =  ф.0503230Gт.1стр.470гр.6 -  ф.0503230Gт.1стр.470гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567565,7,0,0,0,'ф.0503121Gт.1стр.520гр.6 +  ф.0503121Gт.1стр.530гр.6 =  ф.0503230Gт.1стр.470гр.8 -  ф.0503230Gт.1стр.470гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567566,7,0,0,0,'ф.0503121Gт.1стр.310гр.6 =  ф.0503230Gт.1стр.150гр.8 -  ф.0503230Gт.1стр.150гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567567,7,0,0,0,'ф.0503121Gт.1стр.161гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120211'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120211''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567568,7,0,0,0,'ф.0503121Gт.1стр.162гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120212'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120212''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567569,7,0,0,0,'ф.0503121Gт.1стр.163гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120213'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120213''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567570,7,0,0,0,'ф.0503121Gт.1стр.171гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120221'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120221''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567571,7,0,0,0,'ф.0503121Gт.1стр.172гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120222'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120222''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567572,7,0,0,0,'ф.0503121Gт.1стр.173гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120223'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120223''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567573,7,0,0,0,'ф.0503121Gт.1стр.174гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120224'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120224''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567574,7,0,0,0,'ф.0503121Gт.1стр.175гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120225'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120225''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567575,7,0,0,0,'ф.0503121Gт.1стр.176гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120226'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120226''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567576,7,0,0,0,'ф.0503121Gт.1стр.191гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120231'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120231''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567577,7,0,0,0,'ф.0503121Gт.1стр.192гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120232'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120232''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567578,7,0,0,0,'ф.0503121Gт.1стр.211гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120241'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120241''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567579,7,0,0,0,'ф.0503121Gт.1стр.212гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120242'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120242''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567580,7,0,0,0,'ф.0503121Gт.1стр.241гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120261'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120261''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567581,7,0,0,0,'ф.0503121Gт.1стр.242гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120262'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567582,7,0,0,0,'ф.0503121Gт.1стр.243гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120263'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567583,7,0,0,0,'ф.0503121Gт.1стр.261гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120271'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120271''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567584,7,0,0,0,'ф.0503121Gт.1стр.270гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120290'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120290''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567585,7,0,0,0,'ф.0503121Gт.1стр.370гр.6 =  ф.0503230Gт.1стр.140гр.8 -  ф.0503230Gт.1стр.140гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567586,7,0,0,0,'ф.0503121Gт.1стр.440гр.5 =  ф.0503230Gт.1стр.212гр.7 -  ф.0503230Gт.1стр.212гр.4 +  ф.0503230Gт.1стр.372гр.7 -  ф.0503230Gт.1стр.372гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,567587,7,0,0,0,'ф.0503121Gт.1стр.440гр.4 =  ф.0503230Gт.1стр.212гр.6 -  ф.0503230Gт.1стр.212гр.3 +  ф.0503230Gт.1стр.372гр.6 -  ф.0503230Gт.1стр.372гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,567588,7,0,0,0,'ф.0503121Gт.1стр.440гр.6 =  ф.0503230Gт.1стр.212гр.8 -  ф.0503230Gт.1стр.212гр.5 +  ф.0503230Gт.1стр.372гр.8 -  ф.0503230Gт.1стр.372гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,567589,7,0,0,0,'ф.0503121Gт.1стр.480гр.4 =  ф.0503230Gт.1стр.230гр.6 -  ф.0503230Gт.1стр.230гр.3 +  ф.0503230Gт.1стр.260гр.6 -  ф.0503230Gт.1стр.260гр.3 +  ф.0503230Gт.1стр.310гр.6 -  ф.0503230Gт.1стр.310гр.3 +  ф.0503230Gт.1стр.320гр.6 -  ф.0503230Gт.1стр.320гр.3 +  ф.0503230Gт.1стр.330гр.6 -  ф.0503230Gт.1стр.330гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,567590,7,0,0,0,'ф.0503121Gт.1стр.480гр.5 =  ф.0503230Gт.1стр.230гр.7 -  ф.0503230Gт.1стр.230гр.4 +  ф.0503230Gт.1стр.260гр.7 -  ф.0503230Gт.1стр.260гр.4 +  ф.0503230Gт.1стр.310гр.7 -  ф.0503230Gт.1стр.310гр.4 +  ф.0503230Gт.1стр.320гр.7 -  ф.0503230Gт.1стр.320гр.4 +  ф.0503230Gт.1стр.330гр.7 -  ф.0503230Gт.1стр.330гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (65,1,567591,7,0,0,0,'ф.0503121Gт.1стр.480гр.6 =  ф.0503230Gт.1стр.230гр.8 -  ф.0503230Gт.1стр.230гр.5 +  ф.0503230Gт.1стр.260гр.8 -  ф.0503230Gт.1стр.260гр.5 +  ф.0503230Gт.1стр.310гр.8 -  ф.0503230Gт.1стр.310гр.5 +  ф.0503230Gт.1стр.320гр.8 -  ф.0503230Gт.1стр.320гр.5 +  ф.0503230Gт.1стр.330гр.8 -  ф.0503230Gт.1стр.330гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 65
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'- ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'- ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,4,'- ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,4,'+ ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,4,'- ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,4,'+ ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,4,'- ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,4,'+ ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,4,'- ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,4,'+ ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,4,'- ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,16,4,'+ ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,17,4,'- ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,18,4,'+ ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,19,4,'- ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,20,4,'+ ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,21,4,'- ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,22,4,'+ ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,23,4,'- ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,24,4,'+ ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,25,4,'- ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,26,4,'+ ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,27,4,'- ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,28,4,'+ ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,29,4,'- ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,30,4,'- ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,31,4,'+ ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'- ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,4,'- ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,4,'+ ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,4,'- ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,4,'+ ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,4,'- ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'- ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'- ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'- ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,4,'- ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,4,'+ ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,4,'- ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'- ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'- ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'- ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'- ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'- ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,4,'- ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,6,4,'+ ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,7,4,'- ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,8,4,'+ ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,9,4,'- ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,10,4,'+ ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,11,4,'- ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,12,4,'+ ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,13,4,'- ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,14,4,'+ ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,15,4,'- ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,16,4,'+ ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,17,4,'- ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,18,4,'+ ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,19,4,'- ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,20,4,'+ ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,21,4,'- ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,22,4,'+ ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,23,4,'- ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,4,'- ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,5,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,6,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,7,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,4,'+ ',0,0,'','','','CODE LIKE ''%1401202__''','по счетам счета 140120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120263''','{КОД СЧЕТА}=''140120263''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,8,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,9,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,5,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,4,'+ ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,4,'- ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,6,4,'+ ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,7,4,'- ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,4,'- ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,6,4,'+ ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,7,4,'- ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,8,4,'+ ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,9,4,'- ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'- ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,11,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,11,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,5,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,7,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,9,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,11,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,12,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,7,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,9,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,11,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,12,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'- ',0,0,'','','','','','','',8,'     ','6','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'- ',0,0,'','','','','','','',8,'     ','5','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,0,'- ',0,0,'','','','','','','',8,'     ','8','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,0,'- ',0,0,'','','','','','','',8,'     ','4','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','600','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'- ',0,0,'','','','','','','',8,'     ','3','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'- ',0,0,'','','','','','','',8,'     ','5','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'- ',0,0,'','','','','','','',8,'     ','5','490','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,5,0,'- ',0,0,'','','','','','','',8,'     ','5','510','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','530','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,7,0,'- ',0,0,'','','','','','','',8,'     ','5','530','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','150','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'- ',0,0,'','','','','','','',8,'     ','4','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,5,0,'- ',0,0,'','','','','','','',8,'     ','4','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,5,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,5,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'- ',0,0,'','','','','','','',8,'     ','4','211','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,5,0,'- ',0,0,'','','','','','','',8,'     ','4','371','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'- ',0,0,'','','','','','','',8,'     ','4','170','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','290','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'- ',0,0,'','','','','','','',8,'     ','3','290','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','290','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,3,0,'- ',0,0,'','','','','','','',8,'     ','5','290','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,4,0,'- ',0,0,'','','','','','','',8,'     ','3','470','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,3,0,'- ',0,0,'','','','','','','',8,'     ','4','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,5,0,'- ',0,0,'','','','','','','',8,'     ','4','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,3,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,5,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,3,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,5,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,7,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,9,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,10,0,'+ ',0,0,'','','','','','','',8,'     ','6','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,11,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,3,0,'- ',0,0,'','','','','','','',8,'     ','4','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,5,0,'- ',0,0,'','','','','','','',8,'     ','4','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,7,0,'- ',0,0,'','','','','','','',8,'     ','4','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,9,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,11,0,'- ',0,0,'','','','','','','',8,'     ','4','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','470','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,4,0,'- ',0,0,'','','','','','','',8,'     ','5','470','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','150','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,0,'- ',0,0,'','','','','','','',8,'     ','5','150','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,3,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,5,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,7,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,9,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,11,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,3,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,5,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','140','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,3,0,'- ',0,0,'','','','','','','',8,'     ','5','140','1','0503230G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','161','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','163','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','162','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','174','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','172','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','171','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','242','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','241','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','212','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','211','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','192','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','191','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','370','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','270','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','261','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','243','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','231','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','233','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','232','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','263','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','262','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,0,'- ',0,0,'','','','','','','',8,'     ','4','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','093','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,0,'- ',0,0,'','','','','','','',8,'     ','4','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','092','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','091','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','100','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','062','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','040','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','061','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','030','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 365
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'2014_17')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (65,'2014_17')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 65
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_17'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_17' , 'Проверка:0503230G, 0503121G,0503110G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:07:16:450PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_2 - Проверка: 0503230G - 0503168G_БД (18 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_2' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_2'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567670,7,0,0,0,'ф.0503230Gт.1стр.010гр.3 =  ф.0503168G_БДт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567671,7,0,0,0,'ф.0503230Gт.1стр.020гр.3 =  ф.0503168G_БДт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567672,7,0,0,0,'ф.0503230Gт.1стр.040гр.3 =  ф.0503168G_БДт.1стр.110гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567673,7,0,0,0,'ф.0503230Gт.1стр.050гр.3 =  ф.0503168G_БДт.1стр.120гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567674,7,0,0,0,'ф.0503230Gт.1стр.070гр.3 =  ф.0503168G_БДт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567675,7,0,0,0,'ф.0503230Gт.1стр.080гр.3 =  ф.0503168G_БДт.1стр.190гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567676,7,0,0,0,'ф.0503230Gт.1стр.110гр.3 =  ф.0503168G_БДт.1стр.320гр.4 +  ф.0503168G_БДт.1стр.360гр.4 +  ф.0503168G_БДт.1стр.380гр.4 +  ф.0503168G_БДт.1стр.420гр.4 +  ф.0503168G_БДт.1стр.440гр.4 +  ф.0503168G_БДт.1стр.450гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567677,7,0,0,0,'ф.0503230Gт.1стр.010гр.6 =  ф.0503168G_БДт.1стр.010гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567678,7,0,0,0,'ф.0503230Gт.1стр.020гр.6 =  ф.0503168G_БДт.1стр.050гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567679,7,0,0,0,'ф.0503230Gт.1стр.040гр.6 =  ф.0503168G_БДт.1стр.110гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567680,7,0,0,0,'ф.0503230Gт.1стр.050гр.6 =  ф.0503168G_БДт.1стр.120гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567681,7,0,0,0,'ф.0503230Gт.1стр.070гр.6 =  ф.0503168G_БДт.1стр.150гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567682,7,0,0,0,'ф.0503230Gт.1стр.080гр.6 =  ф.0503168G_БДт.1стр.190гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567683,7,0,0,0,'ф.0503230Gт.1стр.110гр.6 =  ф.0503168G_БДт.1стр.320гр.7 +  ф.0503168G_БДт.1стр.360гр.7 +  ф.0503168G_БДт.1стр.380гр.7 +  ф.0503168G_БДт.1стр.420гр.7 +  ф.0503168G_БДт.1стр.440гр.7 +  ф.0503168G_БДт.1стр.450гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567684,7,0,0,0,'ф.0503230Gт.1стр.120гр.3 =  ф.0503168G_БДт.1стр.330гр.4 +  ф.0503168G_БДт.1стр.370гр.4 +  ф.0503168G_БДт.1стр.430гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567685,7,0,0,0,'ф.0503230Gт.1стр.120гр.6 =  ф.0503168G_БДт.1стр.330гр.7 +  ф.0503168G_БДт.1стр.370гр.7 +  ф.0503168G_БДт.1стр.430гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567686,7,0,0,0,'ф.0503230Gт.1стр.090гр.6 =  ф.0503168G_БДт.1стр.070гр.7 +  ф.0503168G_БДт.1стр.130гр.7 +  ф.0503168G_БДт.1стр.170гр.7 +  ф.0503168G_БДт.1стр.230гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567687,7,0,0,0,'ф.0503230Gт.1стр.090гр.3 =  ф.0503168G_БДт.1стр.070гр.4 +  ф.0503168G_БДт.1стр.130гр.4 +  ф.0503168G_БДт.1стр.170гр.4 +  ф.0503168G_БДт.1стр.230гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','330','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','370','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','430','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','370','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','430','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','090','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','090','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','120','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','010','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','120','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','110','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','080','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','070','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','050','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','040','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','020','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','010','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','110','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','080','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','070','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','050','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','040','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','020','1','0503230G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 56
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'2014_2')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'2014_2')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_2'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_2' , 'Проверка: 0503230G - 0503168G_БД', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:05:54:923PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_3 - Проверка: 0503130G - 0503168G_БД (18 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_3' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_3'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567395,7,0,0,0,'ф.0503130Gт.1стр.010гр.3 =  ф.0503168G_БДт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567396,7,0,0,0,'ф.0503130Gт.1стр.020гр.3 =  ф.0503168G_БДт.1стр.050гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567397,7,0,0,0,'ф.0503130Gт.1стр.040гр.3 =  ф.0503168G_БДт.1стр.110гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567398,7,0,0,0,'ф.0503130Gт.1стр.050гр.3 =  ф.0503168G_БДт.1стр.120гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567399,7,0,0,0,'ф.0503130Gт.1стр.070гр.3 =  ф.0503168G_БДт.1стр.150гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567400,7,0,0,0,'ф.0503130Gт.1стр.080гр.3 =  ф.0503168G_БДт.1стр.190гр.4',0,0,1,'20141230','','','','',NULL,NULL,'=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567401,7,0,0,0,'ф.0503130Gт.1стр.110гр.3 =  ф.0503168G_БДт.1стр.320гр.4 +  ф.0503168G_БДт.1стр.360гр.4 +  ф.0503168G_БДт.1стр.380гр.4 +  ф.0503168G_БДт.1стр.420гр.4 +  ф.0503168G_БДт.1стр.440гр.4 +  ф.0503168G_БДт.1стр.450гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567402,7,0,0,0,'ф.0503130Gт.1стр.010гр.6 =  ф.0503168G_БДт.1стр.010гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567403,7,0,0,0,'ф.0503130Gт.1стр.020гр.6 =  ф.0503168G_БДт.1стр.050гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567404,7,0,0,0,'ф.0503130Gт.1стр.040гр.6 =  ф.0503168G_БДт.1стр.110гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567405,7,0,0,0,'ф.0503130Gт.1стр.050гр.6 =  ф.0503168G_БДт.1стр.120гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567406,7,0,0,0,'ф.0503130Gт.1стр.070гр.6 =  ф.0503168G_БДт.1стр.150гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567407,7,0,0,0,'ф.0503130Gт.1стр.080гр.6 =  ф.0503168G_БДт.1стр.190гр.7',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567408,7,0,0,0,'ф.0503130Gт.1стр.110гр.6 =  ф.0503168G_БДт.1стр.320гр.7 +  ф.0503168G_БДт.1стр.360гр.7 +  ф.0503168G_БДт.1стр.380гр.7 +  ф.0503168G_БДт.1стр.420гр.7 +  ф.0503168G_БДт.1стр.440гр.7 +  ф.0503168G_БДт.1стр.450гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567409,7,0,0,0,'ф.0503130Gт.1стр.120гр.3 =  ф.0503168G_БДт.1стр.330гр.4 +  ф.0503168G_БДт.1стр.370гр.4 +  ф.0503168G_БДт.1стр.430гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567410,7,0,0,0,'ф.0503130Gт.1стр.120гр.6 =  ф.0503168G_БДт.1стр.330гр.7 +  ф.0503168G_БДт.1стр.370гр.7 +  ф.0503168G_БДт.1стр.430гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567411,7,0,0,0,'ф.0503130Gт.1стр.090гр.6 =  ф.0503168G_БДт.1стр.070гр.7 +  ф.0503168G_БДт.1стр.130гр.7 +  ф.0503168G_БДт.1стр.170гр.7 +  ф.0503168G_БДт.1стр.230гр.7',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567412,7,0,0,0,'ф.0503130Gт.1стр.090гр.3 =  ф.0503168G_БДт.1стр.070гр.4 +  ф.0503168G_БДт.1стр.130гр.4 +  ф.0503168G_БДт.1стр.170гр.4 +  ф.0503168G_БДт.1стр.230гр.4',0,0,1,'20141230','','','','',NULL,'','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','120','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,7,0,'+ ',0,0,'','','','','','','',8,'     ','4','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','010','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','050','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','110','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','120','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','150','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','190','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','360','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','380','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','420','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','440','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,7,0,'+ ',0,0,'','','','','','','',8,'     ','7','450','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','330','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','370','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','430','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','370','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','430','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'+ ',0,0,'','','','','','','',8,'     ','7','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','070','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'+ ',0,0,'','','','','','','',8,'     ','4','130','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','170','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,5,0,'+ ',0,0,'','','','','','','',8,'     ','4','230','1','0503168G_БД         ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','090','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','090','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','120','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','010','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','120','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','110','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','080','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','070','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','050','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','040','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','020','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','010','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','110','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','080','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','070','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','050','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','040','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','020','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 56
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'2014_3')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'2014_3')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 18
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_3'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_3' , 'Проверка: 0503130G - 0503168G_БД', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:03:34:580PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_6 - Проверка:0503130G, 0503121G,0503110G (65 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_6' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_6'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567458,7,0,0,0,'ф.0503121Gт.1стр.020гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10904_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10905_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10906_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10907_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10903_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10902_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10901_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___101_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___101_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___103_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___103_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___104_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___104_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___105_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___105_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___106_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___106_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___107_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___107_______140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___108_______140110110'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10909_____140110110'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10909_____140110110''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567459,7,0,0,0,'ф.0503121Gт.1стр.030гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___111_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___111_______140110120'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___112_______140110120'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___112_______140110120''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567460,7,0,0,0,'ф.0503121Gт.1стр.040гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___113_______140110130'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___113_______140110130''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567461,7,0,0,0,'ф.0503121Gт.1стр.050гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10908_____140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___115_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___115_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___116_______140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___116_______140110140'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1101104001140110140'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1101104001140110140''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (5,1,567462,7,0,0,0,'ф.0503121Gт.1стр.061гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___219_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___219_______140110151'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___202_______140110151'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___202_______140110151''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (6,1,567463,7,0,0,0,'ф.0503121Gт.1стр.062гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___205_______140110152'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___205_______140110152''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (7,1,567464,7,0,0,0,'ф.0503121Gт.1стр.080гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___10202_____140110160'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___10202_____140110160''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (8,1,567465,7,0,0,0,'ф.0503121Gт.1стр.091гр.4 =  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010603____140110171'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010603____140110171''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (9,1,567466,7,0,0,0,'ф.0503121Gт.1стр.092гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___114_______140110172'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___114_______140110172'''' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010502____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010502____140110172'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___010601____140110172'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___010601____140110172''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (10,1,567467,7,0,0,0,'ф.0503121Gт.1стр.093гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___1_________140110173'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___1_________140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0102______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0102______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0106______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0106______140110173'' +  ф.0503110Gт.3гр.3Фильтр:{КОД СЧЕТА }=''___0202______140110173'' -  ф.0503110Gт.3гр.2Фильтр:{КОД СЧЕТА }=''___0202______140110173''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (11,1,567468,7,0,0,0,'ф.0503121Gт.1стр.100гр.4 =  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11701_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11702_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11705_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11706_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11707_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___11711_____140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___218_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___218_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___201_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___201_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___203_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___203_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___207_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___207_______140110180'' +  ф.0503110Gт.1гр.3Фильтр:{КОД СЧЕТА }=''___204_______140110180'' -  ф.0503110Gт.1гр.2Фильтр:{КОД СЧЕТА }=''___204_______140110180''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (12,1,567469,7,0,0,0,'ф.0503121Gт.1стр.540гр.4 =  ф.0503130Gт.1стр.490гр.6 -  ф.0503130Gт.1стр.490гр.3 +  ф.0503130Gт.1стр.510гр.6 -  ф.0503130Gт.1стр.510гр.3 +  ф.0503130Gт.1стр.530гр.6 -  ф.0503130Gт.1стр.530гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.3 -  ф.0503110Gт.4стр.00000000000000000130404000гр.2 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (13,1,567470,7,0,0,0,'ф.0503121Gт.1стр.540гр.6 =  ф.0503130Gт.1стр.490гр.8 -  ф.0503130Gт.1стр.490гр.5 +  ф.0503130Gт.1стр.510гр.8 -  ф.0503130Gт.1стр.510гр.5 +  ф.0503130Gт.1стр.530гр.8 -  ф.0503130Gт.1стр.530гр.5 +  ф.0503110Gт.4стр.00000000000000000130404000гр.3 -  ф.0503110Gт.4стр.00000000000000000130404000гр.2 +  ф.0503110Gт.4стр.00000000000000000130406000гр.3 -  ф.0503110Gт.4стр.00000000000000000130406000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (14,1,567471,7,0,0,0,'ф.0503121Gт.1стр.410гр.4 =  ф.0503130Gт.1стр.170гр.6 -  ф.0503130Gт.1стр.170гр.3 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (15,1,567472,7,0,0,0,'ф.0503121Gт.1стр.410гр.6 =  ф.0503130Gт.1стр.170гр.8 -  ф.0503130Gт.1стр.170гр.5 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (16,1,567473,7,0,0,0,'ф.0503121Gт.1стр.380гр.4 =  ф.0503130Gт.1стр.400гр.6 -  ф.0503130Gт.1стр.400гр.3 -  ф.0503130Gт.1стр.600гр.6 +  ф.0503130Gт.1стр.600гр.3 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.2 -  ф.0503110Gт.4стр.00000000000000000130404000гр.3 +  ф.0503110Gт.4стр.00000000000000000130406000гр.2 -  ф.0503110Gт.4стр.00000000000000000130406000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (17,1,567474,7,0,0,0,'ф.0503121Gт.1стр.380гр.6 =  ф.0503130Gт.1стр.400гр.8 -  ф.0503130Gт.1стр.400гр.5 -  ф.0503130Gт.1стр.600гр.8 +  ф.0503130Gт.1стр.600гр.5 +  ф.0503110Gт.4стр.00000000000000000121002000гр.2 -  ф.0503110Gт.4стр.00000000000000000130405000гр.3 +  ф.0503110Gт.4стр.00000000000000000130404000гр.2 -  ф.0503110Gт.4стр.00000000000000000130404000гр.3 +  ф.0503110Gт.4стр.00000000000000000130406000гр.2 -  ф.0503110Gт.4стр.00000000000000000130406000гр.3 +  ф.0503110Gт.4стр.00000000000000000121004000гр.2',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (18,1,567475,7,0,0,0,'ф.0503121Gт.1стр.380гр.5 =  ф.0503130Gт.1стр.400гр.7 -  ф.0503130Gт.1стр.400гр.4 -  ф.0503130Gт.1стр.600гр.4 +  ф.0503130Gт.1стр.600гр.7',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (19,1,567476,7,0,0,0,'ф.0503121Gт.1стр.010гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.1гр.2Фильтр:по счетам счета 140110100 +  ф.0503110Gт.3гр.3Фильтр:по счетам счета 140110100 -  ф.0503110Gт.3гр.2Фильтр:по счетам счета 140110100',0,0,0,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (20,1,567477,7,0,0,0,'ф.0503121Gт.1стр.150гр.4 -  ф.0503121Gт.1стр.280гр.4 =  ф.0503110Gт.2гр.2Фильтр:по счетам счета 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (21,1,567478,7,0,0,0,'ф.0503121Gт.1стр.310гр.4 =  ф.0503130Gт.1стр.150гр.6 -  ф.0503130Gт.1стр.150гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (22,1,567479,7,0,0,0,'ф.0503121Gт.1стр.231гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120251'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120251''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (23,1,567480,7,0,0,0,'ф.0503121Gт.1стр.232гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120252'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120252''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (24,1,567481,7,0,0,0,'ф.0503121Gт.1стр.233гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120253'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120253''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (25,1,567482,7,0,0,0,'ф.0503121Gт.1стр.262гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120272'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120272''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (26,1,567483,7,0,0,0,'ф.0503121Gт.1стр.263гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120273'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120273''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (27,1,567484,7,0,0,0,'ф.0503121Gт.1стр.290гр.6 -  ф.0503121Gт.1стр.110гр.6 +  ф.0503121Gт.1стр.280гр.6 =  ф.0503110Gт.1гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 040110100, 040120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 040110100, 040120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 040110100, 040120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (28,1,567485,7,0,0,0,'ф.0503121Gт.1стр.290гр.4 +  ф.0503121Gт.1стр.280гр.4 -  ф.0503121Gт.1стр.110гр.4 =  ф.0503110Gт.1гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.1гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.2гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.2гр.2Фильтр:по счетам 140110100, 140120200 +  ф.0503110Gт.3гр.3Фильтр:по счетам 140110100, 140120200 -  ф.0503110Gт.3гр.2Фильтр:по счетам 140110100, 140120200',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (29,1,567486,7,0,0,0,'ф.0503121Gт.1стр.420гр.6 =  ф.0503130Gт.1стр.211гр.8 -  ф.0503130Gт.1стр.211гр.5 +  ф.0503130Gт.1стр.371гр.8 -  ф.0503130Gт.1стр.371гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (30,1,567487,7,0,0,0,'ф.0503121Gт.1стр.470гр.4 =  ф.0503130Gт.1стр.213гр.6 -  ф.0503130Gт.1стр.213гр.3 +  ф.0503130Gт.1стр.373гр.6 -  ф.0503130Gт.1стр.373гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (31,1,567488,7,0,0,0,'ф.0503121Gт.1стр.470гр.5 =  ф.0503130Gт.1стр.213гр.7 -  ф.0503130Gт.1стр.213гр.4 +  ф.0503130Gт.1стр.373гр.7 -  ф.0503130Gт.1стр.373гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (32,1,567489,7,0,0,0,'ф.0503121Gт.1стр.470гр.6 =  ф.0503130Gт.1стр.213гр.8 -  ф.0503130Gт.1стр.213гр.5 +  ф.0503130Gт.1стр.373гр.8 -  ф.0503130Gт.1стр.373гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (33,1,567490,7,0,0,0,'ф.0503121Gт.1стр.420гр.4 =  ф.0503130Gт.1стр.211гр.6 -  ф.0503130Gт.1стр.211гр.3 +  ф.0503130Gт.1стр.371гр.6 -  ф.0503130Gт.1стр.371гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (34,1,567491,7,0,0,0,'ф.0503121Gт.1стр.420гр.5 =  ф.0503130Gт.1стр.211гр.7 -  ф.0503130Gт.1стр.211гр.4 +  ф.0503130Gт.1стр.371гр.7 -  ф.0503130Gт.1стр.371гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (35,1,567492,7,0,0,0,'ф.0503121Gт.1стр.410гр.5 =  ф.0503130Gт.1стр.170гр.7 -  ф.0503130Gт.1стр.170гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (36,1,567493,7,0,0,0,'ф.0503121Gт.1стр.460гр.4 =  ф.0503130Gт.1стр.290гр.6 -  ф.0503130Gт.1стр.290гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (37,1,567494,7,0,0,0,'ф.0503121Gт.1стр.460гр.6 =  ф.0503130Gт.1стр.290гр.8 -  ф.0503130Gт.1стр.290гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (38,1,567495,7,0,0,0,'ф.0503121Gт.1стр.520гр.4 +  ф.0503121Gт.1стр.530гр.4 =  ф.0503130Gт.1стр.470гр.6 -  ф.0503130Gт.1стр.470гр.3',0,0,1,'20141230','','','','',NULL,'','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (39,1,567496,7,0,0,0,'ф.0503121Gт.1стр.520гр.6 +  ф.0503121Gт.1стр.530гр.6 =  ф.0503130Gт.1стр.470гр.8 -  ф.0503130Gт.1стр.470гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (40,1,567497,7,0,0,0,'ф.0503121Gт.1стр.310гр.6 =  ф.0503130Gт.1стр.150гр.8 -  ф.0503130Gт.1стр.150гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (41,1,567498,7,0,0,0,'ф.0503121Gт.1стр.161гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120211'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120211''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (42,1,567499,7,0,0,0,'ф.0503121Gт.1стр.162гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120212'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120212''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (43,1,567500,7,0,0,0,'ф.0503121Gт.1стр.163гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120213'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120213''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (44,1,567501,7,0,0,0,'ф.0503121Gт.1стр.171гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120221'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120221''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (45,1,567502,7,0,0,0,'ф.0503121Gт.1стр.172гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120222'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120222''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (46,1,567503,7,0,0,0,'ф.0503121Gт.1стр.173гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120223'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120223''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (47,1,567504,7,0,0,0,'ф.0503121Gт.1стр.174гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120224'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120224''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (48,1,567505,7,0,0,0,'ф.0503121Gт.1стр.175гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120225'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120225''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (49,1,567506,7,0,0,0,'ф.0503121Gт.1стр.176гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120226'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120226''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (50,1,567507,7,0,0,0,'ф.0503121Gт.1стр.191гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120231'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120231''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (51,1,567508,7,0,0,0,'ф.0503121Gт.1стр.192гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120232'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120232''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (52,1,567509,7,0,0,0,'ф.0503121Gт.1стр.211гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120241'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120241''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (53,1,567510,7,0,0,0,'ф.0503121Gт.1стр.212гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120242'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120242''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (54,1,567511,7,0,0,0,'ф.0503121Gт.1стр.241гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120261'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120261''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (55,1,567512,7,0,0,0,'ф.0503121Gт.1стр.242гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120262'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (56,1,567513,7,0,0,0,'ф.0503121Gт.1стр.243гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120263'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120262''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (57,1,567514,7,0,0,0,'ф.0503121Gт.1стр.261гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120271'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120271''',0,0,1,'20141230','','','','',NULL,'','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (58,1,567515,7,0,0,0,'ф.0503121Gт.1стр.270гр.4 =  ф.0503110Gт.2гр.2Фильтр:{КОД СЧЕТА}=''140120290'' -  ф.0503110Gт.2гр.3Фильтр:{КОД СЧЕТА}=''140120290''',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (59,1,567516,7,0,0,0,'ф.0503121Gт.1стр.370гр.6 =  ф.0503130Gт.1стр.140гр.8 -  ф.0503130Gт.1стр.140гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (60,1,567517,7,0,0,0,'ф.0503121Gт.1стр.440гр.5 =  ф.0503130Gт.1стр.212гр.7 -  ф.0503130Gт.1стр.212гр.4 +  ф.0503130Gт.1стр.372гр.7 -  ф.0503130Gт.1стр.372гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (61,1,567518,7,0,0,0,'ф.0503121Gт.1стр.440гр.4 =  ф.0503130Gт.1стр.212гр.6 -  ф.0503130Gт.1стр.212гр.3 +  ф.0503130Gт.1стр.372гр.6 -  ф.0503130Gт.1стр.372гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (62,1,567519,7,0,0,0,'ф.0503121Gт.1стр.440гр.6 =  ф.0503130Gт.1стр.212гр.8 -  ф.0503130Gт.1стр.212гр.5 +  ф.0503130Gт.1стр.372гр.8 -  ф.0503130Gт.1стр.372гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (63,1,567520,7,0,0,0,'ф.0503121Gт.1стр.480гр.4 =  ф.0503130Gт.1стр.230гр.6 -  ф.0503130Gт.1стр.230гр.3 +  ф.0503130Gт.1стр.260гр.6 -  ф.0503130Gт.1стр.260гр.3 +  ф.0503130Gт.1стр.310гр.6 -  ф.0503130Gт.1стр.310гр.3 +  ф.0503130Gт.1стр.320гр.6 -  ф.0503130Gт.1стр.320гр.3 +  ф.0503130Gт.1стр.330гр.6 -  ф.0503130Gт.1стр.330гр.3',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (64,1,567521,7,0,0,0,'ф.0503121Gт.1стр.480гр.5 =  ф.0503130Gт.1стр.230гр.7 -  ф.0503130Gт.1стр.230гр.4 +  ф.0503130Gт.1стр.260гр.7 -  ф.0503130Gт.1стр.260гр.4 +  ф.0503130Gт.1стр.310гр.7 -  ф.0503130Gт.1стр.310гр.4 +  ф.0503130Gт.1стр.320гр.7 -  ф.0503130Gт.1стр.320гр.4 +  ф.0503130Gт.1стр.330гр.7 -  ф.0503130Gт.1стр.330гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (65,1,567522,7,0,0,0,'ф.0503121Gт.1стр.480гр.6 =  ф.0503130Gт.1стр.230гр.8 -  ф.0503130Gт.1стр.230гр.5 +  ф.0503130Gт.1стр.260гр.8 -  ф.0503130Gт.1стр.260гр.5 +  ф.0503130Gт.1стр.310гр.8 -  ф.0503130Gт.1стр.310гр.5 +  ф.0503130Gт.1стр.320гр.8 -  ф.0503130Gт.1стр.320гр.5 +  ф.0503130Gт.1стр.330гр.8 -  ф.0503130Gт.1стр.330гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 65
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,4,'- ',0,0,'','','','code like ''___10904_____140110110''','{КОД СЧЕТА }=''___10904_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,4,4,'+ ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,5,4,'- ',0,0,'','','','code like ''___10905_____140110110''','{КОД СЧЕТА }=''___10905_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,6,4,'+ ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,7,4,'- ',0,0,'','','','code like ''___10906_____140110110''','{КОД СЧЕТА }=''___10906_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,8,4,'+ ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,9,4,'- ',0,0,'','','','code like ''___10907_____140110110''','{КОД СЧЕТА }=''___10907_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,10,4,'+ ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,11,4,'- ',0,0,'','','','code like ''___10903_____140110110''','{КОД СЧЕТА }=''___10903_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,12,4,'+ ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,13,4,'- ',0,0,'','','','code like ''___10902_____140110110''','{КОД СЧЕТА }=''___10902_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,14,4,'+ ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,15,4,'- ',0,0,'','','','code like ''___10901_____140110110''','{КОД СЧЕТА }=''___10901_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,16,4,'+ ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,17,4,'- ',0,0,'','','','code like ''___101_______140110110''','{КОД СЧЕТА }=''___101_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,18,4,'+ ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,19,4,'- ',0,0,'','','','code like ''___103_______140110110''','{КОД СЧЕТА }=''___103_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,20,4,'+ ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,21,4,'- ',0,0,'','','','code like ''___104_______140110110''','{КОД СЧЕТА }=''___104_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,22,4,'+ ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,23,4,'- ',0,0,'','','','code like ''___105_______140110110''','{КОД СЧЕТА }=''___105_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,24,4,'+ ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,25,4,'- ',0,0,'','','','code like ''___106_______140110110''','{КОД СЧЕТА }=''___106_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,26,4,'+ ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,27,4,'- ',0,0,'','','','code like ''___107_______140110110''','{КОД СЧЕТА }=''___107_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,28,4,'+ ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,29,4,'- ',0,0,'','','','code like ''___108_______140110110''','{КОД СЧЕТА }=''___108_______140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,30,4,'- ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,31,4,'+ ',0,0,'','','','code like ''___10909_____140110110''','{КОД СЧЕТА }=''___10909_____140110110''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,4,'+ ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,4,'- ',0,0,'','','','code like ''___10908_____140110140''','{КОД СЧЕТА }=''___10908_____140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,4,'+ ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,4,'- ',0,0,'','','','code like ''___115_______140110140''','{КОД СЧЕТА }=''___115_______140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,4,'+ ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,4,'- ',0,0,'','','','code like ''___116_______140110140''','{КОД СЧЕТА }=''___116_______140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,8,4,'+ ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,9,4,'- ',0,0,'','','','code like ''___1101104001140110140''','{КОД СЧЕТА }=''___1101104001140110140''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,4,'- ',0,0,'','','','code like ''___111_______140110120''','{КОД СЧЕТА }=''___111_______140110120''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,4,'+ ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,4,'- ',0,0,'','','','code like ''___112_______140110120''','{КОД СЧЕТА }=''___112_______140110120''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,2,4,'+ ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,3,4,'- ',0,0,'','','','code like ''___218_______140110151''','{КОД СЧЕТА }=''___218_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,4,4,'+ ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,5,4,'- ',0,0,'','','','code like ''___219_______140110151''','{КОД СЧЕТА }=''___219_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,6,4,'+ ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,7,4,'- ',0,0,'','','','code like ''___202_______140110151''','{КОД СЧЕТА }=''___202_______140110151''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,4,'+ ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,4,'- ',0,0,'','','','code like ''___113_______140110130''','{КОД СЧЕТА }=''___113_______140110130''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,2,4,'+ ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,3,4,'- ',0,0,'','','','code like ''___205_______140110152''','{КОД СЧЕТА }=''___205_______140110152''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,2,4,'+ ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,3,4,'- ',0,0,'','','','code like ''___10202_____140110160''','{КОД СЧЕТА }=''___10202_____140110160''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,2,4,'+ ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,3,4,'- ',0,0,'','','','code like ''___1_________140110173''','{КОД СЧЕТА }=''___1_________140110173''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,2,4,'+ ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,3,4,'- ',0,0,'','','','code like ''___11701_____140110180''','{КОД СЧЕТА }=''___11701_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,4,4,'+ ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,5,4,'- ',0,0,'','','','code like ''___11702_____140110180''','{КОД СЧЕТА }=''___11702_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,6,4,'+ ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,7,4,'- ',0,0,'','','','code like ''___11705_____140110180''','{КОД СЧЕТА }=''___11705_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,8,4,'+ ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,9,4,'- ',0,0,'','','','code like ''___11706_____140110180''','{КОД СЧЕТА }=''___11706_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,10,4,'+ ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,11,4,'- ',0,0,'','','','code like ''___11707_____140110180''','{КОД СЧЕТА }=''___11707_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,12,4,'+ ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,13,4,'- ',0,0,'','','','code like ''___11711_____140110180''','{КОД СЧЕТА }=''___11711_____140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,14,4,'+ ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,15,4,'- ',0,0,'','','','code like ''___218_______140110180''','{КОД СЧЕТА }=''___218_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,16,4,'+ ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,17,4,'- ',0,0,'','','','code like ''___201_______140110180''','{КОД СЧЕТА }=''___201_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,18,4,'+ ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,19,4,'- ',0,0,'','','','code like ''___203_______140110180''','{КОД СЧЕТА }=''___203_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,20,4,'+ ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,21,4,'- ',0,0,'','','','code like ''___207_______140110180''','{КОД СЧЕТА }=''___207_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,22,4,'+ ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,23,4,'- ',0,0,'','','','code like ''___204_______140110180''','{КОД СЧЕТА }=''___204_______140110180''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,2,4,'+ ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,3,4,'- ',0,0,'','','','code like ''___114_______140110172''','{КОД СЧЕТА }=''___114_______140110172''''','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,2,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,3,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,4,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,5,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,5,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','1','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,6,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,7,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,6,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,7,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,3,4,'+ ',0,0,'','','','CODE LIKE ''%1401202__''','по счетам счета 140120200','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120251''','{КОД СЧЕТА}=''140120251''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120252''','{КОД СЧЕТА}=''140120252''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120253''','{КОД СЧЕТА}=''140120253''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120272''','{КОД СЧЕТА}=''140120272''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120273''','{КОД СЧЕТА}=''140120273''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120211''','{КОД СЧЕТА}=''140120211''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120212''','{КОД СЧЕТА}=''140120212''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120213''','{КОД СЧЕТА}=''140120213''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120221''','{КОД СЧЕТА}=''140120221''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120222''','{КОД СЧЕТА}=''140120222''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120223''','{КОД СЧЕТА}=''140120223''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120224''','{КОД СЧЕТА}=''140120224''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120225''','{КОД СЧЕТА}=''140120225''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120226''','{КОД СЧЕТА}=''140120226''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120231''','{КОД СЧЕТА}=''140120231''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120232''','{КОД СЧЕТА}=''140120232''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120241''','{КОД СЧЕТА}=''140120241''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120242''','{КОД СЧЕТА}=''140120242''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120261''','{КОД СЧЕТА}=''140120261''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120263''','{КОД СЧЕТА}=''140120263''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120262''','{КОД СЧЕТА}=''140120262''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120271''','{КОД СЧЕТА}=''140120271''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,2,4,'+ ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','5','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,3,4,'- ',0,0,'','','','SUBSTRING(CODE,15,9)=''140120290''','{КОД СЧЕТА}=''140120290''','','',8,'     ','6','','2','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,8,4,'+ ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,9,4,'- ',0,0,'','','','CODE LIKE ''%401[12]0[12]__''','по счетам 040110100, 040120200','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,8,4,'+ ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,9,4,'- ',0,0,'','','','CODE LIKE ''%1401[12]0[12]__''','по счетам 140110100, 140120200','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,4,4,'+ ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,5,4,'- ',0,0,'','','','CODE LIKE ''%1401101__''','по счетам счета 140110100','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,4,4,'+ ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,5,4,'- ',0,0,'','','','code like ''___010502____140110172''','{КОД СЧЕТА }=''___010502____140110172''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,6,4,'+ ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,7,4,'- ',0,0,'','','','code like ''___010601____140110172''','{КОД СЧЕТА }=''___010601____140110172''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,4,4,'+ ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,5,4,'- ',0,0,'','','','code like ''___0102______140110173''','{КОД СЧЕТА }=''___0102______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,6,4,'+ ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,7,4,'- ',0,0,'','','','code like ''___0106______140110173''','{КОД СЧЕТА }=''___0106______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,8,4,'+ ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,9,4,'- ',0,0,'','','','code like ''___0202______140110173''','{КОД СЧЕТА }=''___0202______140110173''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,2,4,'+ ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','5','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,3,4,'- ',0,0,'','','','code like ''___010603____140110171''','{КОД СЧЕТА }=''___010603____140110171''','','',8,'     ','4','','3','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,11,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,8,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,9,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,10,0,'+ ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,11,0,'- ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,5,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,4,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,5,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,7,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,9,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,11,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,12,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,6,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121002000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,7,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130405000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,8,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,9,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130404000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,10,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,11,0,'- ',0,0,'','','','','','','',8,'     ','5','00000000000000000130406000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,12,0,'+ ',0,0,'','','','','','','',8,'     ','4','00000000000000000121004000','4','0503110G            ','20130101',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,3,0,'- ',0,0,'','','','','','','',8,'     ','3','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,4,0,'- ',0,0,'','','','','','','',8,'     ','6','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,5,0,'+ ',0,0,'','','','','','','',8,'     ','3','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,3,0,'- ',0,0,'','','','','','','',8,'     ','5','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,4,0,'- ',0,0,'','','','','','','',8,'     ','8','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,5,0,'+ ',0,0,'','','','','','','',8,'     ','5','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,3,0,'- ',0,0,'','','','','','','',8,'     ','4','400','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,4,0,'- ',0,0,'','','','','','','',8,'     ','4','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,5,0,'+ ',0,0,'','','','','','','',8,'     ','7','600','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,3,0,'- ',0,0,'','','','','','','',8,'     ','3','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,3,0,'- ',0,0,'','','','','','','',8,'     ','5','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','490','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,3,0,'- ',0,0,'','','','','','','',8,'     ','5','490','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','510','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,5,0,'- ',0,0,'','','','','','','',8,'     ','5','510','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','530','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,7,0,'- ',0,0,'','','','','','','',8,'     ','5','530','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','490','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,3,0,'- ',0,0,'','','','','','','',8,'     ','3','490','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','510','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,5,0,'- ',0,0,'','','','','','','',8,'     ','3','510','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,7,0,'- ',0,0,'','','','','','','',8,'     ','3','530','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,3,0,'- ',0,0,'','','','','','','',8,'     ','5','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,5,0,'- ',0,0,'','','','','','','',8,'     ','5','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','150','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,3,0,'- ',0,0,'','','','','','','',8,'     ','3','150','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,3,0,'- ',0,0,'','','','','','','',8,'     ','3','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,5,0,'- ',0,0,'','','','','','','',8,'     ','3','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,3,0,'- ',0,0,'','','','','','','',8,'     ','4','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,5,0,'- ',0,0,'','','','','','','',8,'     ','4','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,3,0,'- ',0,0,'','','','','','','',8,'     ','5','213','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,5,0,'- ',0,0,'','','','','','','',8,'     ','5','373','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,3,0,'- ',0,0,'','','','','','','',8,'     ','3','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,5,0,'- ',0,0,'','','','','','','',8,'     ','3','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,3,0,'- ',0,0,'','','','','','','',8,'     ','4','211','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,5,0,'- ',0,0,'','','','','','','',8,'     ','4','371','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,3,0,'- ',0,0,'','','','','','','',8,'     ','4','170','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','290','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,3,0,'- ',0,0,'','','','','','','',8,'     ','3','290','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','290','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,3,0,'- ',0,0,'','','','','','','',8,'     ','5','290','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,4,0,'- ',0,0,'','','','','','','',8,'     ','3','470','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,3,0,'- ',0,0,'','','','','','','',8,'     ','4','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,5,0,'- ',0,0,'','','','','','','',8,'     ','4','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,3,0,'- ',0,0,'','','','','','','',8,'     ','3','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,5,0,'- ',0,0,'','','','','','','',8,'     ','3','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,3,0,'- ',0,0,'','','','','','','',8,'     ','3','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,4,0,'+ ',0,0,'','','','','','','',8,'     ','6','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,5,0,'- ',0,0,'','','','','','','',8,'     ','3','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,6,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,7,0,'- ',0,0,'','','','','','','',8,'     ','3','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,8,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,9,0,'- ',0,0,'','','','','','','',8,'     ','3','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,10,0,'+ ',0,0,'','','','','','','',8,'     ','6','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,11,0,'- ',0,0,'','','','','','','',8,'     ','3','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,2,0,'+ ',0,0,'','','','','','','',8,'     ','7','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,3,0,'- ',0,0,'','','','','','','',8,'     ','4','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,4,0,'+ ',0,0,'','','','','','','',8,'     ','7','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,5,0,'- ',0,0,'','','','','','','',8,'     ','4','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,6,0,'+ ',0,0,'','','','','','','',8,'     ','7','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,7,0,'- ',0,0,'','','','','','','',8,'     ','4','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,8,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,9,0,'- ',0,0,'','','','','','','',8,'     ','4','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,10,0,'+ ',0,0,'','','','','','','',8,'     ','7','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,11,0,'- ',0,0,'','','','','','','',8,'     ','4','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,3,0,'+ ',0,0,'','','','','','','',8,'     ','8','470','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,4,0,'- ',0,0,'','','','','','','',8,'     ','5','470','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','150','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,3,0,'- ',0,0,'','','','','','','',8,'     ','5','150','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,3,0,'- ',0,0,'','','','','','','',8,'     ','5','230','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,5,0,'- ',0,0,'','','','','','','',8,'     ','5','260','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,6,0,'+ ',0,0,'','','','','','','',8,'     ','8','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,7,0,'- ',0,0,'','','','','','','',8,'     ','5','310','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,8,0,'+ ',0,0,'','','','','','','',8,'     ','8','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,9,0,'- ',0,0,'','','','','','','',8,'     ','5','320','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,10,0,'+ ',0,0,'','','','','','','',8,'     ','8','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,11,0,'- ',0,0,'','','','','','','',8,'     ','5','330','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,3,0,'- ',0,0,'','','','','','','',8,'     ','5','212','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,4,0,'+ ',0,0,'','','','','','','',8,'     ','8','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,5,0,'- ',0,0,'','','','','','','',8,'     ','5','372','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,2,0,'+ ',0,0,'','','','','','','',8,'     ','8','140','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,3,0,'- ',0,0,'','','','','','','',8,'     ','5','140','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (60,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','020','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (63,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (41,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','161','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (40,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (43,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','163','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (42,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','162','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (47,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','174','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (46,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','173','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (45,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','172','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (44,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','171','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (55,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','242','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (54,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','241','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (53,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','212','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (52,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','211','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (51,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','192','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (50,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','191','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (49,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','176','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (48,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','175','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (65,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (64,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','480','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (62,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (61,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','440','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (59,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','370','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (58,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','270','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (57,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','261','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (56,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','243','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (39,2,0,'+ ',0,0,'','','','','','','',8,'     ','6','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','520','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (38,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','530','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (37,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (36,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','460','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (35,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (34,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (33,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (32,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (31,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (22,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','231','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (21,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','310','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (24,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','233','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (23,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','232','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,2,0,'- ',0,0,'','','','','','','',8,'     ','6','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (27,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (26,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','263','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (25,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','262','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (30,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','470','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (29,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','420','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','290','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (28,3,0,'- ',0,0,'','','','','','','',8,'     ','4','110','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (10,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','093','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (13,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (16,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (15,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (14,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','410','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (19,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','150','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (20,2,0,'- ',0,0,'','','','','','','',8,'     ','4','280','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (18,1,0,'+ ',0,0,'','','','','','','',8,'     ','5','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (17,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','380','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (9,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','092','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (8,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','091','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (7,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','080','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','050','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (11,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','100','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (12,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','540','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (6,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','062','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','040','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (5,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','061','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','030','1','0503121G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 365
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (5,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (6,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (7,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (8,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (9,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (10,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (11,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (12,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (13,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (14,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (15,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (16,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (17,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (18,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (19,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (20,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (21,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (22,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (23,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (24,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (25,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (26,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (27,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (28,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (29,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (30,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (31,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (32,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (33,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (34,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (35,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (36,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (37,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (38,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (39,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (40,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (41,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (42,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (43,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (44,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (45,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (46,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (47,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (48,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (49,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (50,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (51,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (52,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (53,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (54,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (55,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (56,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (57,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (58,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (59,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (60,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (61,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (62,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (63,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (64,'2014_6')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (65,'2014_6')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 65
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_6'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_6' , 'Проверка:0503130G, 0503121G,0503110G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:02:277PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_7 - Проверка: 0503130G - 0503176G (4 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_7' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_7'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567414,7,0,0,0,'ф.0503130Gт.1стр.320гр.3 =  ф.0503176Gт.1стр.010гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567415,7,0,0,0,'ф.0503130Gт.1стр.320гр.4 =  ф.0503176Gт.1стр.010гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,567416,7,0,0,0,'ф.0503130Gт.1стр.320гр.6 =  ф.0503176Gт.1стр.060гр.4',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,567417,7,0,0,0,'ф.0503130Gт.1стр.320гр.7 =  ф.0503176Gт.1стр.060гр.5',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','010','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','010','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','4','060','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','060','1','0503176G            ','20130101',NULL,'',1,NULL,1,'@@OPTIONAL',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','3','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','6','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','4','320','1','0503130G            ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 8
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_7')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_7')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'2014_7')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'2014_7')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_7'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_7' , 'Проверка: 0503130G - 0503176G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 19 2015  5:06:09:280PM)
-- Выгружены следующие группы междокументных КС:
-- 2014_8 - Заполнение и Проверка: 0503173G_СВ из 0503130G (2 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = '2014_8' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = '2014_8'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,567524,7,0,0,0,'ф.0503173G_СВт.1гр.4 =  ф.0503130Gт.1гр.4',1,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',0,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,567525,7,0,0,0,'ф.0503173G_СВт.1гр.3 =  ф.0503130Gт.1[12м2013г]',1,0,0,'20141230','CODE not in (''512'',''515'',''516'')','','','',NULL,'Тамбов                                                                                              ','=',0,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,4,'+ ',0,0,'','','','CODE not in (''610'',''800'')','','CODE','',8,'     ','4','','1','0503173G_СВ         ','20121231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,4,'+ ',0,0,'','','','CODE not in (''610'',''800'')','','CODE','',8,'     ','3','','1','0503173G_СВ         ','20121231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,4,'+ ',12,0,'','','','1=1','','CODE','',8,'     ','','','1','0503130G            ','20130101',2013,'',1,'20131231',1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,4,'+ ',0,0,'','','','1=1','','CODE','',8,'     ','4','','1','0503130G            ','20141231',NULL,'',1,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'2014_8')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'2014_8')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 2
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = '2014_8'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, '2014_8' , 'Заполнение и Проверка: 0503173G_СВ из 0503130G', 0, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Сгенерировано х.п. RA_EXPORT_GROUP_KS. (янв 21 2015  9:36:06:480AM)
-- Выгружены следующие группы междокументных КС:
-- rk_737_1 - Проверка форм 0503737G - 0503730G (4 шт.)
-- Параметры выгрузки:
-- удаление старых КС : да

SET NOCOUNT               ON
SET ANSI_NULLS            ON
SET ANSI_WARNINGS         ON  -- При возникновении ошибки транзакция не прерывается.
SET IMPLICIT_TRANSACTIONS OFF -- Режим явного определения транзакций.
SET LOCK_TIMEOUT          -1  -- Бесконечное время ожидания разблокировки ресурсов.

BEGIN TRANSACTION         -- Начало новой транзакции.
SAVE TRANSACTION SaveTran -- Создание точки сохранения.

IF OBJECT_ID('tempdb..#tabErrorLog') IS NOT NULL
BEGIN
   DROP TABLE #tabErrorLog
END
CREATE TABLE #tabErrorLog([PROC] VARCHAR(250),[ERROR] INT)

----------------------------------------------------------------------------------------------------
-- Раздел удаления правил.

DELETE
FROM dbo.[REPORT_CONTROL_RULES]
WHERE [LINK_RULE] IN (SELECT [A].[LINK_RULE]
                      FROM dbo.[REPORT_CONTROL_GROUP] [A]
                      JOIN dbo.[REPORT_GROUP_KS]      [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
                      WHERE [B].[CODE] = 'rk_737_1' AND
                            (SELECT COUNT(*)
                             FROM dbo.[REPORT_CONTROL_GROUP] [C]
                             WHERE [C].[LINK_RULE] = [A].[LINK_RULE]) = 1)

DELETE [B]
FROM dbo.[REPORT_GROUP_KS]      [A]
JOIN dbo.[REPORT_CONTROL_GROUP] [B] ON [A].[LINK_GROUP_KS] = [B].[LINK_GROUP_KS]
WHERE [A].[CODE] = 'rk_737_1'

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения правил.
DECLARE @iERROR INT

IF OBJECT_ID('tempdb..#tabRULES') IS NOT NULL
BEGIN
   DROP TABLE #tabRULES
END

CREATE TABLE #tabRULES ([LINK_RULE]       INT NULL,
                        [LINK_TASK]       INT NULL,
                        [IsOutside]       TINYINT NULL,
                        [LINK_FORM]       INT NULL,
                        [OrderRule]       INT NULL,
                        [PERIOD]          SMALLINT NULL,
                        [PERIOD_NOM]      SMALLINT NULL,
                        [ORG_LEVEL]       SMALLINT NULL,
                        [IsSvod]          SMALLINT NULL,
                        [STR_RULE]        VARCHAR (6000) NULL,
                        [IsDoschet]       TINYINT NULL,
                        [CALC_ORDERS]     INT NULL,
                        [IsSystemsRule]   TINYINT NULL ,
                        [MODIFY_DATE]     DATETIME NULL,
                        [ROWS]            VARCHAR(1000),
                        [COLS]            VARCHAR(250),
                        [ROWS_DESC]       VARCHAR (250),
                        [CODE_FORM]       VARCHAR (250),
                        [START_DATE_FORM] VARCHAR (250),
                        [REGION]			 VARCHAR (100),
                        [SIGN_SR]         CHAR(2)      NOT NULL,
                        [ALGORITHM]       TINYINT      NOT NULL,
                        [ATR_CODE_SR]     VARCHAR(254) NOT NULL,
                        [COMMENT]     VARCHAR(8000))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabRULES',@iERROR)
END

GO

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (1,1,568059,7,0,0,0,'ф.0503730G_BUт.2стр.171гр.7 =  |ф.0503737Gт.1стр.710гр.5(код вида 5)| +  |ф.0503737Gт.1стр.710гр.6(код вида 5)|',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (2,1,568060,7,0,0,0,'ф.0503730G_BUт.2стр.171гр.8 =  |ф.0503737Gт.1стр.710гр.5(код вида 2)| +  |ф.0503737Gт.1стр.710гр.6(код вида 2)| +  |ф.0503737Gт.1стр.710гр.5(код вида 4)| +  |ф.0503737Gт.1стр.710гр.6(код вида 4)| +  |ф.0503737Gт.1стр.710гр.5(код вида 7)| +  |ф.0503737Gт.1стр.710гр.6(код вида 7)|',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (3,1,568061,7,0,0,0,'ф.0503730G_BUт.2стр.180гр.7 =  ф.0503737Gт.1стр.720гр.5(код вида 5) +  ф.0503737Gт.1стр.720гр.6(код вида 5)',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')

INSERT #tabRULES ([LINK_RULE],[IsOutside],[OrderRule],[PERIOD],[PERIOD_NOM],[ORG_LEVEL],[IsSvod],[STR_RULE],[IsDoschet],[CALC_ORDERS],[IsSystemsRule],[MODIFY_DATE],[ROWS],[COLS],[ROWS_DESC],[CODE_FORM],[START_DATE_FORM],[REGION],[SIGN_SR],[ALGORITHM],[ATR_CODE_SR],[COMMENT])
VALUES (4,1,568062,7,0,0,0,'ф.0503730G_BUт.2стр.181гр.8 =  ф.0503737Gт.1стр.720гр.5(код вида 2) +  ф.0503737Gт.1стр.720гр.6(код вида 2) +  ф.0503737Gт.1стр.720гр.5(код вида 4) +  ф.0503737Gт.1стр.720гр.6(код вида 4) +  ф.0503737Gт.1стр.720гр.5(код вида 7) +  ф.0503737Gт.1стр.720гр.6(код вида 7)',0,0,1,'20141230','','','','',NULL,'                                                                                                    ','=',1,'','')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRules',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabROWS') IS NOT NULL
BEGIN
   DROP TABLE #tabROWS
END

CREATE TABLE #tabROWS ([LINK_RULE]       INT NULL,
                       [OrderRow]        INT NULL,
                       [VAL_TYPE]        TINYINT NULL,
                       [SIGN]            CHAR(2) NULL,
                       [LINK_FORM]       INT NULL,
                       [LINK_TABLE]      INT NULL,
                       [LINK_COL]        INT NULL,
                       [LINK_ROW]        INT NULL,
                       [PERIOD_FORM]     SMALLINT NULL,
                       [FACTOR]          FLOAT NULL,
                       [EXEC_PROC]       VARCHAR(250) NULL,
                       [EXEC_PROC_DESC]  VARCHAR(250) NULL,
                       [CODE_ROW]        VARCHAR(250) NULL,
                       [FILTER]          VARCHAR(1000) NULL,
                       [FILTER_DESC]     VARCHAR(250) NULL,
                       [MASKA]           VARCHAR(250) NULL,
                       [MASKA_DESC]      VARCHAR(250) NULL,
                       [PERIOD_TYPE]     TINYINT,
                       [BUDG_CODE]       CHAR(5),
                       [CODE_FORM_ROW]   VARCHAR(25)  NULL,
                       [COL]             VARCHAR(100) NULL,
                       [ROW]             VARCHAR(100) NULL,
                       [TABLE]           VARCHAR(25)  NULL,
                       [START_DATE_FORM] DATETIME     NULL,
                       [PERIOD_YEAR]     SMALLINT     NULL,
                       [ATR_CODE]        VARCHAR(254) NOT NULL,
                       [PART]            TINYINT      NOT NULL,
                       [BEGIN_DATE]      DATETIME     NULL,
                       [PX]              FLOAT(53)    NOT NULL,
                       [PX_COMMENT]      VARCHAR(600) NOT NULL,
                       [PROPERTY]        TINYINT      DEFAULT (0))

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabROWS',@iERROR)
END

GO

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','710','1','0503737G            ','20121231',NULL,'#2',1,NULL,1,'(код вида 2)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','710','1','0503737G            ','20121231',NULL,'#2',1,NULL,1,'(код вида 2)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','710','1','0503737G            ','20121231',NULL,'#4',1,NULL,1,'(код вида 4)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','710','1','0503737G            ','20121231',NULL,'#4',1,NULL,1,'(код вида 4)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','710','1','0503737G            ','20121231',NULL,'#7',1,NULL,1,'(код вида 7)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','710','1','0503737G            ','20121231',NULL,'#7',1,NULL,1,'(код вида 7)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','710','1','0503737G            ','20121231',NULL,'#5',1,NULL,1,'(код вида 5)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','710','1','0503737G            ','20121231',NULL,'#5',1,NULL,1,'(код вида 5)',3)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','720','1','0503737G            ','20121231',NULL,'#5',1,NULL,1,'(код вида 5)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','720','1','0503737G            ','20121231',NULL,'#5',1,NULL,1,'(код вида 5)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,2,0,'+ ',0,0,'','','','','','','',8,'     ','5','720','1','0503737G            ','20121231',NULL,'#2',1,NULL,1,'(код вида 2)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,3,0,'+ ',0,0,'','','','','','','',8,'     ','6','720','1','0503737G            ','20121231',NULL,'#2',1,NULL,1,'(код вида 2)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,4,0,'+ ',0,0,'','','','','','','',8,'     ','5','720','1','0503737G            ','20121231',NULL,'#4',1,NULL,1,'(код вида 4)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,5,0,'+ ',0,0,'','','','','','','',8,'     ','6','720','1','0503737G            ','20121231',NULL,'#4',1,NULL,1,'(код вида 4)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,6,0,'+ ',0,0,'','','','','','','',8,'     ','5','720','1','0503737G            ','20121231',NULL,'#7',1,NULL,1,'(код вида 7)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,7,0,'+ ',0,0,'','','','','','','',8,'     ','6','720','1','0503737G            ','20121231',NULL,'#7',1,NULL,1,'(код вида 7)',1)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (1,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','171','2','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (4,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','181','2','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (2,1,0,'+ ',0,0,'','','','','','','',8,'     ','8','171','2','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)

INSERT #tabROWS ([LINK_RULE],[OrderRow],[VAL_TYPE],[SIGN],[PERIOD_FORM],[FACTOR],[EXEC_PROC],[EXEC_PROC_DESC],[CODE_ROW],[FILTER],[FILTER_DESC],[MASKA],[MASKA_DESC],[PERIOD_TYPE],[BUDG_CODE],[COL],[ROW],[TABLE],[CODE_FORM_ROW],[START_DATE_FORM],[PERIOD_YEAR],[ATR_CODE],[PART],[BEGIN_DATE],[PX],[PX_COMMENT],[PROPERTY])
VALUES (3,1,0,'+ ',0,0,'','','','','','','',8,'     ','7','180','2','0503730G_BU         ','20141231',NULL,'',0,NULL,1,'',0)


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabRows) <> 20
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabRows',0)
END

GO

DECLARE @iERROR INT
IF OBJECT_ID('tempdb..#tabGroupRules') IS NOT NULL
BEGIN
   DROP TABLE #tabGroupRules
END

CREATE TABLE #tabGroupRules ([GROUP_CODE] VARCHAR(20) NOT NULL,
                             [LINK_RULE]  INT         NOT NULL)

SELECT @iERROR = @@ERROR

IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('CREATE TABLE #tabGroupRules',@iERROR)
END

GO
INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (1,'rk_737_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (2,'rk_737_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (3,'rk_737_1')

INSERT #tabGroupRules ([LINK_RULE],[GROUP_CODE])
VALUES (4,'rk_737_1')


GO

DECLARE @iERROR INT

IF (SELECT COUNT(*) FROM #tabGroupRules) <> 4
BEGIN
   INSERT #tabErrorLog VALUES ('Не сошлось количество строк в #tabGroupRules',0)
END

GO

----------------------------------------------------------------------------------------------------
-- Раздел сохранения групп.
DECLARE @vcGROUP_CODE CHAR(20), @iGROUP_LINK INT, @iLINK_RULE INT

SELECT @iGROUP_LINK = [LINK] FROM dbo.[RA_VIEW_GROUP_KS] WHERE [CODE] = 'rk_737_1'
EXEC dbo.[RA_SAVE_GROUP_KS] @iGROUP_LINK OUTPUT, 'rk_737_1' , 'Проверка форм 0503737G - 0503730G', 1, 0, '20141231', NULL

GO

DECLARE @iERROR INT

CREATE INDEX #IX_tabROWS ON #tabROWS([LINK_RULE])
CREATE INDEX #IX_tabRULES ON #tabRULES([LINK_RULE])

-- Импорт правил во временные таблицы.
EXEC @iERROR = dbo.[RN_IMPORT_RULES] '#tabRULES', '#tabROWS', 1, '#tabGroupRules'
IF @iERROR <> 0
BEGIN
   INSERT #tabErrorLog VALUES ('RN_IMPORT_RULES',@iERROR)
END
SELECT * FROM #tabErrorLog

IF EXISTS(SELECT * FROM #tabErrorLog)
BEGIN
   ROLLBACK TRANSACTION SaveTran -- Восстановление точки сохранения.
END

DROP TABLE #tabErrorLog

COMMIT TRANSACTION -- Фиксация транзакции.
GO


GO
-- Перенос табличной части в документе Акт списания мягкого и хоз. инвентаря --
-- OUT_TABLE_INV_TYPE --
INSERT INTO dbo.OUT_TABLE_INV_TYPE
	(
	LINK_UP,
	INV_TYPE,
	INV,
	NOMEN,
	TMC
	)
SELECT
	OTR.LINK,
	OTC.STRING,
	OTI.INVENTORY,
	OTN.NOMENCLATURE,
	NULL
FROM dbo.OUT_TABLE_ROW OTR
LEFT JOIN dbo.OUT_TABLE_STRING OTC ON (OTC.OBJECT = dbo.XA_GET_SO_LINK('BA_MP_CHARGE_TABLE_TYPE')
	AND OTC.LINK_UP = OTR.LINK)
LEFT JOIN dbo.OUT_TABLE_NOMENCLATURE OTN ON
			(
			OTC.STRING = 'BV_NOMENCLATURE'
            AND OTN.[OBJECT] = dbo.XA_GET_SO_LINK('BA_MP_CHARGE_TABLE_LINK')
			AND OTN.LINK_UP = OTR.LINK
			)
LEFT JOIN dbo.OUT_TABLE_INVENTORY OTI ON
			(
			OTC.STRING = 'INVENTORY_CARD'
            AND OTI.[OBJECT] = dbo.XA_GET_SO_LINK('BA_MP_CHARGE_TABLE_LINK')
			AND OTI.LINK_UP = OTR.LINK
			)
WHERE
	OTR.[OBJECT] = dbo.XA_GET_SO_LINK ('BA_DOC_MP_CHARGE_TABLE')
	AND NOT EXISTS (SELECT * FROM dbo.OUT_TABLE_INV_TYPE TTT WHERE TTT.LINK_UP = OTR.LINK)

-- OUT_TABLE_INV_TYPE --
INSERT INTO dbo.OUT_TABLE_MZ_CHARGE
	(
	LINK_UP,
	ACCOUNT,
	NOMEN,
	QTY_REST,
	QTY,
	SUMMA,
	PRICE,
	PRICE_FACT
	)
SELECT DISTINCT
	OTR.LINK,
	ACCOUNT = NULL,
	NOMEN = NULL,
	QTY_REST = 0,
	QTY = OTS.SUMMA,
	SUMMA = 0,
	PRICE = 0,
	PRICE_FACT = 0
FROM dbo.OUT_TABLE_ROW OTR
INNER JOIN dbo.G_PROV G ON (G.LINK = OTR.LINK_UP)
LEFT JOIN dbo.G_PROV_EMPL GPE ON (GPE.DOC_LINK = G.LINK
	AND GPE.[OBJECT] = dbo.XA_GET_SO_LINK('BA_DOC_MP_CHARGE_MOL_LINK'))
LEFT JOIN dbo.OUT_TABLE_SUMMA  OTS ON (OTS.[OBJECT] = dbo.XA_GET_SO_LINK('BA_MP_CHARGE_TABLE_QTY')
	AND OTS.LINK_UP = OTR.LINK)
WHERE
	OTR.[OBJECT] = dbo.XA_GET_SO_LINK ('BA_DOC_MP_CHARGE_TABLE')
	AND NOT EXISTS (SELECT * FROM dbo.OUT_TABLE_MZ_CHARGE TTT WHERE TTT.LINK_UP = OTR.LINK)
GO



GO
EXEC dbo.X_UPDATE_DELETE_TRIGGERS
GO


GO
