Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Executing a SQL Server stored procedure
Message
 
 
À
05/03/2001 23:58:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00482118
Message ID:
00482249
Vues:
17
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform