日期:2014-05-18 浏览次数:20676 次
select substring(col,1,charindex('%',col+'%')-1) from tb
--没环境,没测,LZ试下
------解决方案--------------------
--或者
select left(col,charindex('%',col+'%')-1) from tb
--col换成你的字段
------解决方案--------------------
declare @t table (col varchar(16))
insert into @t
select '李明%张平%郭大可' union all
select '张平%郭大可' union all
select '郭大可'
select col=left(col,charindex('%',col+'%')-1) from @t
/*
col
----------------
李明
张平
郭大可
*/
------解决方案--------------------
declare @t table (col varchar(16))
insert into @t
select '李明%张平%郭大可' union all
select '张平%郭大可' union all
select '郭大可'
--如果%不超过3个,可以用parsename
select
col=parsename(replace(col,'%','.'),len(col)-len(replace(col,'%',''))+1)
from @t
/*
col
----------
李明
张平
郭大可
*/