lundi 13 juin 2016

How does the rand() operator work?

Quickly wanted to ask that does the RAND() operator distribute the values in equal numbers? e.g. If I have 100 rows in a table and a column named NumberOfItems and I want to assign the values 1-10 to them such that it is divided equally between the 100 records (10 records will have 1, 10 will have 2 ......)

The statement I have is:

select CAST(RAND(CHECKSUM(NEWID())) * 10 as INT)+1




Aucun commentaire:

Enregistrer un commentaire