Trim function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepk84
    New Member
    • Oct 2006
    • 97

    Trim function

    hi all..
    i have a doubt...how we can remove blank spaces
    in a column value while retrieving?
    i tried using LTRIM(RTRIM(COL UMN NAME))...
    But it's removing only the leading and trailing spaces...
    how i can remove spaces in between?
    anybody please help...
    thanks and regards,
    Sand...
  • scripto
    New Member
    • Oct 2006
    • 143

    #2
    Originally posted by sandeepk84
    hi all..
    i have a doubt...how we can remove blank spaces
    in a column value while retrieving?
    i tried using LTRIM(RTRIM(COL UMN NAME))...
    But it's removing only the leading and trailing spaces...
    how i can remove spaces in between?
    anybody please help...
    thanks and regards,
    Sand...

    Replace(COLUMN_ NAME, " ", "")

    Comment

    • lordspace
      New Member
      • Nov 2006
      • 10

      #3
      I think that will erase all the spaces.
      Trim should erase leading and trailing white spaces
      oopps
      your answer is correct, the other user requested to delete all spaces.

      Comment

      • heberd
        New Member
        • May 2010
        • 1

        #4
        SQL Trim

        Look at http://sqltrim.codeplex.com for a function that will trim spaces from a string

        Comment

        • trajender
          New Member
          • Jan 2012
          • 1

          #5
          replace(replace ( cast(ba.heading 1 as varchar),'<p>', ''),'</p>','')

          Comment

          • jonno99
            New Member
            • Jan 2012
            • 1

            #6
            Try this simple whitespace remover

            Code:
            This should handle any variation of whitespace:
            
            declare @text varchar(500)
            set @text = 'delete      white      space' -- add as many spaces between the words as you want...
            set @text = replace(replace(replace(replace(replace(@text,'     ',' '),'    ',' '),'   ',' '),'  ',' '),'  ',' ')
            print @text
            
            Note: if you know that your whitespace count will never exceed 30 spaces, you can omit the '5 spaces' iteration.
            Important Note: don't click on 'Wrap' - it messes up the formatting. If you did click wrap, refreshing the page seems to return things to normal...
            Last edited by jonno99; Jan 30 '12, 09:44 PM. Reason: Clarity

            Comment

            Working...