Here is what I used to update the Cancelled flag when there orders that were cancelled and not re-billed (count is an even number):
UPDATE Orders
SET o.Cancelled = 1
FROM Orders o INNER JOIN (SELECT a.Order_ID, convert(int,right(a.Order_ID,2)) as Order_End, case when (x.Count % 2) = 0 then 0...