我想知道如何将SQL查询的结果分配给变量。将sql查询的结果存储到变量中
我有下面的查询:
set userid = Server.CreateObject("adodb.recordset")
user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'"
userid.Open query,OLSLive,1,3
和我想分配查询的结果,使我可以将它作为一个参数的存储过程。
我想知道如何将SQL查询的结果分配给变量。将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序列中的列名collect(0)使得可读性不如汇集(“id”)将是...也不要忘记当你是关闭你的记录集做... – 2011-12-15 13:11:31
你在VB中是什么意思? – 2011-12-15 13:04:22