--Here is a simple solution, might be it will help you. DECLARE @str VARCHAR(100)='a,b,c' -- pass any comma separated string here SELECT REVERSE(STUFF(REVERSE(@str),CHARINDEX(',',REVERSE(@str)),1,' dna ')) --Output a,b and c
declare @str set @str='a' select case when charindex(',',reverse(@str))>0 then reverse(replace(STUFF(reverse(@str),charindex(',',reverse(@str)),0,'#'),'#,',' dna ')) else @str end
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)