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
 How to get the nth row.

Author  Topic 

Vijaykumar_Patil
Posting Yak Master

121 Posts

Posted - 2007-09-13 : 09:31:03
Hi is there a way to get the nth row in a select query?

Necessity is the mother of all inventions!

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-13 : 09:47:20
create table #tempxyz (rowid int identity(1,1),col1 int, col2 char)

insert into #tempxyz(col1,col2)
select col1,col2 from
tablexyz
order by col1 asc, col2 desc

select col1,col2 from #tempxyz where rowid = nthrow

drop table #tempxyz

PS: If anyone is interested in a SQL Server job in Connecticut with excellent pay please send me a resume to ValterBorges@msn.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-13 : 09:52:01
It depends on how you define nth row

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-13 : 09:52:32
Or, if using SQL Server 2005, make use of the new ROW_NUMBER() function.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-13 : 10:11:54
quote:
Originally posted by Vijaykumar_Patil

Hi is there a way to get the nth row in a select query?

Necessity is the mother of all inventions!



Tell us why you need to do this


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -