在 MS SQL 中用单个逗号替换多个逗号 [英] Replacing multiple commas with single comma in MS SQL

查看:80
本文介绍了在 MS SQL 中用单个逗号替换多个逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 MS SQL 中用单个逗号替换列中的连续逗号?

How do I replace consecutive commas in a column with single comma in MS SQL?

例如,我有像

 a,,,,b,,,c,,,,,,
 d,e,,,f,,,,,,g,,  

我希望将其处理为以下格式:

I want this to be processed to following format:

 a,b,c,
 d,e,f,g,

建议重复,使用 SQL 将字符串中的多个逗号替换为单个逗号,适用于 Oracle.这是一个关于 SQL Server 的问题.

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.

推荐答案

这就是我所做的.

select replace(replace(replace('a,,,b,,,c,d,e,,,,f',',','<>'),'><',''),'<>',',')

select replace(replace(replace('a,,,b,,,c,d,e,,,,f',',','<>'),'><',''),'<>',',')

这篇关于在 MS SQL 中用单个逗号替换多个逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆