Between子句出错

时间:2014-04-23 21:32:03

标签: sql ms-access-2010

我在此查询中收到以下错误:在没有和在查询表达式中的运算符之间' [DateTime] 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] 

1 个答案:

答案 0 :(得分:1)

不要在BETWEEN ... JOIN语句中使用ON运算符,而是在WHERE子句中使用它。

例如:

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