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

How to connect a database with sql express.?

574


You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?

110


What is read uncmmited?

585


What are indexers?

631


Why should you use or avoid select * statements?

579






How to rename an existing column with the "sp_rename" stored procedure in ms sql server?

556


How to call stored procedure using http soap?

526


What is the purpose of sql profiler in sql server?

519


What are the different types of stored procedures?

556


What is query processing?

547


How to modify an existing stored procedure in ms sql server?

541


Explain how would you store your query in an SSRS report or a Database server?

90


What are ddl (data definition language) statements for tables in ms sql server?

549


how do you determine the Load performance of any query in sql server {example how do u determine performance of a select stmnt which returns Dynamically many no of records ... some times 100,1000,10000 etc., }

1857


How to count duplicated values in a column in ms sql server?

521