>open a_item >fetch next from a_item into @giveid,@item,@freqindays > >--run through the cursor >while @@fetch_status = 0 >begin > >--preform function >if ((select max(invdte) from pkpro..artran where item = @item and custno = @custno) > dateadd(day,-@freqindays,getdate())) > begin > delete from a_item where current of a_item > end >else > begin > select @giveid,@item > end > >--fetch the next record >fetch next from a_item into @giveid,@item,@freqindays > >--end and close the cursor >end