我正在使用MS Access制作一个程序,之前我使用过这个查询并且它有效,但它处于完全不同的情况。我不知道如何修改它以使其在这里工作。我需要选择并计算过去30天内打开的工作人员的数量,但我的日期在WHERE部分存在问题。
以下是查询:
"SELECT 'Completed' AS Status, Count(tblWorkorders.WOID) AS CountOfWOID " & _
"From tblWorkorders " & _
"WHERE ((tblWorkorders.CompleteDate >= DateAdd('m',-10,DateValue(#[@DailyReportStartDate]#))) And (tblWorkorders.CompleteDate < DateAdd('d',1,DateValue(#[@DailyReportEndDate]#)))) " & _
"UNION ALL " & _
"SELECT 'Open' AS Status, Count(tblWorkorders.WOID) AS CountOfWOID " & _
"From tblWorkorders " & _
"WHERE (((tblWorkorders.RequestDate) < #[@DailyReportEndDate]#) And ((tblWorkorders.CompleteDate) >= #[@DailyReportEndDate]# Or (tblWorkorders.CompleteDate) Is Null) AND ((tblWorkorders.StatusID) In (1,4))) " & _
"Group BY 'Open' "
编辑:这是公共职能:
Public Function CreateDailyReport() As Boolean
Dim reportName As String
Dim QueryName As String
Dim q As String
q = "SELECT * FROM tblDowntime WHERE 1=0"
reportName = "rptDailyReport"
QueryName = "qryDailyReport"
Modify_QuerySQL QueryName, q
Modify_QuerySQL "qryDailyReport_Downtime", Replace(Replace(SQL_DailyReportDowntime, "[@DailyReportStartDate]", DailyReportStartDate), "[@DailyReportEndDate]", DailyReportEndDate)
Modify_QuerySQL "qryDailyReport_GeneralNotes", Replace(Replace(SQL_DailyReportGeneralNotes, "[@DailyReportStartDate]", DailyReportStartDate), "[@DailyReportEndDate]", DailyReportEndDate)
Modify_QuerySQL "qryDailyReport_PM", Replace(Replace(SQL_DailyReportPM, "[@DailyReportStartDate]", DailyReportStartDate), "[@DailyReportEndDate]", DailyReportEndDate)
Modify_QuerySQL "qryDailyReport_WorkOrder", Replace(Replace(SQL_DailyReportWorkOrder, "[@DailyReportStartDate]", DailyReportStartDate), "[@DailyReportEndDate]", DailyReportEndDate)
DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, Get_TempPath & reportName & ".pdf", True
End Function
答案 0 :(得分:1)
您可以在此处提供未声明/已分配的变量 DailyReportStartDate 和 DailyReportEndDate :
Modify_QuerySQL "qryDailyReport_Downtime", Replace(Replace(SQL_DailyReportDowntime, "[@DailyReportStartDate]", DailyReportStartDate), "[@DailyReportEndDate]", DailyReportEndDate)
这也没什么意义:
DateValue(#[@DailyReportEndDate]#)
- 如果 DailyReportEndDate 是一个字符串 - 结果是:
DateValue(#2016/06/15#)
应该是:
#2016/06/15#
或 - 如果 DailyReportEndDate 是一个日期 - 被转换为您控制范围之外的格式的字符串,如:
DateValue(#15-06-2016#)
应该是:
#2016/06/15#