Global Developer's Technologies

Global Developer's  Technologies Global Developer's Technologies

20/03/2015

GENERATE 8 CHAR RANDOM NUMBER
IN SQL SERVER
Help for Password Generation
------------------------------------------
Method - 1
------------------------------------------
DECLARE varchar(8)
SELECT = coalesce(, '') + n
FROM (SELECT top 8
CHAR(number) n FROM
master..spt_values
WHERE type = 'P' AND
(number between ascii(0) and ascii(9)
or number between ascii('A') and ascii('Z')
or number between ascii('a') and ascii('z'))
ORDER BY newid()) a;
SELECT ;
------------------------------------------
Method - 2
------------------------------------------
DECLARE varchar(8)
SELECT = coalesce(, '') +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
SELECT ;

Address

Noida
201301

Website

Alerts

Be the first to know and let us send you an email when Global Developer's Technologies posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Share

Category