Trimming text strings in SQL Server 2008

后端 未结 7 1708
无人共我
无人共我 2020-12-30 19:05

I have a table in a SQL Server 2008 database. This table has a nvarchar(256) column called \'Name\'. Unfortunately, the values in this field have extra spaces included. For

相关标签:
7条回答
  • 2020-12-30 19:31

    SQL Server does not have a TRIM function, but rather it has two. One each for specifically trimming spaces from the "front" of a string (LTRIM) and one for trimming spaces from the "end" of a string (RTRIM).

    Something like the following will update every record in your table, trimming all extraneous space (either at the front or the end) of a varchar/nvarchar field:

    UPDATE 
       [YourTableName]
    SET
       [YourFieldName] = LTRIM(RTRIM([YourFieldName]))
    

    (Strangely, SSIS (Sql Server Integration Services) does have a single TRIM function!)

    0 讨论(0)
提交回复
热议问题