通过ADO在更新语句中使用select

Jam*_*ken 1 sql vbscript adodb

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

UPDATE table1 
SET    NAME = 'John' 
WHERE  userid IN (SELECT Max(userid) 
                  FROM   table1 
                  WHERE  userid = NULL) 
Run Code Online (Sandbox Code Playgroud)

这成功运行.当我尝试从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
Run Code Online (Sandbox Code Playgroud)

Vam*_*ala 5

userid = NULL在该where条款中将始终返回未知.因此,不会发生更新.

使用userid is null来代替.