I've added two new columns on one of my database's table. They are called Exam and assignment results.
At the moment the two columns are both empty. I want them filled with random examination results but no greater than 100. How to I generate random number for both columns from 0 to 100?
Thanks.
You can do this using rand(),
checksum(), and
newid()`:
update t
set exam = rand(checksum(newid())) * 101,
assignment = rand(checksum(newid())) * 101;
In SQL Server, rand()
is (essentially) called once for a query. To get around this, you can give it a new seed. You could also use other columns in each row as the seed value, if you wanted reproducible results.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments