Function regex blank spaces SQL Server 2008

Asked

Viewed 384 times

0

Hello,

Within a specific table in my DB, I have certain fields that were registered by someone else (users), so some fields instead of having a single space ' ', has spaces of the most diverse types! I do the processing in Javascript as follows:

/\s/g

However, I would like to create a function within SQL Server that does this kind of processing. Is it possible? I looked here in the forum something similar but nothing effective and, I tried to create a function through the above syntax but without results.

Thank you!

  • @Marconi but if there is another type of "space", such as a tab, will it remove tbm? I am without sql now to test

  • @jvbarsou made the test with a tab and worked, a tab inside the Sql-Management considered with 1 space, now already two this solution does not treat.

  • @jvbarsou tries to take this my solution and adapts in Juliet’s response to this reply so-EN.

  • 1

    Reading suggestion : What the REGEX shortcut means

1 answer

0

Try the form below and you can use as a function.

Declare @Texto1 varchar(100),
        @TextoTemp varchar(100),
        @Tamanho Integer,
        @Posicao Integer

Set @Texto1= 'pro paro xiton  a'
Set @Tamanho=Len(@Texto1)
Set @Posicao=1
Set @TextoTemp = ''

While @Posicao <= @Tamanho
Begin
   If SubString(@Texto1,@Posicao,1) <> ' '
      Begin
         Set @TextoTemp = @TextoTemp + SubString(@Texto1,@Posicao,1)
      end

   Set @Posicao = @Posicao+1
end

SELECT @TextoTemp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.