Is it possible to have temp tables in a function?

前端 未结 2 635
刺人心
刺人心 2021-01-03 22:15

Apparently, I can\'t use them. I\'m getting an error message like:

Invalid use of a side-effecting operator \'SELECT\' within a function

相关标签:
2条回答
  • 2021-01-03 22:26

    You can also do it with a CTE. See the template browser in SSMS. IntelliSense confuses the issue and will show an error until you complete the CTE and the following insert/select, but it will work.

    0 讨论(0)
  • 2021-01-03 22:27

    No, per this thread where the same question was asked, you cannot, but you can use a table variable

    DECLARE @MyTempTableVariable TABLE (SCHEMA)
    
    INSERT INTO @MyTempTableVariable
    SELECT bleh
    FROM bleh
    
    0 讨论(0)
提交回复
热议问题