March 2017 Entries

SQL Server: How do I split a comma delimited column into multiple columns or rows?
-- converting column with commas to multiple columns --declare @col1 varchar(500)set @col1 = 'I,Hate,Broccoli'DECLARE @Tmp TABLE ( Id int, Element VARCHAR(20)) INSERT @Tmp SELECT 1,@col1 SELECT Id, PARSENAME(REPLACE(Element,'... Name, PARSENAME(REPLACE(Element,'... Surname FROM @Tmp-- converting column with commas to multiple rows --declare @col1 varchar(500)set @col1 = 'I,am,really,a,smart person, one of the smartest'DECLARE @Tmp TABLE ( Id int, Element VARCHAR(200)) INSERT @Tmp SELECT ......

Posted On Thursday, March 9, 2017 4:32 PM | Comments (0)