开发者

Lib for LIMIT statement in SQL SERVER?

Is there 开发者_开发百科some lib or function i can use to take my basic sql statement and transform the limit statement to a sql server compatible statement?


The closest equivalent of MySQL's LIMIT function is the TOP function. So

Select..
From Table
LIMIT 10

In SQL Server this would be:

Select TOP 10 ...
From Table
Order By ...

ADDITION

Per your comments, you are asking about mimicking the offset parameter on LIMIT. You can do that with a CTE in SQL Server 2005+:

With NumberedItems As
    (
    Select ...
        , ROW_NUMBER() OVER ( Order By ... ) As Num
    From Table
    )
Select ...
From NumberedItems
Where Num Between 5 And 20


Sounds like you're wanting to use LIMIT's offset functionality for pagination, in which case the SO question "What is the best way to paginate results in MS SQLServer" has a very good accepted answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜