Of course this is a problem in procedural programing, not batch programing. Thus, this is the kind of code that makes DBAs (like me) tense up and make ugly faces. With that being said, assuming that you have a unique index, I believe you want something like this:
declare @id int
declare @newvalue int
declare @oldvalue int
select @id = min([UNIQUE INDEX])
from
while @id is not null
Begin
select @newvalue = [COLUMN]
from
where [UNIQUE INDEX] = @id
if @newvalue = @oldvalue
Begin
--Your Code Here
End
select @oldvalue = @newvalue
select @id = min([UNIQUE INDEX])
from
where [UNIQUE INDEX] > @id
End