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

Database Projects, SQL Unit Tests, and TeamCity

Building nice XML from SQL Server Tables

Not everyone needs to be a software developer...