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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select statement

Author  Topic 

pintosack
Starting Member

4 Posts

Posted - 2007-02-27 : 10:37:41
Hi everyone...
I've been trying to find a select statement that will start at a certain record, then select all the records from that record to the top. For example, if there is 50 records, and the 20th record is chosen, i want records 20->50 to be selected.
Any help would be great. Thanx

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-27 : 10:42:52
[code]
select top 30 *
from (select top 50 * from sometable order by somecol)
order by somecol desc
[/code]


KH

Go to Top of Page

pintosack
Starting Member

4 Posts

Posted - 2007-02-27 : 12:27:03
thanks for reply...
perhaps i could use your code if i get the COUNT, and also the rownumber of the selected record?
would that be possible?

Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-03-01 : 02:25:28
quote:
Originally posted by pintosack

thanks for reply...
perhaps i could use your code if i get the COUNT, and also the rownumber of the selected record?
would that be possible?





in SQL Server its not possible to get the ROWNUMBER like Oracle supports. does ur table have any primary key, so that u can get ur sr no (rownumber).

let us know

Mahesh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-01 : 03:16:39
in SQL 2005, you can use ROW_NUMBER() function. see http://msdn2.microsoft.com/en-us/library/ms186734.aspx


KH

Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-03-01 : 03:43:25
quote:
Originally posted by khtan

in SQL 2005, you can use ROW_NUMBER() function. see http://msdn2.microsoft.com/en-us/library/ms186734.aspx


KH





thx khtan. i was not knowing this. can u tell some more links where i can get the comparision between SQL 2k and SQL 2005?

thanks in advance,

Mahesh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-01 : 03:49:29
just google for what's new in sql server 2005 you will get lot's of links


KH

Go to Top of Page
   

- Advertisement -