欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

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

程序员文章站 2023-12-28 14:16:28
...

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

上一篇:

下一篇: