I am using the below in my stored procedure to create a 8 digit password and return it as output.
select @AuthKey = @AuthKey + char(n) from
(
select top 8 number as n from master.. spt_values
where type= 'p' and number between 48 and 57
order by newid()
) as t
But i want the output as alpha numeric value, instead of just numeric value. How can i get it ?
Anuya — this is a very clever way to randomize values, using
order by newid(). You can also use lowercase characters, if your passwords are case sensitive:Using a slightly different approach, you could include a specific character set, including symbols:
Of course this only includes any given character one time. Still it is a very clever way of generating passwords. Kudos!
Edit:
If you want to have the chance of having doubles, you can do it like this :
(will be slightly faster too as the query doesn’t require sorting spt_values.