This is what you get as the result:
This is what you get as the result:
-- -- Steven Rao -- June 15, 2013 -- A simple and efficient way to split string with separator -- It has very good performance since no looping is used USE [TEST] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_SplitString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[fn_SplitString] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[fn_SplitString](@string AS VARCHAR(8000), @stringSeperator AS CHAR(1)) RETURNS TABLE AS RETURN SELECT (number - 1) - LEN(REPLACE(LEFT(@string, number - 1), @stringSeperator, '')) + 1 AS stringNumber ,LTRIM(RTRIM(SUBSTRING(@string, number, CHARINDEX(@stringSeperator, @string + @stringSeperator, number) - number))) AS stringValue FROM(select number from master..spt_values where type='p') as numbers WHEREnumber <= LEN(@string) + 1 AND SUBSTRING(@stringSeperator + @string, number, 1) = @stringSeperator; GO