I am doing a select within a SQL Server stored procedure. This select returns the results to the caller, which is what I need, but I also need to use one of the fields from the select in the rest of the stored procedure.
Right now, I am doing the select as normal. Then I create a temporary table, and re-do the same select again, but I insert the results into the temporary table. Is there a better way to do this?
For context, I am essentially pulling a tree out of a database. There are many one-to-many tables, and I am using the ids that I get from one level to pull out the next level.