What is the Sql update command for a range values(numbers) in a row

  • What is the Sql update command for a range values(numbers) in a row . I want to update each row with different unique value?

    I want a an sql update command that will update a range of row say 1-10 and replace with 11-20. What command can I use instead of having to manually replace this values please

    Additional Details

    The table name is scoretable and the row i want to replace the values in it is called score_id

    the values in the score_id range from 28324 to 32768,

    I want the new range to be 1 to 4444

    I will appreciate if I can get the actual command so I will just apply it.

  • From what you've said:

    Update scoretable

    set score_id = score_id- 28323

    where score_id between 28324 and 32768

    will do what you need...

    I will appreciate if I can get the actual command so I will just apply it.

    dont do anything you dont fully understand



    Clear Sky SQL
    My Blog[/url]

  • Thanks for your reply. But I would like to know , in ur response there is now reference to the value that I want to be updated in the row. I mean the range of value from 1 to 4444. Could you be more elaborate please?

  • Its just simple maths!

    If you have the id's 1 thru 10 and you want to update them to 11 thru 20 you just add 10 to the id , yes?

    If you have the id's 28324 thru 32768 and want to update them to 1 to 4444 then subtract 28323.



    Clear Sky SQL
    My Blog[/url]

  • Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    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
  • If the column is defined as an identity, there are other steps you'll have to take, since you won't be able to just update it. Is it?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • And if that column is referenced by other tables, you'll have to update those as well.....

    -- You can't be late until you show up.

  • Thanks, I have applied it and it worked Just perfect.

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

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