Wednesday, October 30, 2013

Generate Random Alpha Numeric Number with

When we require to generate unique id without using NEWID() function of sql, here is the good alternative to generate unique alpha nemuric identifier to use at primary key.

DECLARE @alpha_numeric VARCHAR(16)
SET @alpha_numeric=''

SELECT @alpha_numeric=@alpha_numeric+CHAR(n) FROM
( SELECT TOP 16 number AS n FROM master..spt_values WHERE TYPE='p' and (number between 48 and 57 or number between 65 and 90) ORDER BY NEWID()) AS t

SELECT @alpha_numeric


Hope this will be helpful to generating manual alpha numeric identifier.

Happy Coding!!