不想让注册时候存在类似的名字,比如  小王 ,不想让其他人注册如,小王二,小王三
只要存在的用户,后面加任何字符都不行,不可以注册这个语句怎么写

解决方案 »

  1.   

    if exists(select 1 from tb where registreName like '%张三%')
    print '存在的用户,不可以注册'
    else
    insert into tb ......
      

  2.   

    exists(select 1 from tb where registreName like '%小王%')
      

  3.   


    if charindex('小王',注册名)>0
    --存在
    else
    --不存在
      

  4.   

    if exists (select 1 from table where registreName like '小王%')
    print '....'
    else insert into table ...如果想判断名字有类似的,就用'%小王%'
    '小王%'只判断了是否其后有区别
      

  5.   


    --re:sqlserver version>=2008
    declare @t_register table (iid int,name varchar(10))--there is already a record containing Key:Hellan 
    insert into @t_register
    select 1,'Hellan'--tends to insert a new record,also containing Key:Hellan ,then inore it
    merge @t_register as R
    using (select 2 as iid,'Hellan.B' as name) as T
    on T.name like R.name+'%'
    when matched then --already a record exists ,do nothing
    update set R.name=R.name
    when not matched then --record not found in the database ,insert it
    insert(iid,name)values(T.iid,T.name);select * from @t_register
      

  6.   

    if exists(select 1 from tb where registreName like '%张三%')
    print '存在的用户,不可以注册'
    else
    insert into tb ......