- 打卡等级:无名新人
- 打卡总天数:3
- 打卡月天数:1
- 打卡总奖励:5
- 最近打卡:2024-11-01 16:19:28
|
发表于 2019-1-2 11:03:36
|
显示全部楼层
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[BG_CalcBgYear] @year INTEGER
AS
BEGIN
DECLARE @cacc_id NVARCHAR(5);
DECLARE @BudgetAccountName varchar(20);
DECLARE @iFirstPeriod varchar(20);
DECLARE @mysql nvarchar(1000);
DECLARE @ParmDefinition NVARCHAR(200);
EXEC BG_GetBudgetAccountName
@BudgetAccountName = @BudgetAccountName OUTPUT;
IF @BudgetAccountName is not null and exists(select 1 from master..sysdatabases where name=@BudgetAccountName)
BEGIN
DECLARE @existSql1 nvarchar(200);
DECLARE @existSql2 nvarchar(200);
DECLARE @exist1 varchar(100);
DECLARE @exist2 varchar(100);
SET @existSql1 = 'SELECT @exist1 = ''true'' FROM '+@BudgetAccountName+'.[dbo].[sysobjects] WHERE NAME = ''BG_BgYearPeriod'' and [type] = ''U''';
SET @existSql2 = 'SELECT @exist2 = ''true'' FROM '+@BudgetAccountName+'.[dbo].[sysobjects] WHERE NAME = ''BG_BgYearVoucherDate'' and [type] = ''U''';
exec sp_executesql @existSql1,N'@exist1 varchar(100) out ',@exist1 out
exec sp_executesql @existSql2,N'@exist2 varchar(100) out ',@exist2 out
IF @exist1 = 'true' and @exist2 = 'true'
BEGIN
SET @cacc_id = SUBSTRING(@BudgetAccountName, 8, 3);
SET @mysql = N'select @iFirstPeriod = iFirstPeriodOfCtrlAccount from (SELECT top 1 iFirstPeriodOfCtrlAccount FROM '+@BudgetAccountName+'..BG_BudgetYear WHERE iMakeYear = (SELECT top 1 iMakeYear FROM '+@BudgetAccountName+'..BG_LoginToMakeYear WHERE iLoginYear=@year)) a';
SET @ParmDefinition = N'@iFirstPeriod VARCHAR(20) OUT,@year INT'
EXECUTE sp_executesql @mysql, @ParmDefinition, @iFirstPeriod OUT,@year
PRINT @iFirstPeriod;
-----如果 @iFirstPeriod 为空,说明预算模块的iMakeYear还未初始化,或者期间有问题,此时应进入预算系统保存控制选项,不应用错误数据继续处理
IF(@iFirstPeriod IS NULL)
BEGIN
RETURN;
END
SET @mysql = N'DELETE FROM '+@BudgetAccountName+'..BG_BgYearPeriod';
EXEC (@mysql);
SET @mysql = N'INSERT INTO '+@BudgetAccountName+'..BG_BgYearPeriod
( iYear ,
iId ,
dBegin ,
dEnd ,
iBgYear ,
iBgPeriod
)
SELECT iYear ,
iId ,
dBegin ,
dEnd ,
YEAR(DATEADD(MONTH, -(' + @iFirstPeriod + ' - 1 ),
CAST(iYear AS NVARCHAR(4))+ ''-''
+ CAST(iId AS NVARCHAR(4))+ ''-'' + ''1'')) AS iBgYear ,
MONTH(DATEADD(MONTH, -(' + @iFirstPeriod + ' - 1 ),
CAST(iYear AS NVARCHAR(4)) + ''-''
+ CAST(iId AS NVARCHAR(4)) + ''-'' + ''1'')) AS iBgPeriod
FROM UFSystem..UA_Period
WHERE cAcc_Id = ' + @cacc_id;
EXEC (@mysql);
SET @mysql = N'DELETE FROM '+@BudgetAccountName+'..BG_BgYearVoucherDate';
EXEC (@mysql);
SET @mysql = N'INSERT INTO '+@BudgetAccountName+'..BG_BgYearVoucherDate
( iBgYear ,
dBegin ,
dEnd
)
SELECT iBgYear ,
MIN(dBegin) ,
MAX(dEnd)
FROM '+@BudgetAccountName+'..BG_BgYearPeriod
GROUP BY iBgYear';
EXEC (@mysql);
END;
END;
END;
|
|