用友财务总账(GL)模块的BI数据ETL分析

业务需求如下:

某公司目前用了用友的总账BI分析案例。

/*
sql Server2012使用作业设置定时任务,来保证一天执行一次
*/
/*
一定要注意temp1表里一定要保证要有记录,否则以temp1 来 left join就出现为空的情况。
*/
/*
Step 1: 把所有的数据库列表都插入到BI数据库的DBLIST表里
*/
USE BI;

/*
drop table BI.DBO.TEMP1;
drop table BI.DBO.TEMP2;
drop table BI.DBO.TEMP3;
drop table BI.DBO.TEMP4;
drop table BI.DBO.TEMP5;
drop table BI.DBO.TEMP6;
drop table BI.DBO.TEMP7;
*/

truncate table BI.DBO.DBLIST;

SELECT * FROM BI.DBO.DBLIST;

insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_103_2010','公司名称1');
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_103_2011',DB_COMPANY_NAME) VALUES ('UFDATA_103_2012',DB_COMPANY_NAME) VALUES ('UFDATA_103_2013',DB_COMPANY_NAME) VALUES ('UFDATA_103_2014','公司名称1');


insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_105_2010','公司名称2‘);
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_105_2011','公司名称2);
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_105_2012','公司名称2');
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_105_2013',DB_COMPANY_NAME) VALUES ('UFDATA_105_2014','公司名称2');

 

insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_106_2010','公司名称3’);
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_106_2011','公司名称3');
insert into BI.DBO.DBLIST(DB_CODE,DB_COMPANY_NAME) VALUES ('UFDATA_106_2012',DB_COMPANY_NAME) VALUES ('UFDATA_106_2013',DB_COMPANY_NAME) VALUES ('UFDATA_106_2014','公司名称3');


/*
Step 2: 清空统计表里的记录,方便重新插入,注意设置BI数据库不记录日志的形式
*/
truncate table BI.DBO.CLB;
truncate table BI.DBO.CWB;
truncate table BI.DBO.RCSHB;
truncate table BI.DBO.RSB;
truncate table BI.DBO.TDJS;
truncate table BI.DBO.ZJB;
/*
Step 3: 循环选择数据库,插入BI.DBO.CLB
*/
declare @DB_CODE char(50)
declare @DB_COMPANY_NAME char(100)
declare @sql_STRING varchar(8000)


declare table_cursor cursor for select DB_CODE,DB_COMPANY_NAME from BI.DBO.DBLIST
open table_cursor


fetch next from table_cursor into @DB_CODE,@DB_COMPANY_NAME
WHILE @@FETCH_STATUS = 0
BEGIN

 /*      
 差旅表 CLB
 */
 
 set @sql_STRING='select ' +''''+ '差旅表' +''''+ ' as GLType,'+''''+rtrim(@DB_COMPANY_NAME)+''''+ ' as CompanyName,'
 set @sql_STRING=@sql_STRING+'isnull(md,0.00) as '+''''+'DomesticTravel'+''''+','
 set @sql_STRING=@sql_STRING+'iYPeriod,iperiod,iyear into BI.DBO.temp1 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660214'+''''+';'
 

  set @sql_STRING=@sql_STRING+'select ' +''''+ '差旅表' +''''+ ' as GLType,0.00) as '+''''+'OverseasTravel'+''''+',iyear into BI.DBO.temp2 from '+ rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660213'+''''+';'

  set @sql_STRING=@sql_STRING+'select ' +''''+ '差旅表' +''''+ ' as GLType,0.00) as '+''''+'Entertainment'+''''+',iyear into BI.DBO.temp3 from '+ rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660223'+''''+';'

 
 set @sql_STRING=@sql_STRING+' insert into BI.DBO.CLB(GLType,CompanyName,DomesticTravel,OverseasTravel,Entertainment,iYPeriod,iyear)'
 set @sql_STRING=@sql_STRING+' select BI.DBO.temp1.GLType,BI.DBO.temp1.CompanyName,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.DomesticTravel,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp2.OverseasTravel,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp3.Entertainment,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iYPeriod,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod,BI.DBO.temp1.iyear from BI.DBO.temp1 left join BI.DBO.temp2 on'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp2.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp2.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp2.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp3 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp3.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp3.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp3.iYPeriod;'

 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp1;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp2;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp3;'

    exec(@sql_STRING)
 print @sql_STRING
 

 /*      
 财务表 CWB
 */
 
 set @sql_STRING='select ' +''''+ '财务表' +''''+ ' as GLType,0.00) as '+''''+'BankCharges'+''''+',iyear into BI.DBO.temp1 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660301'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '财务表' +''''+ ' as GLType,0.00) as '+''''+'InterestIncome'+''''+',iyear into BI.DBO.temp2 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660302'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '财务表' +''''+ ' as GLType,0.00) as '+''''+'InterestExpenses'+''''+',iyear into BI.DBO.temp3 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660303'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '财务表' +''''+ ' as GLType,0.00) as '+''''+'IncoMetaxes'+''''+',iyear into BI.DBO.temp4 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'6801'+''''+';'
 

 set @sql_STRING=@sql_STRING+' insert into BI.DBO.CWB(GLType,BankCharges,InterestIncome,InterestExpenses,IncoMetaxes,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.BankCharges,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp2.InterestIncome,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp3.InterestExpenses,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp4.IncoMetaxes,BI.DBO.temp1.iyear from BI.DBO.temp1 left join BI.DBO.temp2 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp2.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp2.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp2.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp3 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp3.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp3.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp3.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp4 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp4.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp4.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp4.iYPeriod;'

 

 set @sql_STRING=@sql_STRING+'drop table  BI.DBO.temp1;'
 set @sql_STRING=@sql_STRING+'drop table  BI.DBO.temp2;'
 set @sql_STRING=@sql_STRING+'drop table  BI.DBO.temp3;'
 set @sql_STRING=@sql_STRING+'drop table  BI.DBO.temp4;'

 exec(@sql_STRING)
 print @sql_STRING
 
 /*      
 日常生活表 RCSHB
 */
 
 set @sql_STRING='select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'FixLineTel'+''''+',iyear into BI.DBO.temp1 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660211'+''''+';'

 set @sql_STRING=@sql_STRING+'select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'MobilePhone'+''''+',iyear into BI.DBO.temp2 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660212'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'OfficeSupplies'+''''+',iyear into BI.DBO.temp3 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660221'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'OfficeRepairMaintenance'+''''+',iyear into BI.DBO.temp4 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660222'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'WaterElectricity'+''''+',iyear into BI.DBO.temp5 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660231'+''''+';'
 
  set @sql_STRING=@sql_STRING+'select ' +''''+ '日常生活表' +''''+ ' as GLType,0.00) as '+''''+'MISExpense'+''''+',iyear into BI.DBO.temp6 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660233'+''''+';'


 set @sql_STRING=@sql_STRING+' insert into BI.DBO.RCSHB(GLType,FixLineTel,MobilePhone,OfficeSupplies,OfficeRepairMaintenance,WaterElectricity,MISExpense,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.FixLineTel,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp2.MobilePhone,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp3.OfficeSupplies,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp4.OfficeRepairMaintenance,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp5.WaterElectricity,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp6.MISExpense,BI.DBO.temp1.iyear from BI.DBO.temp1 left join BI.DBO.temp2 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp2.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp2.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp2.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp3 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp3.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp3.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp3.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp4 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp4.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp4.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp4.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp5 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp5.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp5.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp5.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp6 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp6.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp6.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp6.iYPeriod;'

 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp1;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp2;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp3;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp4;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp5;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp6;'

 exec(@sql_STRING)
 print @sql_STRING
 

 /*      
 人事表 RSB
 */
 
 set @sql_STRING='select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'Salary'+''''+',iyear into BI.DBO.temp1 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'66020101'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'Bonus'+''''+',iyear into BI.DBO.temp2 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'66020102'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'SalesCommission'+''''+',iyear into BI.DBO.temp3 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'66020103'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'SocialInsurance'+''''+',iyear into BI.DBO.temp4 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660203'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'Benefits'+''''+',iyear into BI.DBO.temp5 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660204'+''''+';'

 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,0.00) as '+''''+'HousingOtherAllowance'+''''+',iyear into BI.DBO.temp6 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660205'+''''+';'
    
 set @sql_STRING=@sql_STRING+'select ' +''''+ '人事表' +''''+ ' as GLType,'
 set @sql_STRING=@sql_STRING+'0 as '+''''+'HeadCount'+''''+',iyear into BI.DBO.temp7 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where 1=2;'


 set @sql_STRING=@sql_STRING+' insert into BI.DBO.RSB(GLType,Salary,Bonus,SalesCommission,SocialInsurance,Benefits,HousingOtherAllowance,HeadCount,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.Salary,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp2.Bonus,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp3.SalesCommission,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp4.socialInsurance,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp5.Benefits,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp6.HousingOtherAllowance,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp7.HeadCount,BI.DBO.temp1.iyear from BI.DBO.temp1 left join BI.DBO.temp2 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp2.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp2.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp2.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp3 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp3.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp3.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp3.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp4 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp4.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp4.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp4.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp5 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp5.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp5.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp5.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp6 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp6.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp6.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp6.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp7 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp7.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp7.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp7.iYPeriod;'

 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp1;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp2;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp3;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp4;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp5;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp6;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp7;'


 exec(@sql_STRING)
 print @sql_STRING
 

 /*      
 团队建设表 TDJS
 */

 set @sql_STRING='select ' +''''+ '团队建设表' +''''+ ' as GLType,'
 set @sql_STRING=@sql_STRING+' isnull(md,0.00) as '+''''+'Training'+''''+',iyear into BI.DBO.temp1 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660208'+''''+';'
 
 set @sql_STRING=@sql_STRING+'select ' +''''+ '团队建设表' +''''+ ' as GLType,0.00) as '+''''+'TeamBuilding'+''''+',iyear into BI.DBO.temp2 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660207'+''''+';'

  set @sql_STRING=@sql_STRING+'select ' +''''+ '团队建设表' +''''+ ' as GLType,0.00) as '+''''+'EmployeeUniforms'+''''+',iyear into BI.DBO.temp3 from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'660210'+''''+';'
 
 
 set @sql_STRING=@sql_STRING+' insert into BI.DBO.TDJS(GLType,Training,TeamBuilding,EmployeeUniforms,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.Training,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp2.TeamBuilding,'
 set @sql_STRING=@sql_STRING+' BI.DBO.temp3.EmployeeUniforms,BI.DBO.temp1.iyear from BI.DBO.temp1 left join BI.DBO.temp2 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp2.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp2.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp2.iYPeriod'
 set @sql_STRING=@sql_STRING+' left join BI.DBO.temp3 on '
 set @sql_STRING=@sql_STRING+' BI.DBO.temp1.iperiod=BI.DBO.temp3.iperiod and BI.DBO.temp1.iyear=BI.DBO.temp3.iyear and BI.DBO.temp1.iYPeriod=BI.DBO.temp3.iYPeriod;'

 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp1;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp2;'
 set @sql_STRING=@sql_STRING+' drop table  BI.DBO.temp3;'
 
 exec(@sql_STRING)
 print @sql_STRING 
 
 
 
 /*      
 折旧表 ZJB
 */

 set @sql_STRING='INSERT INTO BI.DBO.ZJB (GLType,DYZJ,LJZJ,GDZCJZ,ZJCLGDZC,iPeriod,iYear)'
 set @sql_STRING=@sql_STRING+' select ' +''''+ '折旧表' +''''+ ' as GLType,'
 set @sql_STRING=@sql_STRING+' a.mc as '+''''+ '当月折旧'+''''+',a.me as  '+''''+'累计折旧'+''''+',(a.me-b.me) as '+''''+'固定资产净值'+''''+',a.md-a.mc as '+''''+'新增或处理固定资产'+''''+','
 set @sql_STRING=@sql_STRING+' a.iYPeriod,a.iperiod,a.iyear '
 set @sql_STRING=@sql_STRING+' from (select   mc,md,me,iyear,iYPeriod from '+rtrim(@DB_CODE)+'.dbo.GL_accsum where ccode='+''''+'1601'+''''+') a,'
 set @sql_STRING=@sql_STRING+' (select   mc,iYPeriod from '+rtrim(@DB_CODE)+'.dbo.GL_accsum      where ccode='+''''+'1602'+''''+') b '
 set @sql_STRING=@sql_STRING+' where a.iYPeriod=b.iYPeriod and a.iperiod=b.iperiod and a.iyear=b.iyear;'

 exec(@sql_STRING)  print @sql_STRING        fetch next from table_cursor into @DB_CODE,@DB_COMPANY_NAME END close table_cursor deallocate table_cursor

相关文章

自1998年我国取消了福利分房的政策后,房地产市场迅速开展蓬...
文章目录获取数据查看数据结构获取数据下载数据可以直接通过...
网上商城系统MySql数据库设计
26个来源的气象数据获取代码
在进入21世纪以来,中国电信业告别了20世纪最后阶段的高速发...