shi yi gong分词后形成一个如下的table
id one
1 shiyigong
2 shi yigong
3 shi yi-gongsql技术

解决方案 »

  1.   

    这种取用SQL实现就没有多大的意义了吧,交给程序员去完成吧。
      

  2.   


    --創建函數
    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
      

  3.   

    declare @tb table (cstr varchar(100))
    insert @tb select 'shi yi gong'SELECT REPLACE(cstr,' ','') cstr FROM @tb
    UNION ALL
    SELECT STUFF(cstr,dbo.f_firstposition(cstr,' ',2),1,'') cstr FROM @tb
    UNION ALL
    SELECT STUFF(cstr,dbo.f_firstposition(cstr,' ',2),1,'-') cstr FROM @tb