需要帮助创建MS Access报告

时间:2014-01-30 02:08:47

标签: ms-access ms-access-2007

我在Access中创建了几个表。

              [Projects]                                       [Assigned]
   [Project Name]  |  [Billable]     [Project Name]  |  [Employee]  |  [Date]   |  [Hours Worked]
        CX111      |    False             LM565      |     Bill     | 1/3/2014  |        8
        LM565      |    True              CX111      |     Zach     | 1/3/2014  |        3
         ...       |    ...               LM565      |     John     | 1/5/2014  |        5 
        AA888      |    True              AA888      |     Bill     | 1/25/2014 |        5
                                          LM565      |     Terry    | 2/6/2014  |        7

我需要创建一个报告,检查每个项目是否为Billable。然后,它需要为该月的所有可计费项目添加所有[工作小时数],然后在报告中显示总小时数。

上面会显示

                        [Billable Hours for the Month]
                       [Month]       |  [Total Billable Hours]
                     January 2014    |          18
                     February 2014   |           7

我是Access的新手,虽然我知道我需要使用'If'语句来检查项目是否[Billable],但似乎我还需要使用某种循环来求和两张表中的所有总数。我不知道如何创建循环,或如何从两个单独的表检查和写入信息。

感谢您提供的任何帮助。 -crash

1 个答案:

答案 0 :(得分:0)

不应该使用循环或If语句/函数。以下查询应提供您需要的总数:

SELECT 
    YEAR(Assigned.[Date]) AS Yr,
    MONTH(Assigned.[Date]) AS Mo,
    SUM(Assigned.[Hours Worked]) AS Hrs
FROM
    Assigned
    INNER JOIN
    Projects
        ON Projects.[Project Name] = Assigned.[Project Name]
WHERE Projects.Billable
GROUP BY 
    YEAR(Assigned.[Date]),
    MONTH(Assigned.[Date])