Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want sql query

my table name is empdata
id   name
1     raj
2     sam
3     jhon
4     x
5     y
6     z
7     p
8     a

in this table when i am giving id =5 . i want data from giving id with before 2 fields and after 2 fields. i.e bellow format.
id   name
3    jhon
4    x
5    y
6    z
7    p  

help me.
Posted
Updated 16-Apr-13 19:36pm
v2

Try below sql

SQL
Declare @id int;
set @id =5;
Select ID,name from My_Table where id between @id -2 and @id+2
 
Share this answer
 
v2
Hello,




SQL
select ID,Name from empdata where ID >= @ID-2 and ID <= @ID + 2



@id is given Parameter

Thanks,
Abhimanyu
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900