Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return a value from a server stored procedure

Client-Server and ODBC

How to return a value from a server stored procedure

by  foxdev  Posted    (Edited  )
In order to standardize a certain operation and/or enhance security, it is sometimes desirable to invoke a stored procedure on the database server and have that stored procedure return a single value to Visual FoxPro. Typically, returned results are in the form of a VFP cursor, but this incurs additional overhead in your VFP source, because you must store the result set's value into a memory variable then remember to close the cursor.

ODBC supports output parameters that allows you to receive a return value without using a result set. For example, say you want to determine if a customer exists in the database server's Customer table, and if so, what that Customer's status is.

The VFP code would be:

[tt]cOutParam = ""
sqlexec(nHandle, "{CALL sp_chkcustomer ('12345', ?@cOutParam)}") [/tt]

An example MS SQL Server stored procedure would be:

[tt]create procedure sp_chkcustomer
@cCustID char(10),
@cReturn char(1) OUTPUT
AS
declare @cStatus char(1)
select @cStatus=status from customer
where CustomerID = @cCustID
if @@rowcount = 0
set cReturn = "N"
else
set cReturn = @cStatus
return(0)
[/tt]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top