Skip to content
Advertisement

How to replace first and last character of column in sql server?

I have a database column and its give a string like ,Recovery, Pump Exchange,.

I want remove first and last comma from string.

Expected Result : Recovery, Pump Exchange.

Advertisement

Answer

You can use SUBSTRING for that:

Obviously, an even better approach would be not to put leading and trailing commas there in the first place, if this is an option.

I want to remove last and first comma only if exist otherwise not.

The expression becomes a little more complex, but the idea remains the same:

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