将sql查询的结果存储到变量中

将sql查询的结果存储到变量中,sql,vbscript,Sql,Vbscript,我想知道如何将SQL查询的结果分配给变量 我有以下疑问: set userid = Server.CreateObject("adodb.recordset") user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'" userid.Open query,OLSLive,1,3 我想分配查询结果,以便将其作为参数传递给存储过程。假设预期返回一个值,则只需读取记录集的第一个值 userid.Open

我想知道如何将SQL查询的结果分配给变量

我有以下疑问:

set userid = Server.CreateObject("adodb.recordset")

user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'"

userid.Open query,OLSLive,1,3

我想分配查询结果,以便将其作为参数传递给存储过程。

假设预期返回一个值,则只需读取记录集的第一个值

userid.Open query,OLSLive,1,3
if not userid.eof then 'check for rows
  your_variable = userid.collect(0) 'read 1st column, 1st row
  ...
else 
  'no matching row

我猜这是VBScript

userID.Open query,OSLive,1,3

if not userID.eof then
   variableNamedSomething = recordset("id")
else
   ' something else
end if
'... get rid of the connection
 userID.Close
 set userID = nothing
 OSLive.Close
 set OSLive = nothing

对不起,我的回答和另一个一样。。。我正在打字,而另一个被提交了。注:。。。我更喜欢在经典asp ordinals collect0中使用列名,这使得可读性不如collectid好。。。也不要忘记在完成后关闭记录集。。。