Results 1 to 4 of 4

Thread: [RESOLVED] Remove empty spaces in a String in TSQL

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved [RESOLVED] Remove empty spaces in a String in TSQL

    Good Day All


    i have the Following string in a Field

    Code:
    'This
    is the 
     
    reason that i did this>> '
    i want to remove spaces in TSQL to this

    Code:
    This is the reason that i did this>>
    THanks

  2. #2

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Remove empty spaces in a String in TSQL

    In any case try using Replace function:

    REPLACE ( string_expression , string_pattern , string_replacement )

    To replace all new line characters try this:

    REPLACE(@string, CHAR(13)+CHAR(10), '')

    To replace extra spaces you may need to loop and replace every 2 spaces with 1 space.

  4. #4

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Re: Remove empty spaces in a String in TSQL

    Thanks i used this and it worked

    Code:
    declare @NewLine char(2)
    set @NewLine=char(13)+char(10)
     
    select  rtrim(ltrim(Replace('This
    is the 
     
    reason that i did this>> ',@NewLine,'')))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width