Explore Courses Blog Tutorials Interview Questions
0 votes
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)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories