Forums

This topic is locked

column with random

Posted 11 Dec 2002 18:55:52
1
has voted
11 Dec 2002 18:55:52 Matthijs Horsman posted:
Hello All,

I am looking for a way to create a random number or string of letters and numbers, when i import a bunch of data in my Table.

Is there anyway you can use a default value so i can create something like that??

thnx in advance

Matthijs
----------------
DWMX/W-XP-PRO/IIS/ASP-VB/MS-SQL

Replies

Replied 12 Dec 2002 16:57:22
12 Dec 2002 16:57:22 Brent Colflesh replied:
Dear Matthijs,
From:
www.planet-source-code.com/xq/ASP/txtCodeId.352/lngWId.5/qx/vb/scripts/ShowCode.htm



SET nocount ON
DECLARE @i int
DECLARE @Length int
DECLARE @NumberOfChars int

/* Change the next two lines to vary the length */
DECLARE @Output varchar(10)

SET @NumberOfChars = 10
SET @Length = 0
SET @Output = ''

WHILE (@Length < @NumberOfChars)
BEGIN

SET @i = cast(rand(convert(int, convert(varbinary, newid()))) * 100 as int)

IF (

(@i >= 48 AND @i <= 57)

OR

(@i >= 65 AND @i <= 90))

BEGIN

set @Output = @Output + char(@i)

set @Length = @Length + 1

END
END


PRINT @Output


Regards,
Brent

Replied 12 Dec 2002 16:59:47
12 Dec 2002 16:59:47 Matthijs Horsman replied:
wow cool thanx!!

Matthijs
----------------
DWMX/W-XP-PRO/IIS/ASP-VB/MS-SQL

Reply to this topic