当前位置:Gxlcms > mysql > 根据指定字符分割字符串并输出表格

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

时间:2021-07-01 10:21:17 帮助过:31人阅读

根据指定字符分割字符串并输出表格 无 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(@Ch

根据指定字符分割字符串并输出表格 <无>
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 

人气教程排行