CREATE Function [fn_Split_IndexString]
(
@str VARCHAR(MAX)
, @p CHAR(1)
, @n INT
)
Returns varchar(max)
AS
Begin
IF (LEN(@str) > 0 AND RIGHT(@str,1) != @p)
SET @str = @str + @p
DECLARE @new_str VARCHAR(50), @i TINYINT
SET @new_str = ''
IF (CHARINDEX(@p, @str) <> 0)
BEGIN
SET @i = 1
WHILE (CHARINDEX(@p, @str) <> 0)
BEGIN
SET @new_str = SUBSTRING(@str,1,CHARINDEX(@p,@str) - 1)
IF (@n = @i)
RETURN @new_str
--SET @str = SUBSTRING(@str,CHARINDEX(@p, @str) + LEN(@p), LEN(@str))
if (@p = ' ')
SET @str = SUBSTRING(@str,CHARINDEX(@p, @str) + 1, LEN(@str))
else
SET @str = SUBSTRING(@str,CHARINDEX(@p, @str) + LEN(@p), LEN(@str))
SET @i = @i + 1
END
END
RETURN NULL
End
댓글 없음:
댓글 쓰기