Using Temporary Tables in API - persistent connection?

In SQLserver I have a very large database, I have a lot of very complicated queries which are much simpler if first I create four or five temporary tables with only the fields I need

I am trying to make an API in Slim 4 Framework with those queries.

I have a solution, but I think that for each query the system has to recreate the temporary tables each time. If I set up a route to create the tables, then another route to query those tables says that it can´t find the table name.

I guess I have to use DI but I can’t understand how to set it up, can you help me?

Thanks, and forgive my bad English.