Guest User

Untitled

a guest
Jun 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. CREATE procedure dbo.AllAccessIDgenerator (
  
  2. @showID varchar(40)
  3. @accessID varchar(100) OUT
 )

  4.  
  5. As

  6.  
  7. Begin
  8. declare @codeLength int
  9. declare @characters varchar(100)

  10. declare @count int
  11. set @characters = ''
  12. set @codeLength = 8
  13.  
  14. -- set A - Z (uppercase)
  
  15. set @count = 65
  
  16. while @count <=90
  
  17. begin
     
  18. set @characters = @characters + Cast(CHAR(@count) as char(1))
     
  19. set @count = @count + 1
  
  20. end
  21. end
  22.  
  23. -- set 0-9
  24. set @count = 48
  25. while @count <=57
  26. begin
  27. set @characters = @characters + Cast(CHAR(@count) as char(1))
  28. set @count = @count + 1
  29. end
  30. end
  31.  
  32. set @count = 0
  33. set @accessID = ''
  34.  
  35. while @count <= @codeLength
  
  36. begin
     
  37. set @accessID = @accessID + SUBSTRING(@characters,CAST(ABS(CHECKSUM(NEWID()))*RAND(@count) as int)%LEN(@characters)+1,1)
     
  38. set @count = @count + 1
  
  39. end

  40. end
  41.  
  42. end

  43. GO
Add Comment
Please, Sign In to add comment