Единственный способ обойти это - использовать CTE с вашим ОБНОВЛЕНИЕМ.
Вы можете запустить следующий пример в SSMS:
-- Sample schema.
DECLARE @Data TABLE (
ID INT, [Name] VARCHAR(50), [Status] VARCHAR(50), [Size] INT, [Comment] VARCHAR(50)
);
-- Sample data.
INSERT INTO @Data ( ID, [Name], [Status], [Size], [Comment] ) VALUES
( 1, 'File1', 'Pass', 20, 'Transmitted' ),
( 2, 'File2', 'Pass', 30, 'Transmitted' ),
( 3, 'File3', 'Pass', 50, 'Transmitted' ),
( 4, 'File4', 'Pass', 10, 'Transmitted' );
-- Update all record's [Comment] to 'Completed' with a SizeTotal <= 100.
WITH running_size AS (
SELECT ID, SizeTotal = Size FROM @Data WHERE ID = 1
UNION ALL
SELECT
d.ID, running_size.SizeTotal + d.Size
FROM running_size
INNER JOIN @Data d ON d.ID = ( running_size.ID + 1 )
)
UPDATE @Data
SET
[Comment] = 'Completed'
FROM @Data d
INNER JOIN running_size rs
ON d.ID = rs.ID
WHERE
rs.SizeTotal <= 100;
-- Show me the money.
SELECT * FROM @Data ORDER BY ID;
Возвращает:
+----+-------+--------+------+-------------+
| ID | Name | Status | Size | Comment |
+----+-------+--------+------+-------------+
| 1 | File1 | Pass | 20 | Completed |
| 2 | File2 | Pass | 30 | Completed |
| 3 | File3 | Pass | 50 | Completed |
| 4 | File4 | Pass | 10 | Transmitted |
+----+-------+--------+------+-------------+
Я полагаю, это то, чего вы хотите достичь?