【043】多语言表字符串处理fn_GetCombineName
侧边栏壁纸
  • 累计撰写 70 篇文章
  • 累计收到 2 条评论

【043】多语言表字符串处理fn_GetCombineName

竹秋廿九
2025-04-08 / 0 评论 / 16 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2025年04月17日,已超过293天没有更新,若内容或图片失效,请留言反馈。
if(OBJECT_ID('fn_GetCombineName') is not null)
    drop function fn_GetCombineName
go

CREATE FUNCTION [dbo].[fn_GetSegName] 
(
    @CombineName nvarchar(max),
    @SplitStr nvarchar(50),
    @SegIndex int
)
RETURNS nvarchar(max)
AS
BEGIN
    
    --如果组合名称自身为空,则返回空串
    if (@CombineName is null or @CombineName='') return ''
    
    declare @Result nvarchar(max)
    
    declare @x nvarchar(max)
    select @x=@CombineName    
    select @x=replace(@x,' ',' ')
    select @x=replace(@x,'',' ')

    declare @curIndex int
    
    declare @i int
    set @i=1
    WHILE @i<=@SegIndex
    BEGIN
        set @curIndex=charIndex(@SplitStr,@x,0)
        if @curIndex=0
        BEGIN
            if (@i=@SegIndex) set @result=@x else  set @result=''
            break
        END
        set @result=left(@x,@curIndex-1)
        if (@i=@SegIndex) break
        
        --准备下次循环
        set @x=right(@x,len(@x)-len(@result)-len(@SplitStr))
        set @i=@i+1
    END
    return @Result
END
0

评论

博主关闭了当前页面的评论