sqlserver里的Split
CREATE FUNCTION f_Split
(
@str varchar(8000),
@strSeperate varchar(10)
)
RETURNS @temp table(a varchar(100))
AS
BEGIN
SET @str=LTrim(RTrim(@str)) --'a,b,c'
--if @str is null or @str=''
DECLARE @i int
SET @i=CHARINDEX(@strSeperate,@str)
WHILE @i>=1
BEGIN
INSERT into @temp SELECT (LEFT(@str,@i-1))
SET @str=SUBSTRING(@str,@i+1,LEN(@str)-@i)
--@str=STUFF(@str,1,@i,'')
SET @i=CHARINDEX(@strSeperate,@str)
END
IF @str!='\'
INSERT into @temp SELECT @str
RETURN
END
GO
select * from f_Split('a,b,c,d,e,f,g',',')
轉自:http://www.cnblogs.com/RobotH/archive/2008/03/15/1107827.html
(
@str varchar(8000),
@strSeperate varchar(10)
)
RETURNS @temp table(a varchar(100))
AS
BEGIN
SET @str=LTrim(RTrim(@str)) --'a,b,c'
--if @str is null or @str=''
DECLARE @i int
SET @i=CHARINDEX(@strSeperate,@str)
WHILE @i>=1
BEGIN
INSERT into @temp SELECT (LEFT(@str,@i-1))
SET @str=SUBSTRING(@str,@i+1,LEN(@str)-@i)
--@str=STUFF(@str,1,@i,'')
SET @i=CHARINDEX(@strSeperate,@str)
END
IF @str!='\'
INSERT into @temp SELECT @str
RETURN
END
GO
select * from f_Split('a,b,c,d,e,f,g',',')
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。