2014-04-23 80 views
-1

我收到以下錯誤與此查詢:運算符之間沒有和在查詢表達式[[日期] BETWEEN [StartDate'。錯誤與條款之間

查詢和數據庫是在Access 2010中

在此先感謝您的幫助!

SELECT 
    t1.[Name], 
    Max(t1.[Sum3Areas]) AS [Max] 
FROM (
    SELECT 
     qryUnion.[Name] 
     , Year(qryUnion.[Date]) as dtYear 
     , DatePart("ww",[Date]) + IIF(Weekday([Date]) >= 6,1,0) as dtWeek 
     , SUM(qryUnion.[Amount]) as Sum3Areas 
    FROM (
     SELECT 
      1 as Source, 
      EID As [Name], 
      Closed  As [Amount], 
      DateTime As [Date] 
     FROM IssueTrakINNER 
     JOIN [DateRangeCriteria] 
      ON [DateTime] BETWEEN [StartDate] and [EndDate] 

     UNION ALL 

     SELECT 
      2 as Source, 
      EID AS [Name], 
      Completed As [Amount], 
      DateCompleted AS enter code here[Date] 
     FROM Kana 
     INNER JOIN [DateRangeCriteria] 
      ON [DateTime] BETWEEN [StartDate] and [EndDate] 

     UNION ALL 

     SELECT 
      3 as Source, 
      EID AS [Name], 
      Handled As [Amount], 
      DateTime AS [Date] 
     FROM Chat 
     INNER JOIN [DateRangeCriteria] 
      ON [DateTime] BETWEEN [StartDate] and [EndDate] 
    ) 
    as qryUnion 
    GROUP BY qryUnion.[Name] , Year(qryUnion.[Date]), DatePart("ww",[Date]) + IIF(Weekday([Date]) >= 6,1,0) 
) AS t1 GROUP BY t1.[Name] 
+0

您是否嘗試編輯訪問生成的SQL代碼?這裏發生了什麼? –

回答

0

而是在你JOIN ... ON語句中使用BETWEEN操作的,使用它的WHERE子句。

例如:

select 
    ... 
from tableA 
join tableB 
    on tableA.[DateTime] = tableB.[DateTime] 
where tableA.[DateTime] BETWEEN #mm/dd/yyyy# AND #mm/dd/yyyy#