Use User Defined function called "[dbo].[CustomSplit]" as follows:SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCreate FUNCTION [dbo].[CustomSplit] (@sep char(1), @Words varchar(512))RETURNS tableASRETURN (WITH Pieces(n, start, stop) AS (SELECT 1, 1, CHARINDEX(@sep, @Words)UNION ALLSELECT n + 1, stop + 1, CHARINDEX(@sep, @Words, stop + 1)FROM PiecesWHERE stop > 0)SELECT n,SUBSTRING(@Words, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS WordsFROM Pieces)
GO Declare @tmp NVARCHAR(MAX) = 'aaa,bbb,ccc,ddd'SELECT * FROM dbo.CustomSplit(',', @tmp)--Chandu