I'm trying to split comma-separated data into separate columns (using SQL Server 2008). I've seen similar questions on here, but in my case, the data contained in each row is BOTH comma-delimited and carriage-return-delimited.
EXAMPLE:
Date Content ---- ------- 1/1/2019 1, John, Doe 2, Jane, Doe 1/2/2019 1, John, Doe 2, Jane Doe 3, Mary, Smith
Using a custom split function, I was able to return the value for just one record:
SELECT * FROM Split_CTE((SELECT TOP 1 content FROM myTable), CHAR(10))
RESULT:
1,John,Doe 2,Jane,Doe
And using a substring function, I was able to return just the first row from each record:
SELECT dateRetrieved, SUBSTRING(content, 1, CHARINDEX(CHAR(10), content)-1) as Row FROM myTable
RESULT:
1/1/2019 1,John,Doe 1/2/2019 1,John,Doe
But what I'm trying to get back is this:
Date Row First Last 1/1/2019 1 John Doe 1/1/2019 2 Jane Doe 1/2/2019 1 John Doe 1/2/2019 2 Jane Doe 1/2/2019 3 Mary Smith
Any suggestions?