日期:2014-05-17 浏览次数:20589 次
declare @t varchar(100),@s varchar(100)
set @t='alfki77777777bfd'
set @s=substring(@t,charindex('f',@t,1)+1,len(@t)-charindex('f',reverse(@t),1)-charindex('f',@t,1))
select @s 's'
/*
s
----------------------
ki77777777b
(1 row(s) affected)
*/
declare @t char(100),@s char(100)
set @t='alfki77777777bfd'
set @s=substring(@t,patindex('%f%','alfkibfd')+1,len(@t))
print substring(@t,patindex('%f%',@t)+1,patindex('%f%',@s)-1)
--楼主的方法已经不错了
SELECT SUBSTRING(STUFF(@t,1,CHARINDEX('f',@t),''),1,CHARINDEX('f',STUFF(@t,1,CHARINDEX('f',@t),''))-1)
SELECT SUBSTRING(@t, CHARINDEX('f',@t)+1, LEN(@t) - CHARINDEX('f',@t) - CHARINDEX('f',REVERSE(RTRIM(@t))))
/*ki77777777b*/