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