Friday, May 22, 2009

if i have 1000 records and i want to access 20 at a time from SQL server, what will be the query?

Use top keyword to fetch the first 20 records from sql server.

for example:
select top 20 * from emp.

you can also use
Set Rowcount keyword to fetch the records from sql server.

ex:
Set Rowcount 20
Select Empname from emp
Set RowCount 0
How to retrieve range of 10th rows to 20 th rows from total rows from a database table.? (Not from Dataset)
select top 10 ID from table1 where ID not in (select top 10 ID from table1)
using row_number() function
 SELECT customerid,customername
FROM (SELECT ROW_NUMBER() OVER (ORDER BY customerid ASC)
AS Row, customerid, customername FROM tbl_customermaster)
AS customermasterWithRowNumbers
WHERE Row >= 10 AND Row <= 20



No comments:

Post a Comment