ALTER proc [dbo].[addUser] ( @mid int output,@phone nvarchar(20),@regmid int,@pwd nvarchar(30),@relname nvarchar(50), @email nvarchar(200),@tel nvarchar(20),@sex nvarchar(2),@photo nvarchar(300),@IDNum nvarchar(20), @integral decimal(18,2),@flag char(1),@linkkey nvarchar(50),@qq nvarchar(30),@msn nvarchar(50), @disc nvarchar(500),@state char(1),@createDate datetime,@moreCol nvarchar(200),@moreCol1 nvarchar(200), @moreCol2 nvarchar(200) ) as begin declare @num int,@code varchar(15) set @code=convert(nvarchar(20),getdate(),112)+dbo.getCode(7) select @num=count(1) from AdminUser where [name]=@code while(@num<>0) begin set @code=convert(nvarchar(20),getdate(),112)+dbo.getCode(7) select @num=count(1) from AdminUser where [name]=@code end set @linkkey=@code insert into [hr_member]([phone],[regmid],[pwd],[relname],[email],[tel],[sex],[photo],[IDNum],[integral], [flag],[linkkey],[qq],[msn],[disc],[state],[createDate],[moreCol],[moreCol1],[moreCol2])values(@phone, @regmid,@pwd,@relname,@email,@tel,@sex,@photo,@IDNum,@integral,@flag,@linkkey,@qq,@msn,@disc,@state, @createDate,@moreCol,@moreCol1,@moreCol2) SET @mid = @@IDENTITY end ---------------------------------------------------- create view v_random as select rand() as random ----------------------------------------------- ALTER FUNCTION [dbo].[split](@str nvarchar(4000),@code varchar(10),@no int) RETURNS varchar(200) AS BEGIN declare @intLen int declare @count int declare @indexb int declare @indexe int set @intLen=len(@code) set @count=0 set @indexb=1 if @no=0 if charindex(@code,@str,@indexb)<>0 return left(@str,charindex(@code,@str,@indexb)-1) else return @str while charindex(@code,@str,@indexb)<>0 begin set @count=@count+1 if @count=@no break set @indexb=@intLen+charindex(@code,@str,@indexb) end if @count=@no begin set @indexe=@intLen+charindex(@code,@str,@indexb) if charindex(@code,@str,@indexe)<>0 return substring(@str,charindex(@code,@str,@indexb)+len(@code),charindex(@code,@str,@indexe)-charindex(@code,@str,@indexb)-len(@code)) else return right(@str,len(@str)-charindex(@code,@str,@indexb)-len(@code)+1) end return '' END ------------------------------------------------------------------------ alter function getCode(@chang int) returns varchar(50) as begin declare @sz nvarchar(69),@code varchar(50),@i int set @sz='0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|j|h|i|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z' set @i=0 set @code='' while(@i<=@chang) begin declare @random float select @random=random from v_random set @code=@code+dbo.split(@sz,'|',ceiling(@random*35)) set @i=@i+1 end return @code end