close
from:黑暗執行緒
ALTER FUNCTION SplitCSV
(
@csv NVARCHAR(4000),
@delm CHAR(1)
)
RETURNS @Result TABLE
(
Element NVARCHAR(4000)
)
AS
BEGIN
DECLARE @p INT, @lastP INT, @quit CHAR(1)
SET @p = 1
SET @lastP = 0
SET @quit = 'N'
WHILE @quit = 'N'
BEGIN
SET @p = CHARINDEX(@delm, @csv, @lastP + 1)
IF (@p = 0)
BEGIN
INSERT INTO @Result VALUES
(SUBSTRING(@csv, @lastP + 1, LEN(@csv) - @lastP))
SET @quit = 'Y'
END
ELSE
INSERT INTO @Result VALUES
(SUBSTRING(@csv, @lastP + 1, @p - @lastP - 1))
SET @lastP = @p
END
RETURN
END
全站熱搜
留言列表