locked
Cursor in Access table RRS feed

  • Question

  • User1015862149 posted

    I need to manipulate the row in field by using cursor.(supose 250 record means i need to change the particular field in each row)

    Saturday, August 10, 2013 6:19 AM

Answers

  • User697462465 posted

    Hi raj1947,

    According to your description, my understanding is that you would like to use cursor to update each record data, if so please to refer to the following code:

    declare c_cursor cursor--declare your cursor
    
    for select id from Student
    
    declare @id int
    
    open c_cursor
    
    fetch next from c_curosr into @id --fetch your first record value
    
    while(@@FETCH_STATUS=0)
    
    begin
    
    update Student
    
    set name = 'hi'
    
    where id=@id
    
    fetch next from c_curosr into @id
    
    end
    
    close c_cursor--close your cursor
    
    deallocate c_cursor--deallocate your cursor
    

    If you have any question please let me know.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 12, 2013 6:03 AM