Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to choose a random number from a particular range in SQL Server is to use the RAND() function in combination with the desired minimum and maximum values. Here is an example SQL query:

SELECT CAST(RAND() * (@maxValue - @minValue) + @minValue AS INT) AS RandomNumber

In this query, @maxValue and @minValue are input parameters representing the maximum and minimum values of the desired range. The RAND() function generates a random float value between 0 and 1, which is then multiplied by the range and added to the minimum value. The CAST function is used to convert the result to an integer. This query will return a random integer within the specified range.