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.
ram27Asked:
Who is Participating?
 
David L. HansenConnect With a Mentor Programmer 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
 
MrJesse34Commented:
Add the SAMPLE 100 to the end

SELECT * FROM TABLE WHERE X = Y SAMPLE 100
0
 
BrandonGalderisiConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.