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

时间:2011-12-15 12:59:56

标签: sql vbscript

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

我有以下查询:

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

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

userid.Open query,OLSLive,1,3

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

2 个答案:

答案 0 :(得分:0)

假设预计会返回一个值,您只需要读取记录集第1个值;

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

答案 1 :(得分:0)

我猜这是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
相关问题