title: SQL: Error, Expression services limit reached?
body: <p>"Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them."</p>
  
  <p>Has anyone seen this before and found a good workaround?</p>
  
  <p>I managed to get around this issue by splitting my SQL query into two parts essentially and writing the first SQL select query to a temp table  and the second part, a new SQL select statement selects from the temporary table and uses alot of CROSS APPLY operator to Calculate cascading computed columns.</p>
  
  <p>This is an example of how the second part looks but I'm using alot more Cross Applys to produce new columns which are calculations:</p>
  
  <pre><code>Select * from #tempTable        
  
  cross apply
      (
        select HmmLowestSalePrice =
         round(((OurSellingPrice + 1.5) / 0.95) - (CompetitorsLowestSalePrice) + 0.08, 2)
      ) as HmmLowestSalePrice 
  
  cross apply
      (
        select checkLowestSP =
         case 
          when adjust = 'No Room' then 'No Room'
          when OrginalTestSalePrice &gt;= CompetitorsLowestSalePrice then 'Minus'
          when OrginalTeslSalePrice &lt; CompetitorsLowestSalePrice then 'Ok'
        end
  ) as checkLowestSP  
  
  cross apply
      (
          select AdjustFinalNewTestSP =
          case
          when FinalNewTestShipping &lt; 0 Then  NewTestSalePrice - (FinalNewTestShipping)
          when FinalNewTestShipping &gt;= 0 Then NewTestSalePrice
          end
  ) as AdjustFinalNewTestSP
  
  cross apply
      (
        select CheckFinalSalePriceWithWP  =
        case 
          when round(NewAdminSalePrice, 2) &gt;= round(wholePrice, 2) then 'Ok'
  
          when round(NewAdminSalePrice, 2) &lt; round(wholePrice, 2) then 'Check'
        end
      ) as CheckFinalPriceWithWP 
  
  
  DROP TABLE #tempTable
  </code></pre>
  
  <p>My goal to to put this into a sql report and it work fine if there is 1 user only as the <code>#tempTable</code> will get created and dropped in the same execution and the results are displayed in the report correctly. But in the future if there are concurrent users I'm concerned that they will be writing to the same <code>#tempTable</code> which will affect the results? </p>
  
  <p>I've looked at putting this into stored procedures but still get the error message above.</p>