over 5 years ago
It is a common requirement in SQL server development to update top N records in SQL server.In this blog we will see two approaches to accomplish the same.
1) Using UPDATE with TOP
UPDATE TOP (100) Table1 SET field1 = 1
However without an ORDER BY the whole idea of TOP is vague, since there's no way to guarantee WHICH top N rows we are updating.
2) Using CTE
;WITH CTE AS
SELECT TOP 100 *
ORDER BY F2
UPDATE CTE SET field1=1
In the above query we are using the ORDER BY on column F2 before updating. So now we have control on which N rows we are updating.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2021 FindNerd.com. All rights reserved.
Sign up using