본문 바로가기

DB

MS-SQL Random


Declare @I Int
Set @I = 0
While(@I < 100)
Begin
 Print '[' + Cast(@I As VarChar) + ',' + Char(@I) + ']'
 Set @I = @I + 1
End


DECLARE @PassWord VarChar(5), @i Int
Set @PassWord = ''
Set @i = 0

NewCreate:
While(@i < 5)
  Begin
 Set @PassWord = @PassWord + SUBSTRING('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',Convert( Int, (Rand() * 36) + 1 ) ,1);
 Set @i = @i + 1
  End

--################################################
If Not Exists(Select 1 From dbo.NEISCode Where UnivId = 1101 And NEISCode = 'B100000540' And AccessPwd = @PassWord)
 Goto EndCreate
Else
 Goto NewCreate
--################################################

EndCreate:
Print @PassWord