1.生成新科目余额表
⑴生成余额表。查询语句如下:
SELECT GL_accsum.ccode AS 科目编码, GL_accsum.mb AS 期初余额, GL_accsum.cendd_c AS 余额方向 INTO 余额表 FROM GL_accsum
WHERE (((GL_accsum.iperiod)=1))
ORDER BY GL_accsum.ccode;
⑵生成往来余额明细表。查询语句如下:
SELECT GL_accvouch.ccode AS 科目编码, GL_accvouch.md AS 借方余额, GL_accvouch.mc AS 贷方余额, GL_accvouch.cperson_id AS 个人往来编码, Person.cPersonName, GL_accvouch.csup_id AS 应付单位编码, Vendor.cVenName, GL_accvouch.ccus_id AS 单位往来编码, Customer.cCusName, GL_accvouch.dbill_date INTO 往来余额明细表
FROM Vendor RIGHT JOIN (Customer RIGHT JOIN (Person RIGHT JOIN GL_accvouch ON Person.cPersonCode = GL_accvouch.cperson_id) ON Customer.cCusCode = GL_accvouch.ccus_id) ON Vendor.cVenCode = GL_accvouch.csup_id WHERE (((GL_accvouch.dbill_date) Like '2007-12-31‘));
⑶生成新往来余额表。查询语句如下:
SELECT
IIf([单位往来编码] Is Not Null,IIf(Len([单位往来编码])=3,余额表。科目编码+'0'+Right([单位往来编码],1),余额表。科目编码+Right([单位往来编码],2)),
IIf([应付单位编码] Is Not Null,IIf(Len([应付单位编码])=4,余额表。科目编码+'0'+Right([应付单位编码],1),余额表。科目编码+Right([应付单位编码],2)),
IIf(Len([个人往来编码])=3,余额表。科目编码+'0'+Right([个人往来编码],1),余额表。科目编码+Right([个人往来编码],2)))) AS 新科目编码,
IIf([借方余额]>0,[借方余额],[贷方余额]) AS 余额,
IIf([借方余额]>0,’借‘,’贷‘) AS 方向,
IIf([cpersonname] Is Not Null,[cpersonname],IIf([cvenname] Is Not Null,[cvenname],[ccusname])) AS 科目名称 INTO 新往来余额表
FROM 往来余额明细表 INNER JOIN 余额表 ON 往来余额明细表。科目编码 = 余额表。科目编码;
⑷生成新余额表。查询语句如下:
SELECT * INTO 新余额表 FROM [SELECT * from 余额表
union select 新科目编码,余额,方向 from 新往来余额表]. AS A
ORDER BY A.科目编码;