T-SQL: UDF Scalar Function to Clean Multiple Spaces

While working on autocomplete dropdown, i created a simple scalar function that replaces multiple spaces with one.

Create database

Create Function

Test the function

If you need to clean only the non-leading and the non-trailing spaces (the inner spaces), remove LTRIM(RTRIM(()) (lines 23, 29)

Delete database

Keep it simple :-)