Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

limit clause in MS SQL

 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

There is limit clause in MY SQL wich get specfic number of records from
specific row.
How we can achieve this in MS SQL Server 2000.

Any Link appreciated.

Thanks
- Kuldeep
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MS SQL has the "top" keyword, e.g. :

will get you the first ten results from that table.
[ November 05, 2008: Message edited by: Paul Sturrock ]
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

MS SQL has the "top" keyword,


Your are right but if I want records from
10 to 15 then how should i get it ?
 
Kaleeswaran Karuppusamy
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kuldeep Yadav:
Hi Paul,



Your are right but if I want records from
10 to 15 then how should i get it ?


SELECT custid
FROM (SELECT TOP (2) custid
FROM (SELECT TOP (3) custid
FROM customer) AS foo
ORDER BY custid DESC) AS bar
ORDER BY custid

x is the number of rows you want returned and y is x+offset.
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kaleeswaran,

Thanks for your solution . It gives me required result.
I want to use this solution for different tables. So
I have 2 way for implementing this solution
  • To create prepared Statement for this query and using it
  • Creating stored procedure for it .and called it fro java code



  • Which one is better ?

    Thanks
    - Kuldeep
    [ November 05, 2008: Message edited by: Kuldeep Yadav ]
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic