I am trying to generate unique random number between 1000 and 1000,000,000,000 (trillion) to insert into a unique field in the SQL database . How do I achieve this?
code in VBScript or a stored procedure will do.
My current code in the stored proc is as follows:
Declare @Random bigint;
DECLARE @Upper bigint;
DECLARE @Lower bigint
-- This will create a random number between 1 and 1000,000,000
SET @Lower = 1 -- The lowest random number
SET @Upper = 1000000000 -- The highest random number
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)
select RandomNumber = @Random
could someone please help me with the code ? Do I have to check each generated random number before inserting into the table to see if it already exists in the table?
Thanks.
code in VBScript or a stored procedure will do.
My current code in the stored proc is as follows:
Declare @Random bigint;
DECLARE @Upper bigint;
DECLARE @Lower bigint
-- This will create a random number between 1 and 1000,000,000
SET @Lower = 1 -- The lowest random number
SET @Upper = 1000000000 -- The highest random number
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)
select RandomNumber = @Random
could someone please help me with the code ? Do I have to check each generated random number before inserting into the table to see if it already exists in the table?
Thanks.