Solved

VBScript calling SQL Server stored procedure with OUTPUT parameter

Posted on 2006-11-22
3
1,994 Views
Last Modified: 2007-12-19
Hi - I have a VBS file that I use to execute a SQL Server stored procedure, but I want to enhance it by retrieving a "Status" indicator when the stored proc ends.  I don't think I can use a RETURN value in the stored proc so I added an OUTPUT parameter.

The stored proc has two input parameters and one output parameter.  When it had just the two input parameters I called in from VBS like this:

NOTE: cn is an ADODB connection object.

cn.Execute("MyProc 'N', 1)

That works fine.  With the new output parameter (@RETURN_STATUS INTEGER OUTPUT), I am trying to call the stored proc like this:

Dim RetVal
RetVal = 99
cn.Execute("MyProc 'N', 1, @RETURN_STATUS = " & RetVal & " OUTPUT")

I get the following error message:

[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use the OUTPUT option when passing a constant to a stored procedure.

NOTE: I tested the stored proc in SQL Server like this:

declare @rtn integer
exec MyProc 'N',1,@RETURN_STATUS = @rtn OUTPUT
print 'Return value = ' + cast(@rtn as varchar)

Can anyone tell me how I can call the stored proc using the connection object and get the value of the output parameter?
Do I have to use a command object?

Thanks!
0
Comment
Question by:wlevy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
azserrata earned 250 total points
ID: 17996616
Hello

Take a look here

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

specially point 4 about ("Any time you need to get data back from a stored procedure via a parameter")

Cheers
azserrata
0
 

Author Comment

by:wlevy
ID: 17997684
Thank you azserrata that is exactly what I needed.
0
 
LVL 3

Expert Comment

by:azserrata
ID: 17997735
Great!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question