473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

To see spcific records

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.
Dec 6 '07 #1
7 1497
ck9663
2,878 Expert 2GB
read this:

http://www.sqlteam.com/article/retur...ber-in-a-query


that will help you create a row number using a query... make that query a subquery and put a WHERE outside it to filter your range.

-- CK
Dec 6 '07 #2
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
Dec 6 '07 #3
ck9663
2,878 Expert 2GB
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


Expand|Select|Wrap|Line Numbers
  1. select * from(SELECT emp_id, lname, fname, job_id,
  2. (SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id) AS rownumber
  3. FROM employee e order by emp_id asc)where rownumber>1 And rownumber<4
  4.  
  5.  
Dec 7 '07 #4
amitpatel66
2,367 Expert 2GB
Check below query, it works:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> select empno,ename,(SELECT COUNT(*) FROM EMP WHERE empno <= e.empno) FROM emp e;
  3.  
  4.     EMPNO ENAME                (SELECTCOUNT(*)FROMEMPWHEREEMPNO<=E.EMPNO)
  5. --------- -------------------- ------------------------------------------
  6.         1 BOND                                                          1
  7.         2 AAAA                                                          2
  8.         3 BBBB                                                          3
  9.         4 CCCC                                                          4
  10.         5 TEST                                                          5
  11.         6 TEST                                                          6
  12.        12 KKKK                                                          7
  13.        17 LLLL                                                          8
  14.        20 MMMM                                                          9
  15.       211 ZZZZ                                                         12
  16.       100 Roopa                                                        11
  17.       100 Roopa                                                        11
  18.  
  19. 12 rows selected.
  20.  
  21. SQL> SELECT * FROM
  22.   2  (select empno,ename,(SELECT COUNT(*) FROM EMP WHERE empno <= e.empno) cnt FROM emp e ORDER BY cnt) x
  23.   3  WHERE cnt BETWEEN 1 AND 5
  24.   4  /
  25.  
  26.     EMPNO ENAME                      CNT
  27. --------- -------------------- ---------
  28.         1 BOND                         1
  29.         2 AAAA                         2
  30.         3 BBBB                         3
  31.         4 CCCC                         4
  32.         5 TEST                         5
  33.  
  34.  
Dec 7 '07 #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.
Dec 7 '07 #6
debasisdas
8,127 Expert 4TB
Try to use UNION & INTERSECT operators.
Dec 7 '07 #7
Jim Doherty
897 Expert 512MB
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 :)
Dec 7 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
6
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...
5
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
13
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...
1
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...
2
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...
1
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...
4
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...
11
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)...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.