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.
| 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 intSELECT @ID = Isnull(Max(ID), 0) FROM mecEventsinsert into mecevents(ID,installationid,name,enddate,eventtypeid)select @ID+1, class_import.installationid, class_import.name, class_import.date, class_import.eventtypefrom mecevents,class_importwhere 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!" |
|
|
|
|
|