Pages

Saturday, October 4, 2008

RAND() Function

SQL Server has a built-in function that generates a random number, the RAND() mathematical function. The RAND math function returns a random float value from 0 through 1. It can take an optional seed parameter, which is an integer expression (tinyint, smallint or int) that gives the seed or start value.

To use it, you can simply do a simple SELECT, as follows:

SELECT RAND() AS Rand_Num

The result generated by this SELECT statement is as follows (note that your results may be different from the value shown here, hence the name random)

RandomNumber
---------------------
0.34344339282376501

No comments: