how to select 5 to 7 rows from a table, which contains 10 rows?

Answer Posted / soorai ganesh

Should Implement ROW_NUMBER() method.

Just take this Example.

Create table emp(empid int, ename varchar(50),salary numeric
(9,2)

Insert into emp values(1,'Employee1',10000)
Insert into emp values(2,'Employee2',20000)
.
.
Insert into emp values(10,'Employee10',100000)

Consider the above table which have 10 records. Now u
want to select 5,6,7 Rows in this table. Just try this
query.

SELECT E.EmpID,E.EName,E.Salary FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY EmpID ASC) AS Rno, *
FROM emp
) E
WHERE E.Rno >= 5 and E.Rno <= 7

Thats all.
If anyone have other such good idea kindly share........

Is This Answer Correct ?    25 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the minimum recommended amount of ram for sql server 2012 enterprise?

495


How to change the name of a database user?

536


What is the sql server 2000 version number?

543


How to see the event list of an existing trigger using sys.trigger_events?

564


What is the difference between executequery () and executeupdate ()?

507






What is the purpose of forms?

483


do views contain data ?

574


What is difference between index and primary key?

576


Explain insert into select statement?

515


What is wide table?

525


Can anyone tell that the extra features are there in SQL SERVER 2008 that are not available in previous versions .

1481


what stored procedure would you use to view lock information? : Sql server administration

572


What do you mean by a Composite primary key?

586


Mention the different types of triggers?

541


Explain temporary table vs table variable by using cursor alternative?

514