A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Random Number Per Queried Row SQL Server 2005

 
 
 

--Random Row Number Generation in SQL Server.

declare @mod_bounds int

set @mod_bounds = 1000

select abs(cast(CAST(NEWID() AS varbinary) as int))%@mod_bounds

--This will give us a random number between 0 and 999

 --If this casting is done on a select statement, the result will change per row.