title: Remove code-duplication in SQL query
body: <p>Is there a way to remove the multiple repetitions of:
  <code>LEFT([Id], PATINDEX('%[0-9]%', [Id]) - 1)</code>
  in the following query?</p>
  
  <pre><code>SELECT 
      ISNULL(LEFT([Id], PATINDEX('%[0-9]%', [Id]) - 1), 'Total'), 
      Count([Id]) 
  FROM [dbo].[Ids]
  GROUP BY ROLLUP(LEFT([Id], PATINDEX('%[0-9]%', [Id]) - 1))
  ORDER BY 
      GROUPING(LEFT([Id], PATINDEX('%[0-9]%', [Id]) - 1)), 
      COUNT([Id]) DESC,
      LEFT([Id], PATINDEX('%[0-9]%', [Id]) - 1)
  </code></pre>
  
  <p>Even though I have a specific exemple I'm hoping to find a generic solution to this problem.</p>