Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'START AT' equivalent in MS-SQL?

Tags:

sql

sql-server

Some databases support commands such as:

SELECT TOP 10 START AT 10 * FROM <TABLE>

Essentially I need to pull the first 10 records, then the next 10, then the next 10 etc. Maybe there is another way to do this but in the past I've done it like the above for databases that support 'START AT'.

like image 583
Douglas Anderson Avatar asked Nov 12 '08 18:11

Douglas Anderson


People also ask

Do SQL IDS start at 0 or 1?

if you are populating a code object from a database record, the object will initialize with an "ID" property of 0. Then if the populating is successful it will be something other than the default of 0.

What is starts with in SQL?

%STARTSWITH (SQL) Matches a value with a substring specifying initial characters.

How do I match a starting string in SQL?

To do this, you can use the character class [sp] to match the first letter, and you can use the character class [aeiou] for the second letter in the string. You also need to use the character to match the start of the string, ^ , so all together you'll write "^[sp][aeiou]" .

Does start in SQL?

BEGIN and END keywords are not required in Transact-SQL. BEGIN and END are used in Transact-SQL to group a set of statements into a single compound statement, so that control statements such as IF … ELSE, which affect the performance of only a single SQL statement, can affect the performance of the whole group.


2 Answers

For SQL Server 2012

SELECT * 
FROM <TABLE>
ORDER BY <SomeCol>
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
like image 177
Martin Smith Avatar answered Oct 27 '22 22:10

Martin Smith


Which version of SQL Server?

In SQL Server 2000 this is a real pain (though possible using ugly tricks like that posted by stingyjack).

In 2005 and later it's a little easier- look at the Row_Number() function.

And, depending on your client application it may not even be that hard. Some of the ASP.Net grid controls have support for automatic paging.

like image 45
Joel Coehoorn Avatar answered Oct 28 '22 00:10

Joel Coehoorn