Apparently, I can't use them. I'm getting an error message like:
Invalid use of a side-effecting operator 'SELECT' within a function
If I want to do something like this:
select bleh into #temp from Blah
... inside a function.
When we query the TempPersonTable, it will return an empty result set. After creating the table, we can insert data into it as the persisted tables. At the same time, we can create a temporary table using the SQL SELECT INTO statement command.
You can create a table for the duration of the function by declaring it as a variable. We use the following code within a function to determine what date the last occurrence of a certain Cycle was.
No, a view consists of a single SELECT statement. You cannot create or drop tables in a view. Maybe a common table expression (CTE) can solve your problem. CTEs are temporary result sets that are defined within the execution scope of a single statement and they can be used in views.
You cannot create and drop the #TEMP table within the CTE query.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With