Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
From VFP auto incremental key to SQL Server
Message
From
16/10/2006 02:54:03
 
 
General information
Forum:
Microsoft SQL Server
Category:
Import/Export
Miscellaneous
Thread ID:
01162137
Message ID:
01162168
Views:
22
>OK. In SQL 2005, you can actually include the OUTPUT keyword into an INSERT statement.
>
>Here's an example that creates a table variable with an identity column, inserts a new row, and outputs the value of the identity column as a result set.
>
>You can also use the scope_identity that I mentioned before, or you can use this.
>
>
>DECLARE @tTestTable TABLE ( MyIdentityCol int IDENTITY, Name char(100))
>
>
>INSERT INTO @tTestTable
>	OUTPUT Inserted.MyIdentityCol
>               VALUES ('KEVIN')
>
>
>Note the reference to 'inserted'....this, along with 'deleted' were two system tables previously available only in insert/update triggers. They're now accessible during an insert/update statement/delete statement.
>
>Not trying to overload you, but figured it might be worth knowing down the road.

Thanks, this is very good. But, this approach requires the creation of a store procedure. As I don't want to create it, as this is done at run time, I need to have everything in the same command. So, for now, I am executing the SQL insert command. Then, after, on another command, I get the primary key. It is basically the same approach as I am using with the VFPOleDb provider which is using a two step approach. Unless you know a way to execute that code as is without having to create anything on disk or in the SQL Server database.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform