• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

sql select only specfic number of rows

Hi,

How can we restrict to select maximum of 100 rows in SQL.
Some times, i will have having 100000 records in d/b but i need to fetch only  maximum of 100 rows please let me know how I can achieve this in SQL. Once i get 100 roes i want to bind it to ASP.net grid.
0
ram27
Asked:
ram27
2 Solutions
 
MrJesse34Commented:
Add the SAMPLE 100 to the end

SELECT * FROM TABLE WHERE X = Y SAMPLE 100
0
 
David L. HansenProgrammer AnalystCommented:
I like to use the "SELECT top(100) * FROM..." method.  Note, you can change the 100 to any integer value and NO comma is needed before the * (ie. no comma between the "(100)" and the "*").
0
 
BrandonGalderisiCommented:
To add on to the correct answer that sl8rz has already provided

"you can change the 100 to any integer value"

It can also be an INT variable.  so if you are passing the value into a procedure.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now