Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Insert random values Expand / Collapse
Author
Message
Posted Monday, June 28, 2010 1:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, November 20, 2011 9:44 PM
Points: 8, Visits: 10
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,
Post #943714
Posted Monday, June 28, 2010 1:57 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 1:33 AM
Points: 1,949, Visits: 8,310
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.





Clear Sky SQL
My Blog
Kent user group
Post #943715
Posted Monday, June 28, 2010 7:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, November 20, 2011 9:44 PM
Points: 8, Visits: 10
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
Post #943888
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse