首頁 >資料庫 >mysql教程 >根据指定字符分割字符串并输出表格

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

WBOY
WBOY原創
2016-06-07 14:56:351032瀏覽

根据指定字符分割字符串并输出表格 无 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 
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn