Guys, how to remove spaces between rows with T-SQL?

<span class="p-title">Вес </span><span class="p-value"> 140</li> <li><span>Area di stampa </span>65</li> <li><span>Misura</span> 50</li> 

  • Specify the server version. Well or at once look towards CLR and regular expressions. - Akina
  • It must be assumed that the number of spaces is arbitrary? - teran

1 answer 1

This code removes multiple spaces:

 declare @string AS varchar(4000) SET @string = '<span class="p-title">Вес </span><span class="p-value"> 140</li> <li><span>Area di stampa </span>65</li> <li><span>Misura</span> 50</li>' SELECT @string SELECT REPLACE( REPLACE( REPLACE( LTRIM(RTRIM((@string))) ,' ',' '+CHAR(7) ) ,CHAR(7)+' ','') ,CHAR(7),'') AS ClearedString 

More information about the algorithm can be found in this article.

Important: the solution will remove multiple spaces and not damage the data strings, provided that the character - it is char(7) , will not appear in the data string. If it can be present in the string - you need to choose guaranteed unused and replace all occurrences of char(7) in the code with a new character.