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
 find the row

Author  Topic 

MageshkumarM
Yak Posting Veteran

61 Posts

Posted - 2011-01-04 : 00:23:23
Hi,

I have one query to find the row,

for example i have 1000 Rows in a table,
i need to find row no. 425. using single line query.

can anyone help me out of this..



Regards,
MAG
SQL newer

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-01-04 : 00:46:14
[code]
select * from (select *, row_no = row_number() over (order by somecol) from yourtable ) d where d.row_no = 425[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-04 : 00:48:50
MAG, you can use the row number function in order to assign numbers to the result set. e.g.

create a procedure which returns the result set with row numbers and having a parameter e.g. exec abc 425

The parameter will be used in the where clause over the "row number" column ...

Cheers!
MIK
Go to Top of Page

MageshkumarM
Yak Posting Veteran

61 Posts

Posted - 2011-01-04 : 01:06:27
ya i found the row which is i looking and thk u guys..


Regards,
MAG
SQL newer
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-01-04 : 02:27:54
Rows have no intrinsic order. If you say you want row no 425, you need to also say which column you're ordering by to get that value. Tables are unordered sets of data and SQL does not keep a record of insert order.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-04 : 02:34:03
Also refer http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

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

- Advertisement -