Forums

ASP

This topic is locked

Please help!

Posted 25 Apr 2002 14:37:18
1
has voted
25 Apr 2002 14:37:18 No more Newsletters posted:
I'm trying to insert new records into a SQL DB where the unique ID scheme is four characters (ABCD) plus 8 digits. How can I modify the existing insert record behaviour to accommodate this?

Replies

Replied 26 Apr 2002 02:32:46
26 Apr 2002 02:32:46 Andrew Watson replied:
Hello Eric,

If you are generating the unique key on the page then you could try this method, there's probably others.

(<img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle> Im not sure if its possible, but can SQL Server not generate the unique ids for you?)

Anyway heres a few line that will generate a random 4Letter8Digit string that you could use and then check against the current records to see if its unique. (there has to be a better way....<img src=../images/dmxzone/forum/icon_smile_dissapprove.gif border=0 align=middle>

<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT"%&gt;


&lt;%

dim max1,min1 ,varRandomLetters
max1=90
min1=65
varRandomLetters = ""
While Len(varRandomLetters) &lt; 4
Randomize
intRand = (Int((max1-min1+1)*Rnd+min1))
varRandomLetters = varRandomLetters & Chr(intRand)
Wend

dim max,min ,varRandomDigits
max=99999999
min=00000000
varRandomDigits = 0000000
While Len(varRandomDigits) &lt; 8
Randomize
varRandomDigits = (Int((max-min+1)*Rnd+min))
Wend

varUniqueReference = varRandomLetters & varRandomDigits

%&gt;

&lt;%= varUniqueReference %&gt;

</font id=code></pre id=code>

Cheers, Leed

:: Son, im Thirty.... ::

Edited by - leed on 26 Apr 2002 02:40:51

Edited by - leed on 26 Apr 2002 02:46:43

Edited by - leed on 26 Apr 2002 02:48:20

Reply to this topic