I'm new to SQL (about 2 days now) and I'm piecing some code together to import some rows from one db to another. The one that I am inserting into does not use auto-incrementing numbers on the primary column... (making this very difficult for me) I need to insert the rows after the highest number.See below:DECLARE @MaxID intSELECT @MaxID = (SELECT MAX(TSPID) FROM HSDB.dbo.TSP)SELECT @MaxIDCREATE TABLE #ACT(TSPID INT IDENTITY(@MaxID,1)AC nvarchar(100) NOT NULL,NAME nvarchar(30) NOT NULL,LU smalldatetime NOT NULL)-- insert GX1 into tempINSERT #ACT (AC, Name, LU)SELECT AC, Name, LU FROM GX1.dbo.AC-- insert from temp into HSDBINSERT HSDB.dbo.TSP (TSPID, TSPTypeID, PV, Name, Arguments, Created, Changed)SELECT TSPID, 1, AC, Name, '', LU, GetDate() FROM #ACT-- prevent dupesWhere AC NOT IN (SELECT PV FROM HSDB.dbo.TSP)ANDAC between 10000 and 99999
Basically I can't alter the DB from the software I'm importing into, but I have several hundred records that need to be inserted manually.I created the temp so I can make my own incrementing field, but i need it to start at the last number from TSP... which is what the MaxID variable is for.Am I completely off base with this?