How to UPDATE TOP 400? How to UPDATE TOP 400? sql sql

How to UPDATE TOP 400?


 UPDATE db.dbo.tbl SET column1 = 2 WHERE primaryID IN (   SELECT TOP (400) primarkyID FROM db.dbo.tbl   WHERE column2 = 1 AND column1 IS NULL )

But I don't like this as there's no way to guarantee WHICH top 400, you might want to add some other type of criteria. And even an Order By to the subquery.


WITH    q AS        (        SELECT  TOP 400 *        FROM    db.dbo.tb        WHERE   column2 = 1                AND column1 is null        ORDER BY                column3 -- choose your order!        )UPDATE  qSET     column2 = 2


How would you determine the top 400? With no order by there is no guanantee that the same set would always be selected and thus the wrong records could be updated.