依据多个表生成报表

根据多个表生成报表
报表主要又五部分组成,一个是工程项目,这个字段在字典里面有,一个是计划总工程量,这个是在月计划的表中,统计当月的数据,本月完成工作量,在养护生产表中,这个表主要是你干了多少,第三个是年初到现在完成的总工作量,这个直接求和计划总工程量,最后一个是当前完成百分比,是按照本月完成工作量/计划总工程量来计算。依据多个表生成报表
------解决方案--------------------
你倒是把其他几个表的结构也给出来啊  不然直接这个表怎么写?
建议用文本方式给出。还给点测试数据 可以构造测试数据来写写。
------解决方案--------------------
引用:
你倒是把其他几个表的结构也给出来啊  不然直接这个表怎么写?
建议用文本方式给出。还给点测试数据 可以构造测试数据来写写。

+1
------解决方案--------------------
用SQL就写出来了啊。
------解决方案--------------------
给你个例子参考下:依据多个表生成报表


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:timefile
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================

ALTER PROCEDURE [dbo].[EmloyeeAlterationReport] 

@begintime DATETIME,
@endtime DATETIME
AS
BEGIN


select department,0 ondutybegmon,0 ondutyendmon,0 moninduty,0 monoutduty,0 monmove,0 monintoonduty,employeeid monoutrate ,id into #1 from Qn_EmloyeeInfo where 1 = 2
insert into #1(department,ondutybegmon,ondutyendmon,moninduty,monoutduty,monmove,monintoonduty,monoutrate)
select department,0,0,0,0,0,0,0
from Qn_EmloyeeInfo 
where isnull(department,'') <> ''
group by department

--月初在职人数
select department, count(*) reccount INTO #2 from Qn_EmloyeeInfo where STATUS <>'离职' and entryDate <= @begintime and isnull(department,'') <> ''  group by department
--月末在职人数
select department, count(*) reccount into #3 from Qn_EmloyeeInfo where  STATUS <>'离职' and entryDate <= @endtime and isnull(department,'') <> ''  group by department
--本月入职人数
select department, count(*) reccount into #4  from Qn_EmloyeeInfo where STATUS <>'离职' and entryDate between @begintime and @endtime and isnull(department,'') <> '' group by department
--本月离职人数
select department, count(*) reccount into #5 from Qn_EmloyeeInfo where STATUS ='离职' and leaveDate between @begintime and @endtime and isnull(department,'') <> '' group by department
--本月异动人数
select newdepartment department, count(*) reccount into #6 from HR_StaandPayChangeList where changeType In ('部门/岗位变动') and changeDate between @begintime and @endtime and isnull(newdepartment,'') <> '' group by newdepartment
--本月转正人数
select department, count(*) reccount into #7 from HR_ContractInfo where formalDate BETWEEN @begintime AND @endtime and status in ('转正记录') and isnull(department,'') <> '' group by department

update #1
set ondutybegmon = #2.reccount
from #2
where #1.department = #2.department
--更新月末在职人数
update #1
set ondutyendmon = #3.reccount
from #3
where #1.department = #3.department

--更新本月入职人数
update #1
set moninduty = #4.reccount
from #4
where #1.department = #4.department

--更新本月离职人数
update #1
set monoutduty = #5.reccount
from #5
where #1.department = #5.department

--更新本月异动人数
update #1
set monmove = #6.reccount
from #6
where #1.department = #6.department

--更新本月转正人数
update #1
set monintoonduty = #7.reccount
from #7
where #1.department = #7.department

--查询报表
select * from #1

END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO