How do I replace consecutive commas in a column with single comma in MS SQL?
For example, I have data like
a,,,,b,,,c,,,,,, d,e,,,f,,,,,,g,,
I want this to be processed to following format:
a,b,c, d,e,f,g,
The suggested duplicate, Use SQL to Replace Multiple Commas in a String with a Single Comma, is for Oracle. This is a question about SQL Server.
Advertisement
Answer
This is what i did.
select replace(replace(replace(‘a,,,b,,,c,d,e,,,,f’,’,’,'<>’),’><‘,”),'<>’,’,’)