SQL random number column

Here's a quickie. If you need to have a new random number on a column, this works really well.

rand(cast(cast(NEWID() as varbinary) as int)) number

Of course NEWID generates a random guid. Casting it as a varbinary first, then as an int gives you a random number which can then be used as a seed for the random number generator.

Comments

Popular posts from this blog

MSSQL Statistical Z-Score

IBM x335 and Windows 2008 installation

Database Projects, SQL Unit Tests, and TeamCity