Replace

  • I'm sure this is an easy one, but my brain isn't working today.

    I have a table with a field that is filled with Nulls. How would I update the table so that the field is filled with sequential integers (1,2,3...)?

  • Here is one easy way. alter the table adding a identity column update the original column setting it to the new identity column then drop the new identity column.

  • try this:

    create table t(x int,d int)

    insert into t(x) values(1)

    insert into t(x) values(2)

    insert into t(x) values(3)

    insert into t(x) values(4)

    select * from t

    declare @x int

    set @x = 0

    update t

    set d=@x,@x=@x+1

    select * from t

    drop table t

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Can one make an assumption about the sequence

    the statement d=@x,@x=@x+1 will be performed?

    Always d=@d and then @x=@x+1?

Viewing 4 posts - 1 through 3 (of 3 total)

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