title: Divide long string into multiple strings SQL
body: <p>So basically I would like a long string to be cut into smaller pieces, but keeping the words intact. So if I have the following sentence in let's say the FoxTable in the column of JumpColumn:</p>
  
  <blockquote>
    <p>the brown fox jumped over the lazy dog and then the lazy dog jumped over the brown fox</p>
  </blockquote>
  
  <p>I would like to split it into max 20 characters (incl. spaces) in SQL. So the outcome would be something like this:</p>
  
  <pre><code>the brown fox jumped 
   over the lazy dog
   and then the lazy 
  dog jumped over the 
  brown fox
  </code></pre>
  
  <p>However, keep in mind that there are different sentences in the JumpColumn column with different lengths and words.</p>
  
  <p>What my query does now is the breaking it into different lines with a SUBSTRING function in SQL-Server.</p>
  
  <pre><code>DECLARE @string_part1 NVARCHAR(500), 
          @string_part2 NVARCHAR(500), 
          @string_part3 NVARCHAR(500), 
          @string_part4 NVARCHAR(500),
          @string_part5 NVARCHAR(500),
          @LoopCount = 1
  
  WHILE (@LoopCount &lt;= 100)
  BEGIN
       SELECT
        string_part1 NVARCHAR(500)  = SUBSTRING(JumpColumn, 0, 20)
       ,string_part2 NVARCHAR(500)  = SUBSTRING(JumpColumn, 20, 20)
       ,string_part3 NVARCHAR(500)  = SUBSTRING(JumpColumn, 40, 20)
       ,string_part4 NVARCHAR(500)  = SUBSTRING(JumpColumn, 60, 20)
       ,string_part5 NVARCHAR(500)  = SUBSTRING(JumpColumn, 80, 20)
  
  FROM FoxTable
  WHERE Row = @LoopCount
  
  SET @LoopCount = @LoopCount + 1
  END
  </code></pre>