日期:2014-05-16 浏览次数:20569 次
create table codes(
[str] varchar(100) not null
)
insert into codes
select 'acescsdnsd' union all
select 'ESEESMCSD' union all
select 'KQCSSSSSM' union all
select 'ssocsosdesf'
declare @v1 varchar(4)
set @v1 ='CSDN'
select CHARINDEX(@v1,[str]),[str] from codes
declare @T table([ID] int,[str] varchar(11),cnt int)
insert @T
select 1,'acescsdnsd',0 union all
select 2,'ESEESMCSD',0 union all
select 3,'KQCSSSSSM',0 union all
select 4,'ssocsosdesf',0
declare @p varchar(10) set @p='csdn'
declare @i int set @i=len(@p)
while @i>0
begin
update @T set cnt=cnt+sign(charindex(substring(@p,@i,1),[str]))
set @i=@i-1
end
select * from @t
/*
ID str cnt
----------- ----------- -----------
1 acescsdnsd 4
2 ESEESMCSD 3
3 KQCSSSSSM 2
4 ssocsosdesf 3
*/