June 28, 2010 at 1:52 am
Dear Friends,
I am wondering if you could give me a hand in this situation.
I am a new user for sql and i am currently work in task that requires me to update random values to my table. I have 1000 rows consist of 0 and 1 values and i would like to randomly change 100 cells that contain 0 values to 1. I would like to know which sql statement can help me to perform this.
Thank you for your assistant in advance.
Regards,
June 28, 2010 at 1:57 am
Hi ,
The consensus of opinion is that newid() provides a pretty good randomness factor.
So if you select top(100) * from <yourtable> order by newid() , you will get 100 random rows.
If the table has a PK , which i should , you can directly update from that list or wrap that in a CTE and update using that.
June 28, 2010 at 7:25 am
Hi Dave Ballantyne
Thank you for your answer but i would like know that CTE can be used to update random columns. because when i execute the following statement, i get 100 rows in random. Can i use CTE to update 100 fields in different columns. For example column, i update 10 fields and in column two i update 25 and so on till 100 fields have been changed.
select top 100 from
Table_A
order by newid ()
Thanks a lot
Viewing 3 posts - 1 through 3 (of 3 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