試試這個,
declare @t table(SNo int,CompanyName varchar(30))
insert into @t VALUES
(1,'24/7 Customers')
,(2,'Rose & Co.')
,(3,'Rose Inc. Corp.')
,(4,'Rose Pvt. Ltd.,')
;With CTE as
(
select sno
,stuff(CompanyName,PATINDEX('%[,[email protected]\.&/]%',CompanyName),1,'') CompanyName
,SUBSTRING(CompanyName,PATINDEX('%[,[email protected]\.&/]%',CompanyName),1) spcol from @t
union ALL
select sno,
replace(CompanyName,SUBSTRING(CompanyName,PATINDEX('%[,[email protected]\.&/]%',CompanyName),1),'')
,SUBSTRING(CompanyName,PATINDEX('%[,[email protected]\.&/]%',CompanyName),1)
from cte
where PATINDEX('%[,[email protected]\.&/]%',CompanyName)>0
)
select distinct spcol
from cte
你是如何定義的特殊字符?非字母,但不是空格? – jarlh
如果條目僅用ASCII,則可以使用範圍查詢完成。在Unicode中可能不那麼容易。 – Namphibian