我已經看到了很多其他人提出,並通過谷歌回答了這一點,但有一個額外的問題,別人沒有覆蓋的功能。我的情況是我從控制器程序AUTOMATE調用Access查詢。該過程將按照前一個月的數據每月運行一次。調用從查詢條件
我的意圖是使用Access中的模塊中聲明的兩個函數將日期範圍置於WHERE
子句中,但我發現將它放在查詢條件行上似乎是一個問題。
這裏有兩個功能:
'##################################################################################
' This function returns the date string for the first day of the prior month.
'##################################################################################
Public Function FirstDayPriorMonth() As Date
Dim dateEnd As Date
dateEnd = DateSerial(Year(Date), Month(Date), 0)
FirstDayPriorMonth = dateEnd - Day(dateEnd) + 1
End Function
'##################################################################################
' This function returns the date string for the last day of the prior month.
'##################################################################################
Public Function LastDayPriorMonth() As Date
LastDayPriorMonth = DateSerial(Year(Date), Month(Date), 0)
End Function
從自動化調用使用DoCmd.OpenQuery
致電查詢。全查詢的SQL版本是這樣的:
SELECT dbo_V_HB_Outsourced_AR.REPORTING_DATE,
dbo_V_HB_Outsourced_AR.REPORTING_FISCAL_YEAR AS FY,
dbo_V_HB_Outsourced_AR.LOC_NAME AS FACILITY,
dbo_V_HB_Outsourced_AR.REVCBO_LEGACY_FINANCIAL_CLASS,
dbo_V_HB_Outsourced_AR.EPIC_FINANCIAL_CLASS,
dbo_V_HB_Outsourced_AR.PRIMARY_FIN_CLASS_NAME,
dbo_V_HB_Outsourced_AR.ACCT_STATUS_NAME,
dbo_V_HB_Outsourced_AR.OUTSOURCED_FLAG_YN,
dbo_V_HB_Outsourced_AR.IN_HOUSE_FLAG_YN,
dbo_V_HB_Outsourced_AR.DNFB,
dbo_V_HB_Outsourced_AR.[0-30],
dbo_V_HB_Outsourced_AR.[31-60],
dbo_V_HB_Outsourced_AR.[61-90],
dbo_V_HB_Outsourced_AR.[91-120],
dbo_V_HB_Outsourced_AR.[121-150],
dbo_V_HB_Outsourced_AR.[151-180],
dbo_V_HB_Outsourced_AR.[181-210],
dbo_V_HB_Outsourced_AR.[211-240],
dbo_V_HB_Outsourced_AR.[241-365],
dbo_V_HB_Outsourced_AR.[366+],
dbo_V_HB_Outsourced_AR.[CR BAL],
dbo_V_HB_Outsourced_AR.[Total (Debit Only)],
dbo_V_HB_Outsourced_AR.[Over 90],
dbo_V_HB_Outsourced_AR.COL_AGNCY_NAME
FROM dbo_V_HB_Outsourced_AR
WHERE (((dbo_V_HB_Outsourced_AR.REPORTING_DATE) Between [FirstDayPriorMonth] And [LastDayPriorMonth])
AND ((dbo_V_HB_Outsourced_AR.COL_AGNCY_NAME)='ADVICARE'
Or (dbo_V_HB_Outsourced_AR.COL_AGNCY_NAME)='CONVERGENT'
Or (dbo_V_HB_Outsourced_AR.COL_AGNCY_NAME)='MEDALIST MANAGEMENT')
AND ((dbo_V_HB_Outsourced_AR.LOC_ID)=1010
Or (dbo_V_HB_Outsourced_AR.LOC_ID)=1011
Or (dbo_V_HB_Outsourced_AR.LOC_ID)=1012
Or (dbo_V_HB_Outsourced_AR.LOC_ID)=1013
Or (dbo_V_HB_Outsourced_AR.LOC_ID)=1014));
我的問題是,爲什麼可以看到查詢條件線函數調用,但必須改變在SQL視圖的查詢?我仍然在努力讓函數調用在SQL視圖中工作。