 <p>If you have multiple CTE's, they need to be at the beginning of your statement (comma-separated, and only one <code>;WITH</code> to start the list of CTE's):</p> <pre><code>;WITH CTE AS (......), [UserDefined] AS (.......) SELECT..... </code></pre> <p>and then you can use both (or even more than two) in your <code>SELECT</code> statement.</p>