I am trying to split the , separated records in separated columns.
I am having 2 issues,
1st if I have more than 4 , separated values than parsename returns NULL
2nd If I have '.' in my rows than also it returns Null.
This is the query which I made and is working fine.
declare @t table (items varchar(50))
insert into @t values ('Apple,banana,mango,pineapple')
select * from @t
SELECT
PARSENAME(REPLACE(items,',','.'),4) Col1,
PARSENAME(REPLACE(items,',','.'),3) Col2,
PARSENAME(REPLACE(items,',','.'),2) Col3,
PARSENAME(REPLACE(items,',','.'),1) Col4
FROM @t
But this query returns null.
declare @t table (items varchar(50))
insert into @t values ('Apple.,banana,mango,pineapple')
select * from @t
SELECT
PARSENAME(REPLACE(items,',','.'),4) Col1,
PARSENAME(REPLACE(items,',','.'),3) Col2,
PARSENAME(REPLACE(items,',','.'),2) Col3,
PARSENAME(REPLACE(items,',','.'),1) Col4
FROM @t
Because of '.'
And also If I add another fruit in my item column it will return Null.
SO my question is how to split the comma separated items in different column if parsename is not working?