title: Can we have dynamic group by clause in sql server?
body: <p>I have one stored procedure...which has one parameter: <code>@subCustName</code>.
  This stored proc has one select statement with <code>group by custName, subCustName</code></p>
  
  <p>Ex:</p>
  
  <pre><code>SELECT custName, subCustName,sum(membership)
  FROM CUSTOMER_TABLE
  GROUP BY
  custName, subCustName
  </code></pre>
  
  <p>If parameter <code>@subCustName</code> is <code>'ALL'</code>, I dont want to group by subCustName.</p>
  
  <p>How do I acheve that ?</p>
  
  <p>Thanks in advance!</p>