Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql Range

Author  Topic 

yyiiyyii2
Starting Member

5 Posts

Posted - 2007-09-29 : 21:24:23
is there a way to get a range of records using a query for example if only want rows from 10 to 20

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-09-29 : 21:35:15
Does the table have any id column? Which version of sql do you use?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-09-29 : 21:39:37
select top 10 *
from (select to 20 * from tbl order by col) a
order by col desc

with tmp
as
(select col1, col2, col3, row_number() over (order by col1) as rownum from tbl)
select *
from tmp
where rownum between 10 and 20


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yyiiyyii2
Starting Member

5 Posts

Posted - 2007-09-30 : 05:16:37
I am using SQL Express 2005, i hear there was a range feature,

i dont want to join the table to itself cause it is huge
Go to Top of Page

yyiiyyii2
Starting Member

5 Posts

Posted - 2007-09-30 : 05:17:49
yes there is a ID on the column although numbers are not in order and numbers are missing
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-30 : 05:35:29
"for example if only want rows from 10 to 20"

You have to express "rows 10 to 20" in terms of some specific column(s) and an ORDER BY.

SQL Server has no concept of the rows being in a particular order. And if you do a SELECt with NO Order By clause there is NO guarantee that you will get the rows in the same order next time.

Kristen
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-09-30 : 13:39:50
quote:
Originally posted by yyiiyyii2

yes there is a ID on the column although numbers are not in order and numbers are missing



See my earlier post
replace col and col1 by id and either should do what you need.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-09-30 : 19:07:02
Has range operator for mdx query.
Go to Top of Page
   

- Advertisement -