SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO
ALTER FUNCTION [dbo].[fn_StringSplit](@text NVARCHAR(4000), @delimiter varchar(20) = ' ')
-- Được viết bởi Nguyễn Thảo
-- Admin laptrinhvb.net
-- Đường dây nóng : 0933 913 122
RETURNS @Strings TABLE
(
position int IDENTITY PRIMARY KEY,
value NVARCHAR(4000)
)
AS
BEGIN
DECLARE @index int
SET @index = -1
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
GO