Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

limit clause in MS SQL

 
Ranch Hand
Posts: 162
Hibernate Spring Java
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • 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 Spring Java
  • 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 ?
 
Ranch Hand
Posts: 155
  • 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 Spring Java
  • 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 ]
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!