locked
Removing spaces between words in sql RRS feed

  • Question

  • I guess there is no built in functions to do this but I have a function that replaces anything that is not A-Z with a space and returns @data. What I additionally need the function to do is scrunch up @data (remove all blanks betwwen each word so that 'I ran very fast' would be 'Iranveryfast').

    What I need help in doing is the "Scrunch" part. Is there a way I could move the @Data to something like @DataHold and inspect each character, if it is not a blank, move that character back to @Data?
    This was pretty easy for me to do in C# with a while loop, but I do not know how to get it done in SQL Server 2005.

    Thanks for any help!

     

    Tuesday, March 20, 2007 4:45 PM

Answers

  • Use the replace function.

    replace( @Data, ' ', '' )

    For example,

    DECLARE @Data varchar(1000)
    SET @Data = 'I ran very fast'

    SELECT replace( @Data, ' ', '' )

    ---------------------------------
    Iranveryfast

    Tuesday, March 20, 2007 6:21 PM

All replies