RE: Random String Generator (ultra lazy)

RE: Random String Generator (ultra lazy)

 

  

Here's something that I have used in the past. You have to send it the
length (which in your case is 7), and you also have to change the list
of @ValidCharacters to your list...

CREATE PROCEDURE sp_GeneratePassword
(
@Length int
)

AS

DECLARE @RandomID varchar(32)
DECLARE @counter smallint
DECLARE @RandomNumber float
DECLARE @RandomNumberInt tinyint
DECLARE @CurrentCharacter varchar(1)
DECLARE @ValidCharacters varchar(255)
SET @ValidCharacters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+&$'
DECLARE @ValidCharactersLength int
SET @ValidCharactersLength = len(@ValidCharacters)
SET @CurrentCharacter = ''
SET @RandomNumber = 0
SET @RandomNumberInt = 0
SET @RandomID = ''

SET NOCOUNT ON

SET @counter = 1

WHILE @counter < (@Length + 1)

BEGIN

SET @RandomNumber = Rand()
SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength
- 1) * @RandomNumber + 1))

SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters,
@RandomNumberInt, 1)

SET @counter = @counter + 1

SET @RandomID = @RandomID + @CurrentCharacter

END

SELECT @RandomID AS 'Password'
GO




Adam Blumenfeld

-----Original Message-----
From: Courday Farnam
[mailto:mssqldba-ezmlmshield-x22327214.[Email address protected]
Sent: Friday, June 29, 2007 11:12 AM
To: LazyDBA Discussion
Subject: Random String Generator (ultra lazy)

Can someone supply me with the syntax that will generate a seven (7)
character string that includes only the following characters?



0, #, *, @, X, P, F, 1-9



Thanks,



Courday





---------------------------------------------------------------------
TO REPLY TO EVERYBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To post a dba job: http://jobs.lazydba.com
To subscribe : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html

#####################################################################################
Warning:

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the named addressee any review, dissemination, distribution or duplication of this e-mail is strictly prohibited. If you have received this email in error, please let us know by e-mail and delete it from your system. Please note that any personal views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.

Thank You.
#####################################################################################

MS Sql Server LazyDBA home page