Loop - SP Help?

Hi all,
I am trying to succeed:
1)Loop through this samle output (that could be lots of records)
2)If same personnelnumber and current row’s oldValue is 1 and previous row’s value is 0
3)Take current and previous operationDate and select some records from another tbl between those operationDates. Each iteration will append the result of select statement and populate the final output.


PersonnelNumber	OldValue	operationDate
89722	1	2012-04-19 21:00:24.150
89722	0	2012-04-17 15:09:33.720
89722	1	2012-04-17 14:46:06.410
89722	0	2012-04-17 12:03:54.313
89783	1	2012-05-06 21:00:33.917
89783	0	2012-05-04 12:14:32.077
89778	1	2012-05-06 21:00:33.913
89778	0	2012-05-04 12:14:32.087

Sounds more like a coding question to me, so I’ve moved the thread (to the PHP forum assuming that’s what you’re using).
Could you post the code you’ve got so far?