MS Access查询无法正常工作

时间:2014-03-11 10:21:56

标签: sql ms-access case

有人可以解释一下这个查询有什么问题吗?

SELECT Attempts, (CASE WHEN LastLogin IS NOT NULL AND DATE_ADD(LastLogin, INTERVAL 1 MINUTE)>NOW() THEN 1 ELSE 0) AS Denied 
FROM tbl_loginLocks 
WHERE IP = "192.168.178.43";

我收到一条操作丢失的错误。 任何帮助,将不胜感激。 谢谢!

3 个答案:

答案 0 :(得分:1)

您在END

的末尾遗失CASE
SELECT Attempts, (CASE WHEN LastLogin IS NOT NULL AND DATE_ADD(LastLogin, INTERVAL 1 MINUTE)>NOW() THEN 1 ELSE 0 END) AS Denied 
FROM tbl_loginLocks 
WHERE IP = '192.168.178.43';

或者,使用IIF声明:

SELECT Attempts, IIF(LastLogin IS NOT NULL AND DATEADD("n", 1, LastLogin) >NOW(), 1, 0) AS Denied 
FROM tbl_loginLocks 
WHERE IP = '192.168.178.43';

答案 1 :(得分:1)

CASE 声明的末尾添加结束

Date_Add 功能错误

Microsoft Access DateAdd 函数返回添加了特定时间/日期间隔的日期。

<强>语法

Microsoft Access DateAdd函数的语法是:

DateAdd ( interval, number, date )

试试这个

SELECT Attempts, (CASE WHEN LastLogin IS NOT NULL AND DateAdd ("n",1,LastLogin)>NOW() THEN 1 ELSE 0 END) AS Denied 
FROM tbl_loginLocks 
WHERE IP = "192.168.178.43";

答案 2 :(得分:1)

MS Access没有案例陈述,请使用IIF:

SELECT Attempts, 
IIf(Not IsNull(LastLogin) AND DATEADD("n",1,LastLogin)>NOW(),1,0) AS Denied 
FROM tbl_loginLocks 
WHERE IP = "192.168.178.43"

Dateadd
IIF