Generate Random Number using Sql sever

DECLARE @rand INT;
DECLARE @Upper INT;
DECLARE @Lower INT;
---- This will create a random number between 1 and 50
SET @Lower = 1 ---- The lowest random number
SET @Upper = 50 ---- The highest random number
SELECT @rand = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
print @rand
declare @Value int;
set @Value = CAST(RAND() * 10000 AS INT) 
print  'WC '+ cast(@Value AS varchar)


declare @alphabet varchar(36) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
select 
substring(@alphabet, convert(int, rand()*36), 1) + 
substring(@alphabet, convert(int, rand()*36), 1) +
substring(@alphabet, convert(int, rand()*36), 1) +
substring(@alphabet, convert(int, rand()*36), 1) +
substring(@alphabet, convert(int, rand()*36), 1);
DECLARE @r varchar(8)
SELECT @r = coalesce(@r, '') +CHAR(
CASE WHEN r between 0 and 9 THEN 48
WHEN r between 10 and 35 THEN 55
ELSE 61 END + r)
FROM
master..spt_values
CROSS JOIN
(SELECT CAST(RAND(ABS(CHECKSUM(NEWID()))) *61 as int) r) a
WHERE type = 'P' AND number < 8
print @r
Ebook Download
View all
DevOps
Read by 0 people
Download Now!
Learn
View all