[英]Store the result of an sql query into a variable
I would like to know how I could assign the result of an SQL query to a variable.我想知道如何将 SQL 查询的结果分配给变量。
I have the query below :我有以下查询:
set userid = Server.CreateObject("adodb.recordset")
user = "SELECT id FROM Users WHERE UserEmail = '" & UserEmail & "'"
userid.Open query,OLSLive,1,3
and I would like to assign the result of the query so that I can pass it as a parameter to a stored procedure.我想分配查询的结果,以便我可以将它作为参数传递给存储过程。
Assuming one value is expected to be returned you simply need to read the recordsets 1st value;假设期望返回一个值,您只需要读取记录集的第一个值;
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
I'm going to guess that this is VBScript...我猜这是 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.