通过ADO

时间:2016-05-17 16:13:40

标签: sql vbscript adodb

我可以在我的数据库工具中运行此查询没问题:

UPDATE table1 
SET    NAME = 'John' 
WHERE  userid IN (SELECT Max(userid) 
                  FROM   table1 
                  WHERE  userid = NULL) 

成功运行。当我尝试从VBScript运行这个完全相同的语句时,我没有收到任何错误,并且更新没有发生。谁能告诉我我做错了什么?

Public Function GetAvailableRow()
  Dim conn, command

  On Error Resume Next

  Set conn = CreateObject("adodb.connection")
  Set command = CreateObject("adodb.command")

  conn.IsolationLevel = 1048576

  conn.Open "Driver={Adaptive Server Enterprise}; Server=myserver;port=myport; db=mydatabase;uid=userid;pwd=password;"

  command.ActiveConnection = conn
  command.CommandText = "UPDATE table1 SET name = 'John' WHERE userid in (SELECT MAX(userid) from table1 where userid = NULL)"

  conn.BeginTrans 
  command.Execute
  conn.CommitTrans

  conn.Close

  Set command = Nothing
  Set conn = Nothing
End Function

1 个答案:

答案 0 :(得分:5)

userid = NULL子句中的

where将始终返回未知。因此,更新不会发生。

改为使用userid is null