title: Cannot access temporary tables from within a function
body: <p>I would like to get count of specific records. So my query will look like the following...</p>
  
  <pre><code>SELECT
      ID, 
      NAME,
      (SELECT...) AS UserCount // Stmt1
  FROM MyTable
  </code></pre>
  
  <p>The issue is that, 'Stmt1' is a complex statement and it cannot be written as innerquery. 
  Well, I can use functions, but the statement includes 'CREATE TABLE' so I get the following error message</p>
  
  <p><strong><code>Cannot access temporary tables from within a function.</code></strong></p>
  
  <p>What is the best way to accomplish the task ?</p>