Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Executing a SQL Server stored procedure
Message
 
 
To
05/03/2001 23:58:56
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00482118
Message ID:
00482249
Views:
18
>hi,
> How can i execute a sql stored procedure with parameters from VFP?
>
> I have a stored procedure in sql server with 2 inputs parameters and 1 output parameter how can i execute & retrieve the value in output parameter from VFP. Is there a way to trap SQL or ODBC error msgs from VFP?
>
>sanjay.

Sanjay,
Let me jump into this even though it looks like it has already been answered.

First, the errors. Reading your other messages, it looks like you are using RAISERROR() to return an error from your SP. Make sure the severity level is configured high enough for SQL Server to generate an error. The level must be higher than 10 in order for SQLExec() to return a negative value and populate the information for Aerror() to pick up.

To return a value, you must pass it in by reference and then set it in you SP. Ex.
local lx, ly, lz
lx = 'Fred'
ly = 22
lz = ''  && blank variable of whatever datatype you need

* assume lnconn holds you connection handle
if sqlexec(lnconn, [exec mySP ?lx, ?ly, ?@lz]) < 0 then
   =aerror(laerror)
   * process error array laerror
else
   * process information returned and stored in lz
endif
The above VFP code was used with the following example SP:
CREATE PROCEDURE testoutput 
   @var1 varchar(10),
   @var2 int, 
   @var3 varchar(10) OUTPUT
AS
if upper(@var1) = 'FRED'
   set @var3 = 'Astaire'
else
   set @var3 = 'Unknown'
HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform