if(OBJECT_ID('fn_GetCombineName') is not null)
drop function fn_GetCombineName
go
CREATE FUNCTION fn_GetCombineName
(
@CombineName nvarchar(max),
@SegIndexStr nvarchar(500),
@SegIndex int
)
RETURNS nvarchar(max)
AS
BEGIN
declare @Result nvarchar(max)=''
declare @SegIndex1 int = 1
declare @str1 nvarchar(500) = ''
declare @str2 nvarchar(500) = @CombineName
while (@SegIndex1 <= @SegIndex)
begin
--print(@SegIndex1)
declare @currentstr nvarchar(500) = ''
set @currentstr = substring(@str2, 0, CHARINDEX('#@#', @str2, 0))
declare @Oldstr1 nvarchar(500) = ''
set @Oldstr1 = @str1
set @str1 = @str1 + substring(@str2, 0, CHARINDEX('#@#', @str2, 0) + 3)
set @str2 = substring(@CombineName, len(@str1) + 1, len(@CombineName) - len(@str1))
if (@SegIndex1 = @SegIndex)
begin
set @Result= @Oldstr1 + @SegIndexStr + '#@#' + @str2
end
set @SegIndex1 = @SegIndex1 + 1
end
return @Result
END
GO
版权归属:
绀香廿九
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区