根据指定字符分割字符串并输出表格

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

CREATE FUNCTION [dbo].[Splitstring] (@StringToSplit NVARCHAR(max), 
 @CharSpliter NVARCHAR(5)) 
returns @SplitTable TABLE ( 
 data NVARCHAR(50)) 
AS 
 BEGIN 
 DECLARE @Count INT 

 SET @Count = 1 

 WHILE ( Charindex(@CharSpliter, @StringToSplit) > 0 ) 
 BEGIN 
 INSERT INTO @SplitTable
 (data) 
 SELECT Data = Ltrim(Rtrim(Substring(@StringToSplit, 1, 
 Charindex(@CharSpliter, @StringToSplit) - 1) 
 )) 

 SET @StringToSplit= Substring(@StringToSplit, Charindex(@CharSpliter, @StringToSplit
 ) 
 + 1, 
 Len(@StringToSplit)) 
 SET @Count = @Count + 1 
 END 

 INSERT INTO @SplitTable
 (data) 
 SELECT Data = Ltrim(Rtrim(@StringToSplit)) 

 RETURN 
 END 

go