2014-02-15 128 views
1

下面是我的代碼:SQL語法錯誤

SELECT HOUR(asl.Start_Time) AS [Hour], 
     t.team_name, 
     SUM(CASE WHEN asl.Working = 1 
       THEN asl.Duration_Seconds 
       ELSE 0 END) 
      AS TotalSeconds 
FROM (Agents 
     INNER JOIN Teams AS t 
     ON Agents.team_no = Teams.team_no) 
     INNER JOIN AgentStateLogs AS asl 
     ON Agents.agent_no = asl.Agent_No 
GROUP BY t.team_name, HOUR(asl.Start_Time); 

的問題是,它是說沒有在聲明中丟失的運算符:

SUM(CASE WHEN asl.Working = 1 
      THEN asl.Duration_Seconds 
      ELSE 0 END) 
    AS TotalSeconds 

我一直努力找到它,我不知道錯誤在哪裏。任何人都可以爲我闡明這一點嗎?此代碼正在MS Access 2013中完成。

在此先感謝您。

+1

@ta:d'oh .... *恥辱的頭...... * –

回答

1
CASE WHEN asl.Working = 1 
THEN asl.Duration_Seconds 
ELSE 0 END 

轉換爲JET,這成爲

IIf(asl.Working = 1, asl.Duration_Seconds, 0) 

搜索立即如果the manual以獲取更多信息。