CREATE FUNCTION [dbo].[Split](@text nvarchar(max))
RETURNS @Strings TABLE
(
value nvarchar(max)
)
AS
BEGIN
DECLARE @index int
DECLARE @delimiter char(1)
SET @index = -1
SET @delimiter = ','
WHILE (LEN(@text) > 0)
BEGIN
SET @index = CHARINDEX(@delimiter , @text)
IF (@index = 0) AND (LEN(@text) > 0)
BEGIN
INSERT INTO @Strings VALUES (@text)
BREAK
END
IF (@index > 1)
BEGIN
INSERT INTO @Strings VALUES (LEFT(@text, @index - 1))
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
ELSE
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
RETURN
END
Немає коментарів:
Дописати коментар