Is it possible to have temp tables in a function? Is it possible to have temp tables in a function? sql sql

Is it possible to have temp tables in a function?


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 @MyTempTableVariableSELECT blehFROM bleh


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.