updating a column

  • create table #test_table(sno int identity(1,1),line_no int null,product_name varchar(20))

    insert into #test_table(product_name) values('TV')

    insert into #test_table(product_name) values('Mobile')

    insert into #test_table(product_name) values('Webcam')

    insert into #test_table(product_name) values('Keyboard')

    Now i need line_no column incremented by 1 starting from 1.... using update command in ascending order of sno column.....

    any help pls?

  • The Row_Number function will do what you want. First write a select that returns the data you what, then use that in the from clause of the update.

    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
  • thanks a lot gail....

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

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