The reason for a string with a space in a table
1, spaces are spaces.
2, data is fetched from other systems, files, imported into SQL Server table, because the source data there is a special character display space.
Second, the solution
In the first case, the processing of the whitespace is relatively simple, and Replace (column, ', ') can be solved.
In the second case, the solution is more troublesome: you need to find the appropriate ASCII code, and then replace (Column,char (ASCII), ") to solve, the following is a chestnut:
CREATE TABLE #temp (NAME NVARCHAR) INSERT into #temp Select ' Tomorrow is National Day ' +char --line break SELECT * from #temp -- The end is displayed as a space select replace (NAME, ' ', ') from #temp --To not go away this space select replace (Name,char), ') from #temp -- Remove the space select Replace (Name,char (name,1)) from #temp --If you do not know what character is the last, first turn the ASCII code in the replacement drop TABLE #temp----Below is the result of the query:-' Tomorrow is the National Day '--' Tomorrow is the National Day '--' Tomorrow is the National Day '--' Tomorrow is the National Day '
SQL string de-whitespace workaround