Updating a table starting with the first empty column in a specific row

  • Hi,

    I'm struggling to find a solution to this (very likely simple) problem:

    I want to populate some rows in a table where the column RequestID is empty. I want the update query to start from the first row were RequestID is empty and continue downwards (RequestID will be incremented by '1'). Tried to use cursor but wasn't successful (the column RequestID gets populated with '1' all the way down!). Any help would be much appreciated:

    Declare @i integer

    set @i=0

    declare CustList cursor for

    SELECT * from FALSEDESCRIPTION WHERE RequestID =''

    OPEN CustList

    FETCH NEXT FROM CustList

    While (@@FETCH_STATUS = 0)

    Begin

    set @i=@i+1

    UPDATE FALSEDESCRIPTION SET RequestID=@i

    FETCH NEXT FROM CustList

    End

    Close CustList

    Deallocate CustList

  • Duplicate post. No replies to this thread please. Direct replies to:http://www.sqlservercentral.com/Forums/Topic963971-1292-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply