Solved

VBScript calling SQL Server stored procedure with OUTPUT parameter

Posted on 2006-11-22
3
1,980 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Documenting Data flow 4 55
Need help in debugging a UDF results 7 52
How to structure query with count aggregate 4 43
Database Owner 3 16
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

756 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