Trying to generate unique serial numbers with alphanumerics (A-Z,a-z,0-9) and no special characters.Used below code where sLength was min 10 and max 12 as defined in front end.
declare @sLength tinyint
declare @randomString varchar(50)
declare @counter tinyint
declare @nextChar char(1)
declare @rnd as float
set @sLength = 3
set @counter = 1
set @randomString = ''
while @counter <= @sLength
-- crypt_gen_random produces a random number. We need a random
select @rnd = cast(cast(cast(crypt_gen_random(2) AS int) AS float) /
65535 as float)
select @nextChar = char(48 + convert(int, (122-48+1) * @rnd))
if ascii(@nextChar) not in (58,59,60,61,62,63,64,91,92,93,94,95,96)
select @randomString = @randomString + @nextChar
set @counter = @counter + 1
Now the requirement has changed where we will be sending set of characters(min 6) & numbers(min 2) selected in front end. So i will be sending the parameter as follows @Include = 'ABCDEFG12345' and @Exclude='HIJKLMNOPQRSTUVXYZ06789'. Can someone suggest how do i change the below code as per the requirement.
My idea is to change the if ascii(@nextChar) not in line and add all the Ascii codes of the @Exclude characters & numbers, but not able to write the code for the same.