Cannot access temporary tables from within a function

前端 未结 4 1285
独厮守ぢ
独厮守ぢ 2020-12-18 18:52

I would like to get count of specific records. So my query will look like the following...

SELECT
    ID, 
    NAME,
    (SELECT...) AS UserCount // Stmt1
FR         


        
4条回答
  •  失恋的感觉
    2020-12-18 19:30

    I came across this post as I started using table variables and switched to temporary tables for performance reasons only to find temporary tables couldn't be used in a function.

    I would be hesitant about using table variables especially if you are playing with large result sets, as these are held in memory. See this post...

    http://totogamboa.com/2010/12/03/speed-matters-subquery-vs-table-variable-vs-temporary-table/

    Other alternatives would be..

    1. Extracting the temporary table result into another table function.
    2. Converting the code into using sub-queries

提交回复
热议问题