How to Remove additional speces after add Replace function

Mahesh Madhusanka 176 Reputation points
2020-09-02T17:51:44.293+00:00

Hi Team,

Currently i have faced issue as a after add replace function to SQL column to remove comma, then output parsing as a addotional spaces on the SQL column data feilds, According to i have used below trim method but its not worked, Could you please advise on this..

Replace Function- Replace(Replace(Replace(Replace(OA_AdditionalAddressInformation,',',' '),'"',''),'/',' '),'"','') as OA_AdditionalAddressInformation,

After adding trim on it. - LTRIM(RTRIM(Replace(Replace(Replace(Replace(OA_AdditionalAddressInformation,',',' '),'"',''),'/',' '),'"',''))) as OOA_AdditionalAddressInformation,

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,605 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,545 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Junior Galvão MVP 76 Reputation points MVP
    2020-09-02T18:25:52.827+00:00

    Mahesh,

    What version of SQL Server are you using?

    As of version 2017 there is the [TRIM()][1] function.

    0 comments No comments

  2. Mahesh Madhusanka 176 Reputation points
    2020-09-02T18:42:50.883+00:00

    Hi @Junior Galvão MVP and Team,

    Our SQL Server Version is
    SQL Server Version: 13.00.5820.21 (x64)
    SQL Server 2016

    and Could you please Support to add this suggetion trim command to below my Current colum condition.

    Current Replace column.

    Replace(Replace(Replace(Replace(OA_AdditionalAddressInformation,',',' '),'"',''),'/',' '),'"','') as OA_AdditionalAddressInformation,


  3. Mahesh Madhusanka 176 Reputation points
    2020-09-03T02:20:10.033+00:00

    Hi Anurag and Team,

    Currently we have SQL tables Columns there have additional Commas inside the column and '/' data

    (Ex value- MAISDIJK 5,PO. BOX 56, )
    according to we want to replace inserted of comma and "/", Below is a current replace condition i used but once i used it its parsing unremovable addional spaces. Could you please support to remove it.

    Current Replace column.

    Replace(Replace(Replace(Replace(OA_AdditionalAddressInformation,',',' '),'"',''),'/',' '),'"','') as OA_AdditionalAddressInformation,

    Thanks
    Mashe


  4. EchoLiu-MSFT 14,571 Reputation points
    2020-09-03T07:24:54.81+00:00

    Hi @Mahesh Madhusanka ,

    You can try char(10), char(13):

     select replace(replace(replace(Replace(Replace(Replace(Replace('Ex value- MAISDIJK 5,PO. BOX 56,',',',' '),'"',''),'/',' '),'"',''),char(10)+char(13),''),char(10),''),char(13),'') as OA_AdditionalAddressInformation  
    

    22356-image.png
    Another method:

    select replace( Replace(Replace(Replace(Replace('Ex value- MAISDIJK 5,PO. BOX 56,' ,',',' '),'"',''),'/',' '),'"','') ,' ','') as OA_AdditionalAddressInformation  
    

    22324-image.png

    Best Regards
    Echo

    0 comments No comments

  5. Erland Sommarskog 100.8K Reputation points MVP
    2020-09-03T21:38:15.15+00:00

    When there are characters you can't seem to remove, cast the value to binary to see what character codes actually are. For instance, it could be a hard space, char(160). Or as Echo suggests CR-LF.