Pagination sql query
Why is this query not working in Sql Server 2008?
Select Top @PageSize Skip @Page * @PageSize * From someTable
Strangely even this doesn't work :-
Select Top @PageSize * From Tree
But开发者_开发问答 this one works :-
Select Top 10 * From Tree
This statement is inside Stored procedure.
Thanks in advance :)
Your first query is not valid syntax at all.
The second one just needs brackets (and should have an ORDER BY
)
Select Top (@PageSize) *
From Tree
ORDER BY /*TODO: Add column(s)*/
To achieve what you are apparently trying to do in the first case you can use ROW_NUMBER
and BETWEEN
as in this answer T-SQL Skip Take Stored Procedure
you need parentheses
Select Top ( @PageSize ) * From Tree
However without an order by it doesn't make a lot of sense
SKIP is not valid SQL Server syntax, the first query won't work
精彩评论