开发者

Pagination sql query

开发者 https://www.devze.com 2023-02-25 04:54 出处:网络
Why is this query not working in Sql Server 2008? Select Top @PageSize Skip @Page * @PageSize * From someTable

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

0

精彩评论

暂无评论...
验证码 换一张
取 消