devxlogo

Identity?

Question:
I’m trying to get the Identity of records as I insert them into my database. I have tried: OrderID = DataConn.Execute(“SELECT @@IDENTITY FROM Orders”). But this returns a syntax errorat ‘@@IDENTITY’. I am using JScript with NT4 and MS Access.

Answer:
What you really want is to select the column name with the Identity property. So, if the column that has the identity property is called iFramis, you would ask for SELECT iFramis from Orders. @@identity might just give you the last integer used in the column.

create table junk (iid, identity (1,1))goinsert junk default valuesgoinsert junk default valuesgoselect iid from junkselect @@identity from junk

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.