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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve the next ID from PK Identity

Status
Not open for further replies.

magmo

Programmer
May 26, 2004
291
SE
Hi


If I use this code...

Code:
SELECT MAX(ID) AS CID FROM dbo.tbl_tablename

The ID is a Primary Key with Identity turned on

What I would like is to retrieve the next ID number instead of the number of rows.

How can I do that?


Regards
 
To get the next ID that will be inserted into a table you can use:

Code:
SELECT IDENT_CURRENT('table') + IDENT_INCR('table') AS nextid

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top