Using conditions to specify groups for GROUP BY <p>I'm not even sure if this is possible using SQL, but I'm completely stuck on this problem. I have a table like this: </p> <pre><code>Total Code 212 XXX_09_JUN 315 XXX_7_JUN 68 XXX_09_APR 140 XXX_AT_APR 729 XXX_AT_MAY </code></pre> <p>I need to sum the "total" column grouped by the code. The issue is that "XXX_09_JUN" and "XXX_7_JUN" and "XXX_09_APR" need to be the same group. </p> <p>I was able to accomplish this by creating a new column where I assigned values based on the row's code, but since this needs to be done on multiple tables with millions of entries, I can't use that method.</p> <p>Is there some way that I could group the rows based on a condition such as:</p> <pre><code>WHERE Code LIKE '%_09_%' OR Code LIKE '%_7_%' </code></pre> <p>This is not the only condition - I need about 10 conditions like this. Sorry if that doesn't make sense, I'm not sure how to explain this...</p> <p>Also, if this can be accomplished using Visual Studio 2008 and SSRS more easily, that would work as well because that is the final goal of this query.</p> <p>Edit: To clarify, this would be the ideal result:</p> <pre><code>Total Code 595 had_a_number 869 had_at </code></pre>