Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript - Retrieving a Scalar Value From a Stored Procedure on SQL Server 2008

My stored procedure is very simple. It inserts a new record. At the end of it I have the following line:

SELECT SCOPE_IDENTITY()

1) Am I using the right code to return the Primary Key value for the newly inserted record?
2) How do I retrieve this value using ASP Classic/VBScript with ADO Classic?

Dim cmdUA
Set cmdUA = Server.CreateObject("ADODB.Command")
Set cmdUA.ActiveConnection = tcon
cmdUA.CommandText = "InsertUserAgent"
cmdUA.CommandType = adCmdStoredProc 
cmdUA.Parameters.Append cmdUA.CreateParameter("useragent", adVarWChar, _
adParamInput, 1000)
cmdUA("useragent") = Request.ServerVariables("HTTP_USER_AGENT")
cmdUA.Exec
'Here I need to get the value returned from the stored procedure
Set cmdUA.ActiveConnection = Nothing
Set cmdUA = Nothing
like image 529
HK1 Avatar asked Oct 18 '25 19:10

HK1


1 Answers

The Execute method (NOT Exec) returns a record set which contains the result from the stored procedure.

 Set rs = cmdUA.Execute
 result = rs.Fields(0).Value
like image 196
Richard Schneider Avatar answered Oct 20 '25 16:10

Richard Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!