Skip to content
Advertisement

SQL – Replace characters in a SQL string

I would like to know how to replace all characters between 2 dashes (-) and replace the dashes as well. It should be in a single select statement, not a loop. The text between the dashes can be variable length and any character. The characters before and after the dashes can also be variable length.

Advertisement

Answer

You can do it by using CHARINDEX, SUBSTRING and LEN

Check this fiddle

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement