CREATE FUNCTION [dbo].[
(
@sTextToSplit NVARCHAR(MAX),
@Delimiter NVARCHAR(50)
)
RETURNS @tbReturn table
(
RowId INT IDENTITY(1,1),
Value NVARCHAR(MAX)
)
AS
BEGIN
SET @Delimiter = LTRIM(RTRIM(@Delimiter))
DECLARE @sSplitedValue NVARCHAR(MAX), @Pos INT
SET @sTextToSplit = LTRIM(RTRIM(@sTextToSplit))+ @Delimiter
SET @Pos = CHARINDEX(@Delimiter, @sTextToSplit, 1)
IF REPLACE(@sTextToSplit, @Delimiter, '') <> ''
BEGIN
WHILE @Pos > 0
BEGIN
SET @sSplitedValue = LTRIM(RTRIM(LEFT(@
IF @sSplitedValue <> ''
BEGIN
INSERT INTO @tbReturn VALUES (@sSplitedValue)
END
SET @sTextToSplit = RIGHT(@sTextToSplit, LEN(@sTextToSplit) - @Pos)
SET @Pos = CHARINDEX(@Delimiter, @sTextToSplit, 1)
END
END
RETURN
END
No comments:
Post a Comment