To split a delimited string to multiple rows using MSSQL you can use the snippet below.
Sample MSSQL
CREATE FUNCTION dbo.StringSplit
(
@Input NVARCHAR(MAX),
@Delimiter NVARCHAR(255)
)
RETURNS TABLE
AS
RETURN (
SELECT Number = ROW_NUMBER() OVER (ORDER BY Number),
Item FROM (
SELECT Number, Item = LTRIM(RTRIM(SUBSTRING(@Input, Number, CHARINDEX(@Delimiter, @Input + @Delimiter, Number) - Number)))
FROM (SELECT ROW_NUMBER() OVER (ORDER BY ao.[object_id])
FROM sys.all_objects AS ao CROSS APPLY sys.all_objects) AS n(Number)
WHERE Number <= CONVERT(INT, LEN(@Input))
AND SUBSTRING(@Delimiter + @Input, Number, 1) = @Delimiter
) AS item);
GO
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…
RT @CodeSnippetsNET: How to split a delimited string to multiple rows using #MSSQL http://t.co/0UdGHtlX8q #tsql #sequelserver #scripting #s…