厦门用友软件 畅捷通T+辅助明细账,辅助是一样的,但是跨年度查询就没有数据,数据不全
备份账套 执行以下语句
declare @debugger varchar(50)
if object_id(N'AA_BackUp',N'U') is null
select * into AA_BackUp from AA_AccountAssociation --删除科目对照表数据前备份
--if(@debugger='test')
--begin
-- insert into AA_AccountAssociation(idcurrentaccountingyear,createdtime,sequencenumber,idcurrentaccountDTO,idpreaccountDTO,preaccountingyear)
-- select id,code,name,currentaccountingyear,createdtime,sequencenumber,idcurrentaccountDTO,idpreaccountDTO,preaccountingyear from AA_BackUp
--end
--修复12.1 AccountAssociation
declare @StartYear int
declare @EndYear int
select @StartYear=2011
select @EndYear=2022
delete AA_AccountAssociation where currentaccountingyear between @StartYear and @EndYear --删除科目对照表数据
declare @TempAccount table(Code varchar(100),Num int)
declare @AllCount int
declare @NowCount int
--查出所有科目CODE
insert into @TempAccount(Code,Num) select code,ROW_NUMBER() over(order by code) as Num from aa_account group by code
set @AllCount=(select count(*) from @TempAccount)
--循环科目CODE
declare @differYear int;
set @differYear=@EndYear;
while @StartYear<=@EndYear
begin
set @NowCount=1
while(@NowCount<=@AllCount)
begin
declare @TempCode varchar(20)
select @TempCode=Code from @TempAccount where num=@NowCount
declare @PreAccountID varchar(50)
declare @CurAccountID varchar(50)
select @CurAccountID=id from AA_Account where code=@TempCode and accountingyear=@EndYear
select @PreAccountID=id from AA_Account where code=@TempCode and accountingyear=@differYear
if(@PreAccountID!='' and @CurAccountID!='')
insert into AA_AccountAssociation(currentaccountingyear,idcurrentaccountDTO,idpreaccountDTO,preaccountingyear)
values
(@EndYear,@CurAccountID,@PreAccountID,@differYear)
set @NowCount=@NowCount+1
set @PreAccountID=''
set @CurAccountID=''
end
set @differYear=@differYear-1
if(@differYear<@StartYear)
BEGIN
set @EndYear=@EndYear-1
set @differYear=@EndYear
END
end