WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Stored Procedure with Return Value


Question:

Sample code for calling procedure:

SQLServer = "(local)" ;This is the name of the SQL Server we point to - can also use IP address.
catalog = "CTNO_TEST" ;This sets the database we need to point to.
table = "tblTeams" ;Could be hard coded in the cSQL, below, rather than using a variable.

cConn = "Provider=SQLOLEDB;Data Source= %SQLServer%;Initial Catalog = %catalog%;Integrated Security=SSPI;"

DB = ObjectOpen("ADODB.Connection")
DB.Open(cConn)
csql = "CTNO_LogEntry @process = '%strProcess%', @team = '%strTeam%', @logdesc1 = '%strLogDesc1%', @logdesc2 = '%strLogDesc2%'"
DB.execute(csql)
DB.close
ObjectClose(DB)
The stored procedure runs just fine. Next item is to have the stored procedure return a value, not a recordset to test run completion. In other cases, I would like it to return the next batch number from a file.

Any ideas?

Answer:

You can use an ADODB.Command Object and the createparameter() method.
oCmd = CreateObject("ADODB.Command")
then your oCmd.CommandText is set to the stored procedure (or if you are using SQL Server, I think you use CALL).

Assume your stored proc returns a integer value, then you would set up something like

prm = oCmd.CreateParameter("[RetVal]", adInteger, adParamOutput) 
oCmd.Parameters.Append(prm) 
use oCmd.Execute, not DB.Execute and prm.Value should contain the stored proc output. At least this will get you started.

Multiple parameters are stored as a 0-based array so oCmd.Parameters(1) and after the command is executed you can obtain its value.


Other resources: http://authors.aspalliance.com/stevesmith/articles/sprocs.asp


Article ID:   W16571
File Created: 2006:10:27:08:44:16
Last Updated: 2006:10:27:08:44:16