Probably what you'll want to do is create an "OldId" field that references the original records.I think this script will do what you want.DROP TABLE FlightDROP TABLE #FlightWorkCREATE TABLE Flight ( ID INT IDENTITY(1, 1) PRIMARY KEY, ExceptionID INT NULL, Price MONEY NULL, FareClassID INT NULL, Active BIT NULL)GOINSERT INTO Flight (ExceptionId, Price, FareClassID, Active) VALUES (0, 30, 1, 1)INSERT INTO Flight (ExceptionId, Price, FareClassID, Active) VALUES (0, 20, 2, 1)INSERT INTO Flight (ExceptionId, Price, FareClassID, Active) VALUES (1, 40, 1, 1)GOSELECT * INTO #FlightWork FROM FlightGOALTER TABLE #FlightWorkADD OldId INT NULLGOINSERT INTO #FlightWork (ExceptionId, Price, FareClassID, Active, OldId)SELECT ExceptionId, Price, FareClassID, Active, IDFROM FlightGO--This will set the ExceptionIds. The ISNULL is to deal with the fact--that you're using zeros instead of NULLs in the ExceptionID column.UPDATE #FlightWork SET ExceptionId = ISNULL((SELECT ID FROM #FlightWork WHERE F.ExceptionId = OldId), 0)FROM #FlightWork FW INNER JOIN Flight F ON FW.OldId = F.IDGO--I think #FlightWork contains the result you're looking for.
--Baldeep