Re: cursor in SPL
Posted in 2000
From: Benjamin Partlow <benpartlow@yahoo.com> > >Hello everyone, I am new to the list and this is my >first post. > >I would like to write a stored procedure that loops >through a cursor and compares each consecutive value >with the next value in the cursor. Something like >this: > >define p_doc_id, p_doc_id_2 integer; > >foreach select document_id > into p_doc_id > from tablename > order by document_id > > fetch next into p_doc_id_2 > > if (p_doc_id + 1) <> p_doc_id_2 then do > something > >end foreach; > > >What I am not sure about is how to move the cursor in >SPL to the next record. Thank you, That's what FOREACH does, it loops through the cursor. Is suspect your problem is possibly that you want to compare "forward". What you should be doing is comparing "back": let cnt = 1 foreach select document_id into p_doc_id from tablename order by document_id if cnt > 1 then if (p_doc_id - 1) <> p_old_id then do something end if end if let p_old_id = p_doc_id end foreach; ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com