• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

limit clause in MS SQL

 
Ranch Hand
Posts: 162
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic