Something like this should work for you. I'm assuming the new OK_ID will be generated same day the first issue was over. If not, Can you explain your business on how to determine CONTIGUOS dates?SELECT IDENTITY(int,1,1) AS Seq,OK_ID,Cust_ID,Proc_ID,StartDt,CompleteDT,Category,Location INTO #TempFROM YourTableORDER BY Category,Location,RowNoSELECT t2.*,t1.OK_ID as OriginalWorkIDFROM #Temp t1INNER JOIN #Temp t2ON t2.ID=t1.ID + 1AND t2.Category=t1.CategoryAND t2.Location=t1.LocationAND t2.StartDt=t1.CompleteDT