September 23, 2002 at 4:58 am
Hi,
Table contains 20 rows. I Want to get 10 - 15 rows using SQL Query. Here i am using Sql Server 7.0 Version.
Waiting for valuable reply
September 23, 2002 at 7:08 am
You have an attribute called Top within the select statement... that essentially limits the number of records returned.... but only the first n records... u can't get say 10th to the 15th record.. only the first say 10 records.. or 11 or whatever...
the other option is using set rowcount and then iterate the recordet to get the required records.... say fetch the 10 records and then next 10 records..
Regards,
Hermit Dave
quote:
Hi,Table contains 20 rows. I Want to get 10 - 15 rows using SQL Query. Here i am using Sql Server 7.0 Version.
Waiting for valuable reply
Edited by - hermitd on 09/24/2002 03:03:39 AM
Regards,
Dave
September 23, 2002 at 8:29 am
quote:
You have an attribute called Top within the select statement... that essentially limits the number of records returned.... but only the first n records... u can't get say 10th to the 15th record.. only the first say 10 records.. or 11 or whatever...the other option is using set rowcount and then iterate the recordet to get the required records.... say fetch the 10 records and then next 10 records..
Regards,
Dave
quote:
Hi,Table contains 20 rows. I Want to get 10 - 15 rows using SQL Query. Here i am using Sql Server 7.0 Version.
Waiting for valuable reply
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
September 23, 2002 at 8:31 am
Here is an example of a way you can retrieve 10-15 without a cursor using the top and order by clauses.
Create table top_test (id int identity, description char(1))
insert into top_test values('a')
insert into top_test values('b')
insert into top_test values('c')
insert into top_test values('d')
insert into top_test values('e')
insert into top_test values('f')
insert into top_test values('g')
insert into top_test values('h')
insert into top_test values('i')
insert into top_test values('j')
insert into top_test values('k')
insert into top_test values('l')
insert into top_test values('m')
insert into top_test values('n')
insert into top_test values('o')
insert into top_test values('p')
insert into top_test values('q')
insert into top_test values('r')
insert into top_test values('s')
select * from (select top 6 * from (select top 15 * from top_test
order by id asc) a
order by id desc) b
order by id asc
drop table top_test
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
September 24, 2002 at 2:31 am
OK Thanks
September 26, 2002 at 2:02 pm
/*
This is the way I use: For example, pub..authors, order by au_lname from the 6th to 10th row.
I use a Java static funcion to generate it for my JSP search pages.
*/
use pubs
go
select *
fromauthors as x,
(select top 10 au_id from authors order by au_lname ) as a
wherex.au_id= a.au_id and
not exists
(select * from (select top 5 au_id from authors order by au_lname ) as b where x.au_id=b.au_id )
order by au_lname
quote:
Hi,Table contains 20 rows. I Want to get 10 - 15 rows using SQL Query. Here i am using Sql Server 7.0 Version.
Waiting for valuable reply
September 26, 2002 at 3:26 pm
I had to do something like this recently. I did it a little differently. Fist I formulated my sql query with an INSERT INTO xTable and inserted an identity column called ID. I then grouped my sql statements by using BETWEEN and then unioned them all together.
SELECT IDENTITY(int, 1,1) AS [ID],
v1.[TimeStamp], v1.Value AS 'Bytes Total/sec',
v2.Value AS 'Files Open', v3.Value AS 'Server Sessions' INTO xTable
FROM Wrksta . . .
Select blah from xTable where ID between x and x
UNION
Select blah from xTable where ID between x and x
And so forth . . .
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply