实现字符串分隔功能的函数

CREATE FUNCTION [dbo].[Func_Split]
(  
   @inputstr VARCHAR(max), 
   @seprator VARCHAR(10)
)
RETURNS @temp TABLE (A VARCHAR(200))
AS
BEGIN
DECLARE @i INT
SET @inputstr = RTRIM(LTRIM(@inputstr))
SET @i = CHARINDEX(@seprator , @inputstr)
WHILE @i >= 1
BEGIN
INSERT @temp VALUES(LEFT(@inputstr , @i - 1))
SET @inputstr = SUBSTRING(@inputstr , @i + 1 , LEN(@inputstr) - @i)
SET @i = CHARINDEX(@seprator , @inputstr)
END
IF @inputstr <> '\'
INSERT @temp VALUES(@inputstr)
RETURN 
END

 

posted @ 2017-05-31 10:45  芈璐  阅读(137)  评论(0编辑  收藏  举报