我想知道如何将SQL查询的结果分配给变量。
我有以下查询:
set userid = Server.CreateObject("adodb.recordset")
user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'"
userid.Open query,OLSLive,1,3
我想分配查询的结果,以便我可以将它作为参数传递给存储过程。
答案 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