Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Capturing the output clause
Message
 
À
11/08/2009 13:09:10
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01417348
Message ID:
01417350
Vues:
62
>SQL Server has a 'nifty' output clause, however, I can't figure out how to capture the return value when using SQLExec. If my sql command is of the form "insert into tablename (code) output inserted.PrimaryKeyName values ('XXX')" and I run it in SQL Server management Studio it returns the primary key value on the screen. However, if I run the same command with SQLExec it only returns a negative number if not successful and a positive number indicating the number of records affected if successful. In VFP code how do I capture the 'inserted.PrimaryKeyName value'? Thanks!

What is your PK?
Some IDENTITY column?
If so use this:
TEXT TO lcInsert NOSHOW TEXTMERGE
     INSERT INTO TableName (Code) VALUES(?lcCode)
     SELECT SCOPE_IDENTITY() AS NewPK
ENDTEXT
IF SQLEXEC(lnSQLHandler, lcInsert, "crsNewPk") < 0
   AERROR(laError)
   MessageBox(laError[1,2])
   RETURN
ENDIF
WAIT WINDOW "New PK values is "+TRANSFORM(crsNewPk.NewPk)
or use Stored Procedure or use CursorAdapter :-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform