Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get id of autonumber field after inserting

Status
Not open for further replies.

jlynch1

Technical User
Dec 20, 2001
100
IE
i am inserting data into 2 tables.
in one of the tables there is an autonumber field called id.
i need the value of the id in order to put data in the other table.

how do i get that value for the autonumer field id so i can insert data into the other table.
 
This may not be the best way, or the cleanest, but it works:

===================
INSERT INTO someTable VALUES (x,y,z)

newID = SELECT TOP 1 autoNumber FROM someTable ORDER BY autoNumber Desc

INSERT INTO table2 VALUES (newID,p,q,r)

===================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top