Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sqlserver how to call a procedure that send back a value
Message
From
09/06/2012 11:16:15
Vladimir Zhuravlev
Institute of the Physics of Earth,Russia
Moscow Region, Russia
 
 
To
08/06/2012 08:54:46
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
01545648
Message ID:
01545725
Views:
78
>i want to call a sqlserver procedure that make a calculation and send back the result to vpf. how to do it?
If you have output parameters in your SQL Server procedure, you can call
it with @ for output parameter, seting variable for this parameter in VFP in advance
Here is the sample
con=SQLCONNECT('pubs','sa','')
?con
par=0
inp=0
?SQLEXEC(con,'myproc ?@par,?inp','query')

?SQLEXEC(con,'exec myproc ?@par,?inp','query')
?par
sqldisconnect(0)

***
Here par is output parameter in SQL server procedure
Other 2 parameters are input parameters
****
OR Other sample with text of procedure

hConn = SQLConnect("odbcpubs", "sa", "")
LOCAL lcQuery, lnResult
lcQuery = ;
"CREATE PROCEDURE p_productcount " + ;
"@ProductId INT, " + ;
"@StartDate DATETIME, " + ;
"@EndDate DATETIME, " + ;
"@QtySold INT OUTPUT " + ;
"AS " + ;
"SELECT @QtySold = SUM(od.Quantity) " + ;
"FROM Orders o INNER JOIN [Order Details] od " + ;
"ON o.OrderId = od.OrderId " + ;
"WHERE od.ProductId = @ProductId " + ;
"AND o.OrderDate BETWEEN @StartDate AND @EndDate "
lnResult = SQLExec(hConn, lcQuery)
*
LOCAL lnTotalCnt, lcQuery
lnTotalCnt = 0
lcQuery = "EXECUTE p_ProductCount 72, '19960701', '19960801', ?@lnTotalCnt"
lnResult = SQLExec(hConn, lcQuery)

*****
lnTotalCn is output variable in procedure
MVP-2006-2011, PHD in Math and Physics ,
host of www.foxclub.ru,
VFP lector at Interface and Microinform companies
Head science researcher of VNIIA Rosatom.
Previous
Reply
Map
View

Click here to load this message in the networking platform