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

1080200032060120121019130214 this is one id like in my table having 13 ids. just for understanding i am giving like this

108020003 20601 20121019130214
108020003 20602 20121019130734
108020003 20603 20121019131157
108020003 20604 20121019131714
108020003 20605 20121019132137
108020003 20606 20121019141036
108020003 20607 20121019141451
108020003 20608 20121019141957
108020003 20609 20121019142735
108020003 20610 20121019144434
108020003 20611 20121019145003
108020003 20612 20121019145450
108020003 20613 20121019150619

id datatype is nvarchar

i am giving like this format. based on 20601 to 20613 read data.

i am giving id as 10802000320607 , i want data giving id with before two fields and after two fields

1080200032060520121019132137
1080200032060620121019141036
1080200032060720121019141451
1080200032060820121019141957
1080200032060920121019142735



plz help me.
Posted
Updated 17-Apr-13 1:39am
v2
Comments
Member 2707515 17-Apr-13 6:46am    
not understand dude explain more
Shanalal Kasim 17-Apr-13 7:24am    
Your giving id format is fixed ?.
Thant means your giving first 14 number(from left) am i right?

1 solution

Are you saying:
You have a single column on the table of type nvarchar
It is 28 characters long
You are given the first 14 characters
You need to return the row starting with those two characters, and the two rows before and two rows after, sorted by that column?

If so

something like

SQL
Select top 3 from table
where id > @givenId
order by id

union

select top 2 from table
where id < @givenid
order by id desc


Sorry I don't have sql server in front of me to check it out but it looks right to me!
 
Share this answer
 
v2
Comments
subbu a 18-Apr-13 0:35am    
it Displays some error .


help me.
_Maxxx_ 18-Apr-13 1:49am    
Are you serious? At leas tell someone what the freaking error is!!!!!!

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