Create FUNCTION [dbo].[fnSplitString] ( @string NVARCHAR(MAX), @delimiter CHAR(1) ) /* select SplitData from fnSplitString('1,2,3,4,5,6',',') */ RETURNS @output TABLE(splitdata NVARCHAR(MAX) ) AS BEGIN DECLARE @start INT, @end INT SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) WHILE @start < LEN(@string) + 1 BEGIN IF @end = 0 SET @end = LEN(@string) + 1 INSERT INTO @output (splitdata) VALUES(SUBSTRING(@string, @start, @end - @start)) SET @start = @end + 1 SET @end = CHARINDEX(@delimiter, @string, @start) END RETURN END
ChaudharyTechBlog is a technology-focused blog dedicated to providing simple, practical, and easy-to-understand tech guides.
Here, you’ll find tutorials, blogging tips, SEO basics, and helpful resources designed to make technology accessible for everyone.
Our content is carefully researched and written to help you learn, grow, and make informed decisions in the digital world.