In my case, the query is generated to export data for one report into another system. It won’t repeat and the next query will look totally different. Creating a view won’t help me here. Stored procedures and functions won’t do either.

 

I will share a little more detail for my use case.

My query runs on a huge database with many patients. First, I am declaring and filling a table with patient id and case id which will be used later to restrict data to relevant cases. Just like in the final select, I can’t retrieve any data from this table either.

In the next step, data is selected from different tables and stored in the @results table as mentioned in my first post. Here I am joining the patient id table since the patient id and case id are the only keys working on (almost) all tables.

Finally, everything from @result is selected and handled by the IRIS.

Everything works fine unless I am using a temporary table in my query. I used a simple version for debugging avoiding the temp table, which worked, but this won’t do for the final version.