File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes limit clause  in MS SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "limit clause  in MS SQL" Watch "limit clause  in MS SQL" New topic
Author

limit clause in MS SQL

Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

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

Joined: Apr 14, 2004
Posts: 10336

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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

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 Karuppasamy
Ranch Hand

Joined: Jul 19, 2007
Posts: 154
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.


Judge a man by his questions rather than his answers --Voltaire
SCJP 1.5 97%
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

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 ]
     
    jQuery in Action, 2nd edition
     
    subject: limit clause in MS SQL
     
    Similar Threads
    large collections in hibernate.
    Another statement to worry about... MS Access related
    Manipulating Array Data
    hi all problem in resultset
    Is there any limit on the length of Strings...