July 20, 2009 at 2:58 am
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.
July 20, 2009 at 3:33 am
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
July 20, 2009 at 3:46 am
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?
July 20, 2009 at 4:04 am
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.
July 20, 2009 at 4:41 am
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
July 20, 2009 at 6:43 am
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
July 20, 2009 at 7:06 am
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.
July 20, 2009 at 2:16 pm
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy