Create function sp_split ( @c nvarchar (4000), @splitchar nvarchar (1)) Returns @table table (Word nvarchar ( max)) Asbegin declare @temp nvarchar () set @[email Protected][email protected] at the far right, add a delimiter for the last to get the rightmost string while CharINDEX (@splitchar, @c) >0 begin/ * CharINDEX (@splitchar, @c) find the first position in the string where the delimiter appears SUBSTRING (@c,1, CharINDEX (@splitchar, @c)-1) intercept the string in front of the delimiter right (@c,len (@c)-charindex (@splitchar, @c)) Intercepting a string from the right specifies the length of the string, removing the string that has been found in the strings */ set @temp =substring (@c,1, CharINDEX (@splitchar, @c)-1) if (len @ Temp) >0) Begininsert @table values (@temp) End set @c=right (@c,len (@c)-charindex (@splitchar, @c)) end return End
SQL Server String Segmentation