Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
5 Character Generaton Routine
Message
From
26/08/2003 11:29:36
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00823200
Message ID:
00823463
Views:
29
Thanks. I tried your code and it works to produce the 5 character value. One requirement I needed was for the numbers to appear random. So I randomly interchanged the characters in the @Base36 value. I also changed the first line in the loop to subtract @i from 36. Then I commented out the set @key line.

Although I modified the code you gave me, you get the credit dude. I was lost on where to start. Thanks again.

YOUR CODE>>
DECLARE @i int, @key int, @Base36 char(36), @Key5 varchar(5)
SET @key = 1234578910
SET @Base36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SET @Key5 = ''
SET @i = 1
WHILE @i < 6
BEGIN
SET @Key5 = SUBSTRING(@Base36, (@key % 36)+1,1) + @Key5
SET @key = CAST(@key / 36 AS int)
SET @i = @i + 1
END
SELECT @Key5

MY CODE>>
/* @identity_int passed in as a parameter */
DECLARE @i int, @key int, @Base36 char(36), @Key5 varchar(5),@ItsNew bit
SET @ItsNew = 0
WHILE @itsNew = 0
BEGIN

SET @key = @identity_int + 10000
/*
SET @Base36 = '0123456789ABCDEFGHIJKLMNOPQ9STUVWXYZ'
Randomize the order to generate numbers that look random.
*/

SET @Base36 = 'ZW2R4PGTK6XHFNOC9BIJML8DE5Q3S7UV1A0'
SET @Key5 = ''
SET @i = 1
WHILE @i < 6
BEGIN
SET @Key5 = SUBSTRING(@Base36, (@key % (36 - @i)+1),1) + @Key5
-- SET @key = CAST(@key / 36 AS int)
SET @i = @i + 1
END
/* Just in case the new value is not 'New' check it. If its new set the Its new bit and exit the procedure. New code checking removed*/

END
SELECT @Key5
Terry Rooks
Software Systems Architect
Microsoft Certified Solution Developer.Net

If at first you don't succeed, then skydiving definitely isn't for you.
Previous
Reply
Map
View

Click here to load this message in the networking platform