if exists(select 1 from tb where registreName like '%张三%') print '存在的用户,不可以注册' else insert into tb ......
exists(select 1 from tb where registreName like '%小王%')
if charindex('小王',注册名)>0 --存在 else --不存在
if exists (select 1 from table where registreName like '小王%') print '....' else insert into table ...如果想判断名字有类似的,就用'%小王%' '小王%'只判断了是否其后有区别
--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
if exists(select 1 from tb where registreName like '%张三%') print '存在的用户,不可以注册' else insert into tb ......
print '存在的用户,不可以注册'
else
insert into tb ......
if charindex('小王',注册名)>0
--存在
else
--不存在
print '....'
else insert into table ...如果想判断名字有类似的,就用'%小王%'
'小王%'只判断了是否其后有区别
--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
print '存在的用户,不可以注册'
else
insert into tb ......