Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 increment primary key insert

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-05 : 09:32:38
Janeen writes "I am trying to insert data into a table that doesn't have an auto-incrementing primary key.
I need to find the max(id) and sequentially add the id's after the max(ID) is determined.
Currently my non-working code looks like this:

********************************************
DECLARE @ID int
SELECT @ID = Isnull(Max(ID), 0)
FROM mecEvents
insert into mecevents(ID,installationid,name,enddate,eventtypeid)
select
@ID+1,
class_import.installationid,
class_import.name,
class_import.date,
class_import.eventtype
from mecevents,class_import
where classid =*class_id and classid = null
********************************************

This inserts the same ID number for each record which causes the query to fail. How do I get the ID to increment as I insert the records?

Thanks!"
   

- Advertisement -