I need to update random numbers for top 100 rows (a field) in sql. random number should be less than 100. how to do that?
In SQL 2008
update top (100) MyTable
set MyField = cast(cast(crypt_gen_random(1) as int) * 100.0 / 256 as int)
I believe the same will work in SQL 2005.
[Edit]
If it doesn't work in SQL 2005, you can do this:
update top (100) MyTable
set MyField = abs(cast(newid() as binary(6)) % 100)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With