One
4 - 23.07.2009 - 05:21
|
exec sp_executesql N'SELECT #V8TblAli1_Q_000_T_001._Q_001_F_000 AS f_1, #V8TblAli1_Q_000_T_001._Q_001_F_003RRef AS _sf_3RRef, #V8TblAli1_Q_000_T_001._Q_001_F_001RRef AS _sf_2RRef, #V8TblAli1_Q_000_T_001._Q_001_F_002 AS _sf_1, #V8TblAli1_Q_000_T_001._Q_001_F_004 AS _sf_5, #V8TblAli1_Q_000_T_001._Q_001_F_005 AS _sf_4, #V8TblAli1_Q_000_T_001._Q_001_F_006 AS f_2, #V8TblAli1_Q_000_T_001._Q_001_F_007 AS f_3, #V8TblAli1_Q_000_T_001._Q_001_F_008 AS f_4, #V8TblAli1_Q_000_T_001._Q_001_F_009 AS f_5, #V8TblAli1_Q_000_T_001._Q_001_F_010 AS f_6, #V8TblAli1_Q_000_T_001._Q_001_F_011 AS f_7, #V8TblAli1_Q_000_T_001._Q_001_F_012 AS f_8, #V8TblAli1_Q_000_T_001._Q_001_F_013 AS f_9 FROM ( SELECT CASE WHEN _CalcKind2._Fld387 = 0x01 THEN N''ДоходыВНатуральнойФорме'' ELSE CAST(N''Начислено'' AS NVARCHAR(23)) END COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _CalcReg580_Q_001_T_001._Fld609RRef AS _Q_001_F_001RRef, _CalcReg580_Q_001_T_001._Period AS _Q_001_F_002, _CalcReg580_Q_001_T_001._Fld582RRef AS _Q_001_F_003RRef, _CalcKind2._Description + CASE WHEN ISNULL(_Reference88._Fld1115RRef, 0x00000000000000000000000000000000) <> 0xbf5c36869f474e744c274fc8bb98f298 THEN CAST(CAST(N'''' AS NVARCHAR(1)) AS NVARCHAR(23)) ELSE N'' (по внутр. совмест-ву)'' END COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''А'' + CASE WHEN _CalcKind2._Fld378 = 0x01 THEN N''А'' ELSE N''Б'' END + CASE WHEN _CalcKind2._Fld379 = 0x01 THEN N''А'' ELSE N''Б'' END + _Reference6623._Code + _CalcKind2._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(SUM(_CalcReg580_Q_001_T_001._Fld586) AS NUMERIC(13,2)) AS _Q_001_F_006, CAST(SUM(_CalcReg580_Q_001_T_001._Fld587) AS NUMERIC(13,2)) AS _Q_001_F_007, CAST(SUM(CASE WHEN _CalcReg580_Q_001_T_001._Fld597RRef = 0x838caab601043bf9442b9053a4c11d6e THEN _CalcReg580_Q_001_T_001._Fld592 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END) AS NUMERIC(21,2)) AS _Q_001_F_008, CAST(SUM(CASE WHEN _CalcReg580_Q_001_T_001._Fld597RRef <> 0x838caab601043bf9442b9053a4c11d6e THEN _CalcReg580_Q_001_T_001._Fld592 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END) AS NUMERIC(21,2)) AS _Q_001_F_009, CAST(CAST(SUM(_CalcReg580_Q_001_T_001._Fld585) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _CalcReg580 _CalcReg580_Q_001_T_001 WITH(NOLOCK) LEFT OUTER JOIN _CalcKind2 WITH(NOLOCK) ON _CalcReg580_Q_001_T_001._CalcKindRRef = _CalcKind2._IDRRef LEFT OUTER JOIN _Reference88 WITH(NOLOCK) ON _CalcReg580_Q_001_T_001._Fld581RRef = _Reference88._IDRRef LEFT OUTER JOIN _Reference6623 WITH(NOLOCK) ON _CalcKind2._Fld6698RRef = _Reference6623._IDRRef WHERE _CalcReg580_Q_001_T_001._Period >= @P1 AND _CalcReg580_Q_001_T_001._Period <= @P2 AND NOT (_CalcReg580_Q_001_T_001._Fld586 = CAST(@P3 AS NUMERIC(1,0)) AND _CalcReg580_Q_001_T_001._Fld587 = CAST(@P3 AS NUMERIC(1,0)) AND CASE WHEN _CalcReg580_Q_001_T_001._Fld597RRef = 0x838caab601043bf9442b9053a4c11d6e THEN _CalcReg580_Q_001_T_001._Fld592 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END = CAST(@P3 AS NUMERIC(1,0)) AND CASE WHEN _CalcReg580_Q_001_T_001._Fld597RRef = 0xa66321972fe2522f4a66da9eeb3ec487 THEN _CalcReg580_Q_001_T_001._Fld592 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END = CAST(@P3 AS NUMERIC(1,0)) AND _CalcReg580_Q_001_T_001._Fld585 = CAST(@P3 AS NUMERIC(1,0))) AND _CalcReg580_Q_001_T_001._Fld582RRef = @P4 GROUP BY CASE WHEN _CalcKind2._Fld387 = 0x01 THEN N''ДоходыВНатуральнойФорме'' ELSE CAST(N''Начислено'' AS NVARCHAR(23)) END COLLATE Cyrillic_General_CI_AS, _CalcReg580_Q_001_T_001._Period, _CalcReg580_Q_001_T_001._Fld582RRef, _CalcKind2._Description + CASE WHEN ISNULL(_Reference88._Fld1115RRef, 0x00000000000000000000000000000000) <> 0xbf5c36869f474e744c274fc8bb98f298 THEN CAST(CAST(N'''' AS NVARCHAR(1)) AS NVARCHAR(23)) ELSE N'' (по внутр. совмест-ву)'' END COLLATE Cyrillic_General_CI_AS, CAST(N''А'' + CASE WHEN _CalcKind2._Fld378 = 0x01 THEN N''А'' ELSE N''Б'' END + CASE WHEN _CalcKind2._Fld379 = 0x01 THEN N''А'' ELSE N''Б'' END + _Reference6623._Code + _CalcKind2._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS, _CalcReg580_Q_001_T_001._Fld609RRef UNION ALL SELECT CASE WHEN _CalcKind1._Fld361 = 0x01 THEN N''ДоходыВНатуральнойФорме'' ELSE CAST(N''Начислено'' AS NVARCHAR(23)) END COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _CalcReg521_Q_002_T_001._Fld541RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _CalcReg521_Q_002_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _CalcReg521_Q_002_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _CalcReg521_Q_002_T_001._Fld523RRef AS _Q_001_F_003RRef, _CalcKind1._Description + CASE WHEN ISNULL(_Reference88._Fld1115RRef, 0x00000000000000000000000000000000) <> 0xbf5c36869f474e744c274fc8bb98f298 THEN CAST(CAST(N'''' AS NVARCHAR(1)) AS NVARCHAR(23)) ELSE N'' (по внутр. совмест-ву)'' END COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''БААА'' + _CalcKind1._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(SUM(CASE WHEN _CalcReg521_Q_002_T_001._Fld544RRef = 0x838caab601043bf9442b9053a4c11d6e THEN _CalcReg521_Q_002_T_001._Fld527 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END) AS NUMERIC(21,2)) AS _Q_001_F_008, CAST(SUM(CASE WHEN _CalcReg521_Q_002_T_001._Fld544RRef = 0xa66321972fe2522f4a66da9eeb3ec487 THEN _CalcReg521_Q_002_T_001._Fld527 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END) AS NUMERIC(21,2)) AS _Q_001_F_009, CAST(CAST(SUM(_CalcReg521_Q_002_T_001._Fld526) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _CalcReg521 _CalcReg521_Q_002_T_001 WITH(NOLOCK) LEFT OUTER JOIN _Reference88 WITH(NOLOCK) ON _CalcReg521_Q_002_T_001._Fld522RRef = _Reference88._IDRRef LEFT OUTER JOIN _CalcKind1 WITH(NOLOCK) ON _CalcReg521_Q_002_T_001._CalcKindRRef = _CalcKind1._IDRRef WHERE _CalcReg521_Q_002_T_001._Period >= @P1 AND _CalcReg521_Q_002_T_001._Period <= @P2 AND NOT (_CalcReg521_Q_002_T_001._Fld526 = CAST(@P3 AS NUMERIC(1,0)) AND CASE WHEN _CalcReg521_Q_002_T_001._Fld544RRef = 0x838caab601043bf9442b9053a4c11d6e THEN _CalcReg521_Q_002_T_001._Fld527 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END = CAST(@P3 AS NUMERIC(1,0)) AND CASE WHEN _CalcReg521_Q_002_T_001._Fld544RRef = 0xa66321972fe2522f4a66da9eeb3ec487 THEN _CalcReg521_Q_002_T_001._Fld527 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(15,2)) END = CAST(@P3 AS NUMERIC(1,0))) AND _CalcReg521_Q_002_T_001._Fld523RRef = @P4 GROUP BY CASE WHEN _CalcKind1._Fld361 = 0x01 THEN N''ДоходыВНатуральнойФорме'' ELSE CAST(N''Начислено'' AS NVARCHAR(23)) END COLLATE Cyrillic_General_CI_AS, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _CalcReg521_Q_002_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _CalcReg521_Q_002_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _CalcReg521_Q_002_T_001._Fld523RRef, _CalcKind1._Description + CASE WHEN ISNULL(_Reference88._Fld1115RRef, 0x00000000000000000000000000000000) <> 0xbf5c36869f474e744c274fc8bb98f298 THEN CAST(CAST(N'''' AS NVARCHAR(1)) AS NVARCHAR(23)) ELSE N'' (по внутр. совмест-ву)'' END COLLATE Cyrillic_General_CI_AS, CAST(N''БААА'' + _CalcKind1._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS, _CalcReg521_Q_002_T_001._Fld541RRef UNION ALL SELECT N''ДоходыВНатуральнойФорме'' COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _AccumReg6279_Q_003_T_001._Fld6287RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6279_Q_003_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6279_Q_003_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _AccumReg6279_Q_003_T_001._Fld6281RRef AS _Q_001_F_003RRef, CAST(N''Мат. выгода по займам (кредитам)'' AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''БААА9'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(CAST(SUM(_AccumReg6279_Q_003_T_001._Fld6284) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _AccumReg6279 _AccumReg6279_Q_003_T_001 WITH(NOLOCK) WHERE _AccumReg6279_Q_003_T_001._Period >= @P1 AND _AccumReg6279_Q_003_T_001._Period <= @P2 AND _AccumReg6279_Q_003_T_001._Fld6282RRef IN (@P5,@P6) AND _AccumReg6279_Q_003_T_001._Fld6288 = @P7 AND _AccumReg6279_Q_003_T_001._Fld6284 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6279_Q_003_T_001._Fld6281RRef = @P4 GROUP BY DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6279_Q_003_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6279_Q_003_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6279_Q_003_T_001._Fld6281RRef, _AccumReg6279_Q_003_T_001._Fld6287RRef UNION ALL SELECT CAST(N''Удержано'' AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _CalcReg645_Q_004_T_001._Fld662RRef AS _Q_001_F_001RRef, _CalcReg645_Q_004_T_001._Period AS _Q_001_F_002, _CalcReg645_Q_004_T_001._Fld646RRef AS _Q_001_F_003RRef, CAST(_CalcKind4._Description AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''АААА'' + _CalcKind4._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(CAST(SUM(_CalcReg645_Q_004_T_001._Fld648) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _CalcReg645 _CalcReg645_Q_004_T_001 WITH(NOLOCK) LEFT OUTER JOIN _CalcKind4 WITH(NOLOCK) ON _CalcReg645_Q_004_T_001._CalcKindRRef = _CalcKind4._IDRRef WHERE _CalcReg645_Q_004_T_001._Period >= @P1 AND _CalcReg645_Q_004_T_001._Period <= @P2 AND _CalcReg645_Q_004_T_001._Fld648 <> CAST(@P3 AS NUMERIC(1,0)) AND _CalcReg645_Q_004_T_001._Fld646RRef = @P4 GROUP BY _CalcReg645_Q_004_T_001._Period, _CalcReg645_Q_004_T_001._Fld646RRef, /* Вот здесь, если убрать COLLATE Cyrillic_General_CI_AS, то работает нормально и ошибок не выдаёт*/ _CalcKind4._Description COLLATE Cyrillic_General_CI_AS, CAST(N''АААА'' + _CalcKind4._Code AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS, _CalcReg645_Q_004_T_001._Fld662RRef UNION ALL SELECT CAST(N''Удержано'' AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _AccumReg6258_Q_005_T_001._Fld6267RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6258_Q_005_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6258_Q_005_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _AccumReg6258_Q_005_T_001._Fld6259RRef AS _Q_001_F_003RRef, CAST(CASE WHEN _AccumReg6258_Q_005_T_001._Fld6268RRef = 0x88c6df0df16e570c49796f904c0304ad THEN N''НДФЛ возврат налога'' ELSE CAST(N''НДФЛ исчисленный '' AS NVARCHAR(19)) END AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''БААА'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(CAST(SUM(_AccumReg6258_Q_005_T_001._Fld6263) AS NUMERIC(19,0)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _AccumReg6258 _AccumReg6258_Q_005_T_001 WITH(NOLOCK) WHERE _AccumReg6258_Q_005_T_001._Fld6269 = @P7 AND _AccumReg6258_Q_005_T_001._Period >= @P1 AND _AccumReg6258_Q_005_T_001._Period <= @P2 AND _AccumReg6258_Q_005_T_001._Fld6268RRef IN (@P8) AND _AccumReg6258_Q_005_T_001._Fld6263 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6258_Q_005_T_001._Fld6259RRef = @P4 GROUP BY DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6258_Q_005_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6258_Q_005_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6258_Q_005_T_001._Fld6259RRef, _AccumReg6258_Q_005_T_001._Fld6267RRef, CAST(CASE WHEN _AccumReg6258_Q_005_T_001._Fld6268RRef = 0x88c6df0df16e570c49796f904c0304ad THEN N''НДФЛ возврат налога'' ELSE CAST(N''НДФЛ исчисленный '' AS NVARCHAR(19)) END AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS UNION ALL SELECT CAST(N''Удержано'' AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _AccumReg6323_Q_006_T_001._Fld6325RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6323_Q_006_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6323_Q_006_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _AccumReg6323_Q_006_T_001._Fld6324RRef AS _Q_001_F_003RRef, CAST(N''Погашение займа'' AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''ВААА'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(SUM(_AccumReg6323_Q_006_T_001._Fld6327 + _AccumReg6323_Q_006_T_001._Fld6328) AS NUMERIC(22,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _AccumReg6323 _AccumReg6323_Q_006_T_001 WITH(NOLOCK) WHERE _AccumReg6323_Q_006_T_001._RecordKind = CAST(@P9 AS NUMERIC(1,0)) AND _AccumReg6323_Q_006_T_001._Period >= @P1 AND _AccumReg6323_Q_006_T_001._Period <= @P2 AND _AccumReg6323_Q_006_T_001._Fld6329 = @P7 AND _AccumReg6323_Q_006_T_001._Fld6327 + _AccumReg6323_Q_006_T_001._Fld6328 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6323_Q_006_T_001._Fld6324RRef = @P4 GROUP BY _AccumReg6323_Q_006_T_001._Fld6326RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6323_Q_006_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6323_Q_006_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6323_Q_006_T_001._Fld6325RRef, _AccumReg6323_Q_006_T_001._Fld6324RRef UNION ALL SELECT CAST(N''Выплата'' AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _AccumReg6170_Q_007_T_001._Fld6172RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170_Q_007_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170_Q_007_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _AccumReg6170_Q_007_T_001._Fld6171RRef AS _Q_001_F_003RRef, CAST(CASE WHEN NOT _AccumReg6170_Q_007_T_001._RecorderTRef = 0x0000007E THEN CASE WHEN _AccumReg6170_Q_007_T_001._Fld6176RRef = 0xb17249345e902311426eb61a0c1e1f85 THEN CAST(N''Через кассу '' AS NVARCHAR(25)) WHEN _AccumReg6170_Q_007_T_001._Fld6176RRef = 0x8dfbbe1a60552b394e1560dbe3ca9417 THEN CAST(N''Перечислено в банк '' AS NVARCHAR(25)) ELSE N''Способ выплаты не указан '' END + CASE WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef IN (0xbdb467d57dea73474e67e741b52036a5,0xad17dfc84e55d4aa458f5d60b238960e) THEN CAST(N''(аванс)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x8cea26a3252a789146cc4239f036668b THEN CAST(N''(под расчет)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x00000000000000000000000000000000 AND _AccumReg6170_Q_007_T_001._Fld6174 > CAST(0. AS NUMERIC(1,0)) THEN CAST(N''(не указано)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x00000000000000000000000000000000 AND _AccumReg6170_Q_007_T_001._Fld6174 < CAST(0. AS NUMERIC(1,0)) THEN N''(погашено задолженности)'' ELSE CAST(N''(межрасчет)'' AS NVARCHAR(24)) END ELSE CAST(N''Задепонировано'' AS NVARCHAR(49)) END AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''ГААА1'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(CAST(SUM(_AccumReg6170_Q_007_T_001._Fld6174) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _AccumReg6170 _AccumReg6170_Q_007_T_001 WITH(NOLOCK) WHERE _AccumReg6170_Q_007_T_001._RecordKind = CAST(@P9 AS NUMERIC(1,0)) AND _AccumReg6170_Q_007_T_001._Fld6174 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6170_Q_007_T_001._Period >= @P1 AND _AccumReg6170_Q_007_T_001._Period <= @P2 AND _AccumReg6170_Q_007_T_001._Fld6171RRef = @P4 GROUP BY _AccumReg6170_Q_007_T_001._Fld6172RRef, _AccumReg6170_Q_007_T_001._Fld6171RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170_Q_007_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170_Q_007_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), CAST(CASE WHEN NOT _AccumReg6170_Q_007_T_001._RecorderTRef = 0x0000007E THEN CASE WHEN _AccumReg6170_Q_007_T_001._Fld6176RRef = 0xb17249345e902311426eb61a0c1e1f85 THEN CAST(N''Через кассу '' AS NVARCHAR(25)) WHEN _AccumReg6170_Q_007_T_001._Fld6176RRef = 0x8dfbbe1a60552b394e1560dbe3ca9417 THEN CAST(N''Перечислено в банк '' AS NVARCHAR(25)) ELSE N''Способ выплаты не указан '' END + CASE WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef IN (0xbdb467d57dea73474e67e741b52036a5,0xad17dfc84e55d4aa458f5d60b238960e) THEN CAST(N''(аванс)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x8cea26a3252a789146cc4239f036668b THEN CAST(N''(под расчет)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x00000000000000000000000000000000 AND _AccumReg6170_Q_007_T_001._Fld6174 > CAST(0. AS NUMERIC(1,0)) THEN CAST(N''(не указано)'' AS NVARCHAR(24)) WHEN _AccumReg6170_Q_007_T_001._Fld6175RRef = 0x00000000000000000000000000000000 AND _AccumReg6170_Q_007_T_001._Fld6174 < CAST(0. AS NUMERIC(1,0)) THEN N''(погашено задолженности)'' ELSE CAST(N''(межрасчет)'' AS NVARCHAR(24)) END ELSE CAST(N''Задепонировано'' AS NVARCHAR(49)) END AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS UNION ALL SELECT CAST(#V8TblAli1_Q_010_T_003._Q_008_F_000 AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, _AccumReg6170_Q_010_T_001._Fld6172RRef AS _Q_001_F_001RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170_Q_010_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170_Q_010_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_001_F_002, _AccumReg6170_Q_010_T_001._Fld6171RRef AS _Q_001_F_003RRef, CAST(N''Компенсация за задержку выплаты заработной платы'' AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''ГААА2'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(CAST(SUM(_Document130_VT1883_Q_010_T_002._Fld1888) AS NUMERIC(21,2)) AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_011, CAST(NULL AS NUMERIC(35,2)) AS _Q_001_F_012, CAST(NULL AS NUMERIC(29,2)) AS _Q_001_F_013 FROM _AccumReg6170 _AccumReg6170_Q_010_T_001 WITH(NOLOCK) INNER JOIN _Document130_VT1883 _Document130_VT1883_Q_010_T_002 WITH(NOLOCK) ON _AccumReg6170_Q_010_T_001._Fld6171RRef = _Document130_VT1883_Q_010_T_002._Fld1885RRef AND _AccumReg6170_Q_010_T_001._Fld6177RRef = _Document130_VT1883_Q_010_T_002._Document130_IDRRef INNER JOIN ( SELECT N''Начислено'' COLLATE Cyrillic_General_CI_AS AS _Q_008_F_000 UNION ALL SELECT CAST(N''Выплата'' AS NVARCHAR(9)) COLLATE Cyrillic_General_CI_AS AS _Q_008_F_000 ) #V8TblAli1_Q_010_T_003 ON 0 = 0 WHERE _AccumReg6170_Q_010_T_001._RecordKind = CAST(@P9 AS NUMERIC(1,0)) AND _AccumReg6170_Q_010_T_001._Fld6174 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6170_Q_010_T_001._Period >= @P1 AND _AccumReg6170_Q_010_T_001._Period <= @P2 AND _Document130_VT1883_Q_010_T_002._Fld1888 <> CAST(@P3 AS NUMERIC(1,0)) AND _AccumReg6170_Q_010_T_001._Fld6171RRef = @P4 GROUP BY _AccumReg6170_Q_010_T_001._Fld6172RRef, _AccumReg6170_Q_010_T_001._Fld6171RRef, DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170_Q_010_T_001._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170_Q_010_T_001._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), #V8TblAli1_Q_010_T_003._Q_008_F_000 COLLATE Cyrillic_General_CI_AS UNION ALL SELECT CAST(N''Сальдо'' AS NVARCHAR(23)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_000, #V8TblAli2_Q_017_T_002._Q_012_F_000RRef AS _Q_001_F_001RRef, #V8TblAli1_Q_017_T_001._Q_011_F_000 AS _Q_001_F_002, #V8TblAli2_Q_017_T_002._Q_012_F_002RRef AS _Q_001_F_003RRef, CAST(CAST(N'''' AS NVARCHAR(1)) AS NVARCHAR(123)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_004, CAST(N''ЯЯЯЯ'' AS NVARCHAR(13)) COLLATE Cyrillic_General_CI_AS AS _Q_001_F_005, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_006, CAST(NULL AS NUMERIC(14,2)) AS _Q_001_F_007, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_008, CAST(NULL AS NUMERIC(22,2)) AS _Q_001_F_009, CAST(NULL AS NUMERIC(23,2)) AS _Q_001_F_010, CAST(SUM(CASE WHEN #V8TblAli2_Q_017_T_002._Q_012_F_001 < #V8TblAli1_Q_017_T_001._Q_011_F_000 THEN #V8TblAli2_Q_017_T_002._Q_012_F_003 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(28,2)) END) AS NUMERIC(32,2)) AS _Q_001_F_011, CAST(SUM(CASE WHEN #V8TblAli2_Q_017_T_002._Q_012_F_001 <= #V8TblAli1_Q_017_T_001._Q_011_F_000 THEN #V8TblAli2_Q_017_T_002._Q_012_F_003 ELSE CAST(CAST(0. AS NUMERIC(1,0)) AS NUMERIC(28,2)) END) AS NUMERIC(32,2)) AS _Q_001_F_012, CAST(SUM(#V8TblAli2_Q_017_T_002._Q_012_F_004) AS NUMERIC(28,2)) AS _Q_001_F_013 FROM ( SELECT DISTINCT DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _InfoReg5701_Q_011_T_001._Fld5702) - 1, DATEADD(YEAR, DATEPART(YEAR, _InfoReg5701_Q_011_T_001._Fld5702) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Q_011_F_000 FROM _InfoReg5701 _InfoReg5701_Q_011_T_001 WITH(NOLOCK) WHERE _InfoReg5701_Q_011_T_001._Fld5702 >= @P1 AND _InfoReg5701_Q_011_T_001._Fld5702 <= @P2 ) #V8TblAli1_Q_017_T_001 LEFT OUTER JOIN ( SELECT #V8TblAli1_Q_012_T_001._Fld6172RRef AS _Q_012_F_000RRef, {ts ''2009-04-01 00:00:00''} AS _Q_012_F_001, #V8TblAli1_Q_012_T_001._Fld6171RRef AS _Q_012_F_002RRef, #V8TblAli1_Q_012_T_001._Fld6174Balance AS _Q_012_F_003, CAST(NULL AS NUMERIC(22,2)) AS _Q_012_F_004 FROM ( SELECT _AccumRegTotals6179._Fld6171RRef AS _Fld6171RRef, _AccumRegTotals6179._Fld6172RRef AS _Fld6172RRef, CAST(SUM(_AccumRegTotals6179._Fld6174) AS NUMERIC(27,2)) AS _Fld6174Balance FROM _AccumRegTotals6179 WITH(NOLOCK) WHERE _AccumRegTotals6179._Period = @P1 AND _AccumRegTotals6179._Fld6171RRef = @P4 GROUP BY _AccumRegTotals6179._Fld6171RRef, _AccumRegTotals6179._Fld6172RRef HAVING CAST(SUM(_AccumRegTotals6179._Fld6174) AS NUMERIC(27,2)) <> CAST(@P3 AS NUMERIC(1,0)) ) #V8TblAli1_Q_012_T_001 UNION ALL SELECT #V8TblAli1_Q_013_T_001._Fld6172RRef AS _Q_012_F_000RRef, #V8TblAli1_Q_013_T_001._Period AS _Q_012_F_001, #V8TblAli1_Q_013_T_001._Fld6171RRef AS _Q_012_F_002RRef, CAST(#V8TblAli1_Q_013_T_001._Fld6174Turnover AS NUMERIC(28,2)) AS _Q_012_F_003, CAST(NULL AS NUMERIC(22,2)) AS _Q_012_F_004 FROM ( SELECT DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Period, _AccumReg6170._Fld6171RRef AS _Fld6171RRef, _AccumReg6170._Fld6172RRef AS _Fld6172RRef, CAST(SUM(CASE WHEN _AccumReg6170._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6170._Fld6174 ELSE - _AccumReg6170._Fld6174 END) AS NUMERIC(21,2)) AS _Fld6174Turnover FROM _AccumReg6170 WITH(NOLOCK) WHERE _AccumReg6170._Period >= @P1 AND _AccumReg6170._Period <= @P2 AND _AccumReg6170._Active = @P7 AND _AccumReg6170._Fld6171RRef = @P4 GROUP BY DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6170._Fld6171RRef, _AccumReg6170._Fld6172RRef HAVING CAST(SUM(CASE WHEN _AccumReg6170._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6170._Fld6174 ELSE - _AccumReg6170._Fld6174 END) AS NUMERIC(21,2)) <> CAST(@P3 AS NUMERIC(1,0)) ) #V8TblAli1_Q_013_T_001 UNION ALL SELECT #V8TblAli1_Q_014_T_001._Fld6252RRef AS _Q_012_F_000RRef, {ts ''2009-04-01 00:00:00''} AS _Q_012_F_001, #V8TblAli1_Q_014_T_001._Fld6251RRef AS _Q_012_F_002RRef, CAST(#V8TblAli1_Q_014_T_001._Fld6254Balance AS NUMERIC(28,2)) AS _Q_012_F_003, CAST(NULL AS NUMERIC(22,2)) AS _Q_012_F_004 FROM ( SELECT _AccumRegTotals6256._Fld6251RRef AS _Fld6251RRef, _AccumRegTotals6256._Fld6252RRef AS _Fld6252RRef, CAST(SUM(_AccumRegTotals6256._Fld6254) AS NUMERIC(25,0)) AS _Fld6254Balance FROM _AccumRegTotals6256 WITH(NOLOCK) WHERE _AccumRegTotals6256._Period = @P1 AND _AccumRegTotals6256._Fld6251RRef = @P4 GROUP BY _AccumRegTotals6256._Fld6251RRef, _AccumRegTotals6256._Fld6252RRef HAVING CAST(SUM(_AccumRegTotals6256._Fld6254) AS NUMERIC(25,0)) <> CAST(@P3 AS NUMERIC(1,0)) ) #V8TblAli1_Q_014_T_001 UNION ALL SELECT #V8TblAli1_Q_015_T_001._Fld6252RRef AS _Q_012_F_000RRef, #V8TblAli1_Q_015_T_001._Period AS _Q_012_F_001, #V8TblAli1_Q_015_T_001._Fld6251RRef AS _Q_012_F_002RRef, CAST(#V8TblAli1_Q_015_T_001._Fld6254Turnover AS NUMERIC(28,2)) AS _Q_012_F_003, CAST(NULL AS NUMERIC(22,2)) AS _Q_012_F_004 FROM ( SELECT DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6250._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6250._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Period, _AccumReg6250._Fld6251RRef AS _Fld6251RRef, _AccumReg6250._Fld6252RRef AS _Fld6252RRef, CAST(SUM(CASE WHEN _AccumReg6250._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6250._Fld6254 ELSE - _AccumReg6250._Fld6254 END) AS NUMERIC(19,0)) AS _Fld6254Turnover FROM _AccumReg6250 WITH(NOLOCK) WHERE _AccumReg6250._Period >= @P1 AND _AccumReg6250._Period <= @P2 AND _AccumReg6250._Active = @P7 AND _AccumReg6250._Fld6251RRef = @P4 GROUP BY DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6250._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6250._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6250._Fld6251RRef, _AccumReg6250._Fld6252RRef HAVING CAST(SUM(CASE WHEN _AccumReg6250._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6250._Fld6254 ELSE - _AccumReg6250._Fld6254 END) AS NUMERIC(19,0)) <> CAST(@P3 AS NUMERIC(1,0)) ) #V8TblAli1_Q_015_T_001 UNION ALL SELECT #V8TblAli1_Q_016_T_001._Fld6172RRef AS _Q_012_F_000RRef, #V8TblAli1_Q_016_T_001._Period AS _Q_012_F_001, #V8TblAli1_Q_016_T_001._Fld6171RRef AS _Q_012_F_002RRef, CAST(NULL AS NUMERIC(28,2)) AS _Q_012_F_003, #V8TblAli1_Q_016_T_001._Fld6174Turnover AS _Q_012_F_004 FROM ( SELECT DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170._Period) - 2000, {ts ''2000-01-01 00:00:00''}))) AS _Period, _AccumReg6170._Fld6171RRef AS _Fld6171RRef, _AccumReg6170._Fld6172RRef AS _Fld6172RRef, CAST(SUM(CASE WHEN _AccumReg6170._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6170._Fld6174 ELSE - _AccumReg6170._Fld6174 END) AS NUMERIC(21,2)) AS _Fld6174Turnover FROM _AccumReg6170 WITH(NOLOCK) WHERE _AccumReg6170._Period >= @P1 AND _AccumReg6170._Period <= @P2 AND _AccumReg6170._Active = @P7 AND _AccumReg6170._Fld6171RRef = @P4 GROUP BY DATEADD(DAY, 1 - 1, DATEADD(MONTH, DATEPART(MONTH, _AccumReg6170._Period) - 1, DATEADD(YEAR, DATEPART(YEAR, _AccumReg6170._Period) - 2000, {ts ''2000-01-01 00:00:00''}))), _AccumReg6170._Fld6171RRef, _AccumReg6170._Fld6172RRef HAVING CAST(SUM(CASE WHEN _AccumReg6170._RecordKind = CAST(0. AS NUMERIC(1,0)) THEN _AccumReg6170._Fld6174 ELSE - _AccumReg6170._Fld6174 END) AS NUMERIC(21,2)) <> CAST(@P3 AS NUMERIC(1,0)) ) #V8TblAli1_Q_016_T_001 ) #V8TblAli2_Q_017_T_002 ON #V8TblAli2_Q_017_T_002._Q_012_F_001 <= #V8TblAli1_Q_017_T_001._Q_011_F_000 WHERE #V8TblAli2_Q_017_T_002._Q_012_F_002RRef = @P4 GROUP BY #V8TblAli2_Q_017_T_002._Q_012_F_000RRef, #V8TblAli2_Q_017_T_002._Q_012_F_002RRef, #V8TblAli1_Q_017_T_001._Q_011_F_000 ) #V8TblAli1_Q_000_T_001 WHERE #V8TblAli1_Q_000_T_001._Q_001_F_003RRef = @P4 ORDER BY #V8TblAli1_Q_000_T_001._Q_001_F_002, #V8TblAli1_Q_000_T_001._Q_001_F_001RRef, #V8TblAli1_Q_000_T_001._Q_001_F_003RRef, #V8TblAli1_Q_000_T_001._Q_001_F_005, #V8TblAli1_Q_000_T_001._Q_001_F_004', N'@P1 datetime,@P2 datetime,@P3 numeric(1,0),@P4 varbinary(16),@P5 varbinary(16),@P6 varbinary(16),@P7 varbinary(1),@P8 varbinary(16),@P9 numeric(1,0)', {ts '2009-05-01 00:00:00'}, {ts '2009-05-31 23:59:59'}, 0, 0xA903001CC49557F011DDD17598789B8B, 0x9DFB0D4629F59BB1491213BCCAC174B8, 0xA6F7BD8B1B623D9E41DEE5ED58704984, 0x01, 0xB429588AD294196D44BA9B1319657176, 1 |