title: T-SQL Recursive CTE, shortened result required for long path
body: <p>Dear Stackoverflow members</p>
  
  <p>I have a recursive CTE query like this:</p>
  
  <pre><code>DECLARE @Level TABLE (ID int, ParentID int, Name varchar(max))
  
  INSERT INTO @Level (ID, ParentID, Name)
           VALUES (1,0, 'AAAA'),
                  (2,1, 'BBBB'),
                  (3,2, 'CCCC'),
                  (4,3, 'DDDD'),
                  (5,4, 'EEEE')
  
  ;WITH cte (ID, ParentID, Name, Path, Level) AS
  (
       SELECT 
           ID, ParentID, Name, CONVERT(varchar(MAX), Name), 1
       FROM 
           @Level
       WHERE 
           ParentID = 0
  
       UNION ALL
  
       SELECT 
           n.ID, n.ParentID, n.Name, 
           CONVERT(varchar(MAX), cte.Path + '/' + n.Name), cte.Level + 1
       FROM 
           @Level n
       JOIN 
           cte on n.ParentID = cte.ID
     )
     SELECT * FROM cte  
  </code></pre>
  
  <p>Result from above query:</p>
  
  <pre><code>ID          ParentID    Name    Path                         Level
  ----------- ----------- ------- ---------------------------- -----------
  1           0           AAAA    AAAA                         1
  2           1           BBBB    AAAA/BBBB                    2
  3           2           CCCC    AAAA/BBBB/CCCC               3
  4           3           DDDD    AAAA/BBBB/CCCC/DDDD          4
  5           4           EEEE    AAAA/BBBB/CCCC/DDDD/EEEE     5
  </code></pre>
  
  <p>Required output from the CTE query:</p>
  
  <pre><code>ID          ParentID    Name   Paths                        Path                         Level
  ----------- ----------- ----------------------------------- ---------------------------- -----------
  1           0           AAAA   AAAA                         AAAA                         1
  2           1           BBBB   AAAA/BBBB                    AAAA/BBBB                    2
  3           2           CCCC   AAAA/.../CCCC                AAAA/BBBB/CCCC               3
  4           3           DDDD   AAAA/.../.../DDDD            AAAA/BBBB/CCCC/DDDD          4
  5           4           EEEE   AAAA/.../.../.../EEEE        AAAA/BBBB/CCCC/DDDD/EEEE     5
  </code></pre>
  
  <p>As seen from the example above, the path can get quite long and would rather have the path replaced with dots. With the exception that the start and end characters remain visible and only the middle contents replaced. Please note that the contents of VALUES can be anything this is just used as an example.</p>
  
  <p>Thanks </p>