Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

What is the best way to remove all spaces from a string in SQL Server 2008?

LTRIM(RTRIM('  a b ')) would remove all spaces at the right and left of the string, but I also need to remove the space in the middle.

1 Answer

0 votes
by (119k points)

You can use REPLACE() function to remove the spaces in the entire column or a string. Not only spaces, but you can also replace any character with another character. Here is the SQL query to remove all spaces from a string in SQL Server:

SELECT REPLACE(Column_Name, ' ', '')

I recommend checking out this SQL Tutorial to learn more about REPLACE() function.

You can learn in-depth about SQL statements, queries and become proficient in SQL queries by enrolling in an industry-recognized SQL training.

Related questions

0 votes
1 answer
+3 votes
3 answers
asked May 28, 2019 in Python by Anvi (10.2k points)

Browse Categories

...