I need to loop through rows which has id and when looping i need to check current and previous values.
I have a cursor to fetch them :
DECLARE idCur CURSOR FOR SELECT MessageId FROM EMMessages;
So now i need to loop through these values and compare them when looping: For example i have ids = [1, 2, 3, 4] I want to compare 1 and 2 then 2 and 3 and so on.. How in sql i should declare this n and n-1 variable or should i decalare n and n+1.