Page 1 of 1

Windows ODBC Drivers for BigCommerce - getting new IDENTITY value?

Posted: Tue 29 Jan 2019 17:29
by jgoemaat
Hello!

Using your ODBC driver, is it possible to get the IDENTITY value of the most recently inserted row?

For example, when I INSERT a row to the Categories tables, how do I get the new "Id" value of the record I inserted?

I'm assuming a "hack" would be to pull the max value from the table as the IDENTITY columns are probably sequential/increasing values, but normally in VBA, I can use a command like this after doing the insert:

Code: Select all

newID = db.OpenRecordset("SELECT @@IDENTITY").Fields(0)
Instead of DAO, I could try using ADO in VBA, but wanted to ask before spending a lot of time trying numerous ways.

Other than that, the product is working great so far and had great value!

Thanks!

Re: Windows ODBC Drivers for BigCommerce - getting new IDENTITY value?

Posted: Wed 30 Jan 2019 14:05
by MaximG
You can retrieve the primary key value of the inserted record with help of the "Returning" construct, for example:

Code: Select all

     Insert Into  Brands (Name) Values ('New Name Value') Returning ID