Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting SQL Server stored proc return value
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00856398
Message ID:
00857479
Vues:
35
Hi Peter,

There're few problems with your VFP code. First, you've to check return value of VFP SPT functions. The negative value would indicate that there was an ODBC error. The AERROR() function can provide detailed information about it. Second, the output parameters should be passed to SQLEXEC by reference. Also, you don't need SQLPREPARE() function.
gnConnHandle = SQLCONNECT('qcm_Connect1')  
IF gnConnHandle < 0
  = AERROR(laOdbcError)
  * ODBC Error cannot proceed further
  ...
ENDIF
pcbabychgid = ""
lcSQLQry = [EXEC dbo.usp_create_char_key 'dbo.babychg', 'babychgid', 12, ?@pcbabychgid]
lnSptResult = SQLEXEC(gnConnHandle, lcSQLQry)
IF lnSptResult < 0
  = AERROR(laOdbcError)
  * ODBC Error cannot proceed further
  ...
ENDIF
...
* OR if you need Stored procedure return value
pnRetval = 0
pcbabychgid = ""
lcSQLQry = [{?@pnRetval=CALL dbo.usp_create_char_key('dbo.babychg', 'babychgid', 12, ?@pcbabychgid)}]
lnSptResult = SQLEXEC(gnConnHandle, lcSQLQry)
IF lnSptResult < 0
  = AERROR(laOdbcError)
  * ODBC Error cannot proceed further
  ...
ENDIF
...
Next time please create new thread for your question.

<snip>

>It correctly returns the desired result to the calling proc in SQL which then uses that value for further processing. So I have attempted to translate this into VFP dialog based upon info in this thread as follows:
>
>*// VFP code used to emulate SQL proc call as above
> STORE SQLCONNECT('qcm_Connect1') TO gnConnHandle
>
> PRIVATE pcbabychgid
> pcbabychgid = ''
>
> lcSQLQry = "EXEC dbo.usp_create_char_key 'dbo.babychg', 'babychgid', 12, ?pcbabychgid OUTPUT"
> w = SQLPREPARE(gnConnHandle, lcSQLQry)
> y = SQLEXEC(gnConnHandle)
> x = pcbabychgid
>
>*// end of VFP code used to emulate SQL proc call as above
>
<snip>
>
>Since the above failed, based upon data in this thread I have now also tried the alternate approaches as below:
>Version a.
> lcSQLQry = [{?@pnRetval=CALL dbo.usp_create_char_key 'dbo.babychg', 'babychgid', 12, ?pcbabychgid OUTPUT}]
> w = SQLPREPARE(gnConnHandle, lcSQLQry)
> y = SQLEXEC(gnConnHandle)
> x = pcbabychgid
>
>Version b
> lnResult = SQLEXEC(gnConnHandle, [{?@pnRetval=CALL dbo.usp_create_char_key 'dbo.babychg', 'babychgid', 12, ?pcbabychgid OUTPUT}])
> x = pcbabychgid
>
>So far, none of these options has produced the desired result. Do you have any clues as to what I am doing wrong? Please advise. Thnx. /psb
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform