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
 select prevous and next record of rows in sql sel

Author  Topic 

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2009-04-06 : 08:51:13
dear all

in table there are 15 record.
i have select a first 5 and last 5 record to maching a perticular row text in table.


thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-06 : 09:13:12
Some sample data would be great.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-06 : 09:22:36
Search for Pagination


Madhivanan

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

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2009-04-06 : 23:30:20
Sr No data
1 ffdf
2 dfsd
3 df
4 fsdf
5 dfsdf
6 dfsdf
7 ddsf
8 test
9 fdsfd
10 sdfsdf
11 sdfdsf
12 dfsdf
13 dfsdf
14 dfsd
15 sdfsdf

i have select top 5 records and bellow 5 records to matching "test" row
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-07 : 01:33:30

Try


select top 5 * from table where [Sr No]<
(
select [Sr No] from table where data='test'
)
order by [Sr No] desc

select top 5 * from table where [Sr No]>
(
select [Sr No] from table where data='test'
)
order by [Sr No]



Madhivanan

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

- Advertisement -