https://docs.microsoft.com/en-us/sql/t-sql/functions/rand-transact-sql?view=sql-server-2017
Generate random numbers within a certain interval
Https://stackoverflow.com/questions/7878287/generate-random-int-value-from-3-to-6
Principle, the RAND function generates a random float number between 0 and 1.
With this random number * interval range + minimum, a random number within an interval range is obtained. Then use the round function to remove the digits after the decimal point.
DECLARE @Random INT;DECLARE @Upper INT;DECLARE @Lower INTSET @Lower = 3 ----the lowest random numberSET @Upper = 7 ----one more than the highest random numberSELECT @Random = ROUND(((@Upper - @Lower -1)* RAND()+ @Lower),0)SELECT @Random
Generating a Boolean value
https://stackoverflow.com/questions/20597269/how-to-generate-random-boolean-value-in-sql-server-2008
If you is only generating one row, you could use something as simple as:
SELECT CAST (ROUND(RAND(),0asBIT)
However, if you is generating more than one row, would evaluate to the RAND()
same value for every row, so please see Marti n Smith ' s answer.
SQL Server generates a random number rand function