存储过程生产随机码
/*
Usage:
Declare @password varchar(100);
EXEC sp_function_generate_randomcode 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789', 7,
@password output;
PRINT @password
*/
CREATE PROCEDURE [dbo].[sp_function_generate_randomcode]
@seed varchar(100),
@length int,
@rtnCode varchar(100) output
AS
BEGIN
DECLARE @randCode INT;
SET @rtnCode = ''
WHILE(@length>0)
BEGIN
SET @randCode = rand() * len( @seed )+1
SET @rtnCode = @rtnCode + substring(@seed, @randCode,1)
SET @length = @length -1
END
END