SSRS 2008:如何计算每年的员工数量

时间:2014-01-05 16:13:34

标签: ssrs-2008 fetch

我有一个问题,我需要计算选定年份的员工和团体人数。这些年来自参数。

E.g。如果我通过参数选择2010-2013,我想计算12月31日那些选定年份的员工人数。问题是我只能使用CRM 2013中的Fecth。

在员工身上有工作日期和结束日期,但我不能对此进行分组,因为它没有告诉我某个选定年份有多少员工。我还需要对员工人数和年度分组制作不同的图表。

使用IIF并计算员工数量并放入特定单元格并不困难,但我需要它是动态的。

编辑:更多想法...... 如果我使用多值参数并将可用值设置为2010-12-31 ... 2013-12-31,并且每年我都会选择计算员工人数。然后我只需要能够对这个多值参数进行分组。这可能吗?

1 个答案:

答案 0 :(得分:0)

如果您的员工具有结束日期(例如2011-06-04)而不是他应该被包括在2011年的报告中,我会为您的任务做客。如果我是对的,你需要像这样的SQL表达式:

With Employee AS
(
SELECT 'employee1' as Name, '2010-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee2' as Name, '2010-02-01' as StartDate, '2011-04-01' as EndDate UNION ALL
SELECT 'employee3' as Name, '2010-02-01' as StartDate, '2011-04-01' as EndDate UNION ALL
SELECT 'employee4' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee5' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee6' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee7' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee8' as Name, '2012-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee9' as Name, '2012-02-01' as StartDate, '2012-04-01' as EndDate
) 
SELECT Employee2.Name AS EmployeeName, YEAR(Employee.StartDate) AS EmployeeWorkedYear
FROM Employee
JOIN Employee as Employee2 ON YEAR(Employee2.EndDate) >= YEAR(Employee.StartDate) AND YEAR(Employee2.StartDate) <= YEAR(Employee.StartDate)
GROUP BY YEAR(Employee.StartDate), Employee2.Name

它将显示他工作的员工姓名和年份。然后你应该用这样的表达式(存储过程)和第二列(年)分组创建数据集,并创建分组表,图表等。