I have a complicated query that select parts from an MRP table using several different criteria. The output of the query is a list of parts which includes the key field [PartNum]. I have saved this query to a file, for example let's says "MyQuery.sql".
I want to use the output of that query in another query, something like "SELECT * FROM [MyQuery] JOIN [part_stock] on [part_stock].[PartNum] = [MyQuery].[PartNum]". The idea is that I have this rather complicated selection criteria for extracting a list of parts from the database. I then want to run other queries on just those selected part numbers. I could just copy all the statements from the original query into the new queries, but that would make them overly complicated. Also, I may want to change the selection criteria for the parts, and I would prefer to only change it in one file and then just re-execute all the queries that use that list.
I realize that I could use the first query to create a table in the DB, and then have the other queries reference that table. But this is a live MPR system and I don't want to alter the DB schema (especially since I don't have much experience with SQL).
How can I use the output from one query file as the input to another query? If that's not possible, is there another way to accomplish this task without creating a table in the DB?