Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert random values

Author  Topic 

Malik
Starting Member

3 Posts

Posted - 2010-06-28 : 03:43:34
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,
Malik

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-28 : 04:35:07
Homework?

UPDATE TOP(100) YourTableNameHere
SET YourColumnNameHere = ABS(CHECKSUM(NEWID())) % 2



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

mohd.taheri
Starting Member

5 Posts

Posted - 2010-06-28 : 04:41:11
select top 100 * from table_1 where Field1=0 order by NEWID()

the above line select 100 random row with where cluase Field1=0

try the rest !!

Nothing Is Impossible
Go to Top of Page
   

- Advertisement -