UPDATE b SET OrderIndex = a.OrderIndex FROM ( SELECT RTRIM(ROW_NUMBER() OVER ( PARTITION BY [ItemID] ORDER BY ID )) AS OrderIndex,IDFROM [MTIDB].[dbo].[ExperimentItem])a,[MTIDB].[dbo].[ExperimentItem] b WHERE a.ID = b.ID