Regex function whitespace SQL Server 2008 [duplicate]

0

Hello,

Within a specific table in my DB, I have certain fields that have been registered by others, so some fields instead of having a simple space ' ' , have spaces of the most diverse types! I do the Javascript treatment as follows:

/\s/g

However, I would like to create a function within SQL Server that would do this type of processing. It's possible? I tried something similar here but nothing effective and tried to create a function through the syntax above but without results.

Thank you!

    
asked by anonymous 17.07.2017 / 16:16

1 answer

0

Try the form below, you can use it 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
    
17.07.2017 / 18:45