title: VBScript - Retrieving a Scalar Value From a Stored Procedure on SQL Server 2008
body: <p>My stored procedure is very simple. It inserts a new record. At the end of it I have the following line:</p>
  
  <pre><code>SELECT SCOPE_IDENTITY()
  </code></pre>
  
  <p>1) Am I using the right code to return the Primary Key value for the newly inserted record?<br>
  2) How do I retrieve this value using ASP Classic/VBScript with ADO Classic?</p>
  
  <pre><code>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
  </code></pre>