Hi All,I have a table like thisQid AnsId pagebreak1 1 01 2 02 3 12 5 13 9 14 12 04 13 05 16 05 17 06 20 1
I want to get the records based on the Qid I pass, and may be one more variable to determine forward or backward.Lets say if pass the Qid as 1,variable as forward then I want to get the records of 1 and 2.Qid AnsId pagebreak1 1 01 2 02 3 12 5 1
If I pass 2 and say forward I want only the record of 2, since 2nd has pagebreak = 1, so for 4 and forward it would be the records of 4,5 and 6. Basically if its forward then the records which start with passed parameter to the records where the first page break = 1(inclusive). For backward it the reverse process, for 6 and backward I want the record of 6,5,4.I guess I can use Cursors for this, but any other way without cursors?create table #test (Qid int,AnsId int,pagebreak tinyint)insert into #testselect 1,1,0unionselect 1,2,0unionselect 2,3,1union select 2,5,1union select 3,9,1union select 4,12,0unionselect 4,13,0union select 5,16,0unionselect 5,17,0unionselect 6,20,1
ThanksKarunakaran