Basically I need to run this on a table with 40 million rows, updating every row at once will crash, so I want to batch the query so that if it crash, it can re-run the quer
Select 1; -- this will set a rowcount
WHILE (@@Rowcount > 0)
BEGIN
UPDATE TOP (1000000) [table]
SET [New_ID] = [Old_ID]
WHERE [New_ID] <> [Old_ID]
or ([New_ID] is null and [Old_ID] is not null)
END
100000 may work better for the top.
Since NewID and OldID is not null then the is null check is not necessary.