Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    47

    Unanswered: Updating Data using Cursor

    I have to a table with 1175574 records.
    I am trying to update DocID, this is int data type. Now in this filed all value are 0, I have BegDoc is my unic

    The following scripts is taking long hours.
    Anybody can change my script to fast update?


    USE TestDb
    GO
    DECLARE @DocID INT,@BegDoc varchar(20),@Count INT
    SET @Count=1
    DECLARE CUR_DupID CURSOR FOR
    select DocID,BegDoc from Table_1 Where DocID=0 Order By BegDoc

    OPEN CUR_DupID
    FETCH NEXT FROM CUR_DupID
    INTO @DocID,@BegDoc
    WHILE @@FETCH_STATUS = 0
    BEGIN
    Update Table_1 SET DocID=@Count WHERE BegDoc=@BegDoc
    SET @Count=@Count+1

    FETCH NEXT FROM CUR_DupID
    INTO @DocID,@BegDoc
    END
    CLOSE CUR_DupID
    DEALLOCATE CUR_DupID

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What version of SQL Server?
    George
    Home | Blog

  3. #3
    Join Date
    Jan 2009
    Posts
    47
    SQL Server 2005 with SP2

  4. #4
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    I assume there is an index on Table_1.BegDoc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •