zoukankan      html  css  js  c++  java
  • sql生成不重复的邀请码

    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
  • 相关阅读:
    Android使用百度地图定位并显示手机位置后使用前置摄像头“偷拍”
    JS传递参数时对中文进行编码和解码
    点击<a>标签,禁止页面自动跳到顶部的解决办法
    百度地图API用法(传地址)
    asp.net页面按Enter键IE不提交表单
    asp.net同时调用JS和后台的无效的解决
    QQ浏览器不支持JS问题
    html中opacity的使用
    c#中传递参数前加out
    IE下使用jquery ajax失效
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768393.html
Copyright © 2011-2022 走看看