CREATE FUNCTION [fn_Split]
(
@String VARCHAR (MAX),
@Delimiter VARCHAR (12)
)
RETURNS @ValueTable TABLE
(
idx int identity(1,1),
StrValue VARCHAR(MAX)
)
BEGIN
DECLARE
@NextString VARCHAR(MAX),
@Pos INT,
@NextPos INT,
@CommaCheck VARCHAR(1)
SET @NextString = ''
SET @CommaCheck = RIGHT(@String, 1)
SET @String = @String + @Delimiter
SET @Pos = CHARINDEX(@Delimiter, @String)
SET @NextPos = 1
WHILE (@pos <> 0)
BEGIN
SET @NextString = SUBSTRING(@String, 1, @Pos - 1)
IF (LEN(@NextString) > 0)
INSERT INTO @ValueTable (StrValue) VALUES (@NextString)
SET @String = SUBSTRING(@String, @pos + LEN(@Delimiter), LEN(@String))
SET @NextPos = @Pos
SET @pos = CHARINDEX(@Delimiter, @String)
END
RETURN
END
댓글 없음:
댓글 쓰기