In this article we’ll learn the procedure that selects random number between the two numbers entered as parameters.
1 2 3 4 5 6 7 8 |
Create Procedure Sp_Random_Value @first int, @second int, @result int output As Begin Set @result =Floor(RAND() * (@second-@first))+@first End |
After getting succesful message we can run the below code to get random values. You can enter deferent values.
1 2 3 |
Declare @r int Execute Sp_Random_Value 20,30,@r output Select @r |
Each time you run the code, you will receive different values between 20 and 30.
I got the result : 23