考虑到TimeExited为null,并且计算机名与“ cm”参数相同,我试图更新表Log(具有最新TimeAccessed的字段)的最后一条记录。我有这个但得到错误,“在SQL语句末尾缺少分号”
怎么了??
dbs.Execute "UPDATE Log " _ & "SET TimeExited = " & Format(CloseTime, "\#hh:mm:ss AMPM\#") _ & " WHERE TimeExited is NULL AND ComputerName = '" & cm & "'" _ & " ORDER BY TimeAccessed DESC" _ & " LIMIT 1; "
前两行没什么问题,可以正常工作,这是最后两行带来的问题
Access SQL不会使用LIMIT n它使用use TOP n,并且正如在问题注释中引用提到的那样,不允许您按照所描述的方式使用TOP。相反,您需要按照以下步骤进行操作:
LIMIT n
TOP n
UPDATE Log SET TimeExited = CloseTime WHERE TimeExited IS NULL AND ComputerName='r2d2' AND TimeAccessed IN ( SELECT TOP 1 TimeAccessed FROM Log WHERE TimeExited IS NULL AND ComputerName='r2d2' ORDER BY TimeAccessed DESC )