//Generate Random Number Between Two Values in SQL Server
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
-- This will create a random number between 1000 and 2000
SET @Lower = 1000 -- The lowest random number
SET @Upper = 2000 -- The highest random number
SELECT @Random =
ROUND(((@Upper - @Lower -1)
*
RAND()
+ @Lower), 0)
SELECT
Round(@Random,-2)
========================================================================
O/P:=1900
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
-- This will create a random number between 1000 and 2000
SET @Lower = 1000 -- The lowest random number
SET @Upper = 2000 -- The highest random number
SELECT @Random =
ROUND(((@Upper - @Lower -1)
*
RAND()
+ @Lower), 0)
SELECT
Round(@Random,-2)
========================================================================
O/P:=1900
No comments:
Post a Comment