sql 分词技术
shi yi gong
分词后形成一个如下的table
idone
1shiyigong
2shi yigong
3shi yi-gong sql 技术
[解决办法]
--創建函數
create function [dbo].[f_firstposition](@Str varchar(8000),@StrSep varchar(10),@AppPos int)
returns int
begin
declare @i int
declare @ii int
set @Str=rtrim(ltrim(@Str))
set @i=1
select @ii=charindex(@StrSep,@Str)
if @i=@AppPos
return @ii
else
while @AppPos>@i
begin
if charindex(@StrSep,right(@Str,len(@Str)-@ii))<>0
select @ii=charindex(@StrSep,right(@Str,len(@Str)-@ii))+@ii
else
set @ii=0
set @i=@i+1
end
return @ii
END
GO
--執行查詢
;WITH a1 (cstr) AS
(
SELECT 'shi yi gong'
)
SELECT REPLACE(cstr,' ','') cstr FROM a1
UNION ALL
SELECT STUFF(cstr,dbo.f_firstposition(cstr,' ',2),1,'') cstr FROM a1
UNION ALL
SELECT STUFF(cstr,dbo.f_firstposition(cstr,' ',2),1,'-') cstr FROM a1