Remove Trailing Spaces and Update in Columns in SQL Server

前端 未结 13 1140
抹茶落季
抹茶落季 2020-12-22 20:42

I have trailing spaces in a column in a SQL Server table called Company Name.

All data in this column has trailing spaces.

I want to remove all

13条回答
  •  半阙折子戏
    2020-12-22 21:09

    If you are using SQL Server (starting with vNext) or Azure SQL Database then you can use the below query.

    SELECT TRIM(ColumnName) from TableName;
    

    For other SQL SERVER Database you can use the below query.

    SELECT LTRIM(RTRIM(ColumnName)) from TableName
    

    LTRIM - Removes spaces from the left

    example: select LTRIM(' test ') as trim = 'test '

    RTRIM - Removes spaces from the right

    example: select RTRIM(' test ') as trim = ' test'

提交回复
热议问题