There may come a time when you need to skip a certain number of rows while querying a database in SQL Server Management Studio. Here is an example used that I see from time to time:
Original data set:
Say we wanted to skip the first 5 records based on the SSN. We could do the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A better solution to this is to use the OFFSET clause:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A catch to this is that you can’t use the TOP clause. If you need to get a TOP number of rows, append the FETCH clause onto OFFSET:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters