SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
by kudychen 2011-9-28
*/
CREATE function [dbo].[SplitString]
(
@Input nvarchar(max), --input string to be separated
@Separator nvarchar(max)=',', --a string that delimit the substrings in the input string
@RemoveEmptyEntries bit=1 --the return value does not include array elements that contain an empty string
)
returns @TABLE table
(
[Id] int identity(1,1),
[Value] nvarchar(max)
)
as
begin
declare @Index int, @Entry nvarchar(max)
set @Index = charindex(@Separator,@Input)
while (@Index>0)
begin
set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1)))
[MSSQL]实现SQL Server中的切割字符串SplitString标量函数
最新推荐文章于 2024-05-09 21:56:42 发布
本文介绍如何在SQL Server中创建一个名为SplitString的标量函数,用于将字符串按指定分隔符切割。该函数考虑了是否移除空项,并提供了使用示例。
摘要由CSDN通过智能技术生成