Hi everybody
I need a query in sqlserver through which i can retrieve the records which are present in the middle part of the table.I mean suppose table has 100 records,then I want to retrive 50 to 70(20 nos of records) records.
7 1497
hello
by your suggestion i got the query to create a column with rownumber .But i can't get the specific record.my query is
select * from(SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id) AS rownumber
FROM employee e order by emp_id asc)where rownumber>1 And rownumber<4
hello
by your suggestion i got the query to create a column with rownumber .But i can't get the specific record.my query is
select * from(SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id) AS rownumber
FROM employee e order by emp_id asc)where rownumber>1 And rownumber<4
i'll assume that the table name, fields and primary key are correct..
try:
select * from (SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id) AS rownumber
FROM employee e order by emp_id asc) A where rownumber between 1 and 4 - select * from(SELECT emp_id, lname, fname, job_id,
-
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id) AS rownumber
-
FROM employee e order by emp_id asc)where rownumber>1 And rownumber<4
-
-
Check below query, it works: -
-
SQL> select empno,ename,(SELECT COUNT(*) FROM EMP WHERE empno <= e.empno) FROM emp e;
-
-
EMPNO ENAME (SELECTCOUNT(*)FROMEMPWHEREEMPNO<=E.EMPNO)
-
--------- -------------------- ------------------------------------------
-
1 BOND 1
-
2 AAAA 2
-
3 BBBB 3
-
4 CCCC 4
-
5 TEST 5
-
6 TEST 6
-
12 KKKK 7
-
17 LLLL 8
-
20 MMMM 9
-
211 ZZZZ 12
-
100 Roopa 11
-
100 Roopa 11
-
-
12 rows selected.
-
-
SQL> SELECT * FROM
-
2 (select empno,ename,(SELECT COUNT(*) FROM EMP WHERE empno <= e.empno) cnt FROM emp e ORDER BY cnt) x
-
3 WHERE cnt BETWEEN 1 AND 5
-
4 /
-
-
EMPNO ENAME CNT
-
--------- -------------------- ---------
-
1 BOND 1
-
2 AAAA 2
-
3 BBBB 3
-
4 CCCC 4
-
5 TEST 5
-
-
hello
I run the query but it shows the error.Again i remembering you this try is in sqlserver not in oracle.
SELECT * FROM (SELECT job_id,lname,(SELECT COUNT(*) FROM employee WHERE job_id <= e.job_id) cnt FROM employee e ORDER BY cnt) x
WHERE cnt BETWEEN 1 AND 5
->The error message is bellow
Server: Msg 1033, Level 15, State 1, Line 4
The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
Try to use UNION & INTERSECT operators.
Hi everybody
I need a query in sqlserver through which i can retrieve the records which are present in the middle part of the table.I mean suppose table has 100 records,then I want to retrive 50 to 70(20 nos of records) records.
If I am reading you correctly you are basically paging records. Have a look at this interesting blog thread as one method to deal with your question. http://weblogs.sqlteam.com/jeffs/arc...3/22/1085.aspx
Jim :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CSDunn |
last post by:
Hello,
I have an Access 2000 Project in which the data comes from a SQL Server 2000
database, and multiple users need to be able to see new records as each user
adds records. The users also need...
|
by: Paul T. Rong |
last post by:
Dear all,
Here is my problem:
There is a table "products" in my access database, since some of the
products are out of date and stopped manufacture, I would like to delete
those PRODUCTS from...
|
by: Grant |
last post by:
Hi
Is there a way to recover deleted records from a table. A mass deletion has
occurred and Access has been closed since it happened
Louis
|
by: Jan |
last post by:
Hi
I have a database that I use to keep track of the sales promotions that we
send to companies.
I normally send a mailing based on a subset of the companies in the database
(found using the...
|
by: KC |
last post by:
Hello,
I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB.
I have tweaked this DB to work for our small co. It has worked pretty
well up until I made the mistake of deleting...
|
by: Niron kag |
last post by:
Hello !
With c# ,I want to get a number with a spcific number of digits after the
point ,
for example if the specific number is '2' :
for this number 334.23523
I want to get 334.23
How can I...
|
by: Niron kag |
last post by:
Hello !
With c# ,I want to get a number with a spcific number of digits after the
point , for example if the specific number is '2' :
for this number 334.23523
I want to get 334.23 (2 digits...
|
by: LetMeDoIt |
last post by:
Greetings,
I'm using ASP to retrieve from MSSQL and I then populate a table.
After several months of successfull retrieves, this same code now
bombs out. It turns out that if I clear out from...
|
by: shriil |
last post by:
Hi
I have this database that calculates and stores the incentive amount
earned by employees of a particular department. Each record is
entered
by entering the Date, Shift (morn, eve, or night)...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |