Вы можете использовать табличное выражение как источник и цель для MERGE
.
WITH SA AS
(
SELECT TOP(10) sub_id,
exam_batch
FROM StudentAllocation
ORDER BY sub_id
)
MERGE SA
USING (SELECT @sub_id AS subId) AS TSA ON SA.sub_id = TSA.subId
WHEN MATCHED THEN
UPDATE SET SA.exam_batch = 1;
хотя может быть проще использовать
WITH SA AS
(
SELECT TOP(10) sub_id,
exam_batch
FROM StudentAllocation
ORDER BY sub_id
)
UPDATE SA
SET exam_batch = 1
WHERE sub_id = @sub_id;