tags:

views:

24

answers:

1

I've got to write 50 relatively simple queries, that all use the same basic form, but each successive query depends on the one before it to run.

I can quick and easily write the queries in SQL in an text editor e.g. word, but I dont know how to import the text back into access. Nor do I know how to specify the name of the query in the SQL code or how to specify that the end of a query has been readched.

Here is a sample of 4 queries. Here, the 1st line is the name of the Query and the two consecutive hard return represents the end of eqch query.

‘Ring2Q1 SELECT RINGS.Parent, RINGS_1.Child, 2 AS Ring FROM RINGS INNER JOIN RINGS AS RINGS_1 ON RINGS.Child = RINGS_1.Parent;

‘Ring2Q2 SELECT Ring2Q1.Parent, Ring2Q1.Child, Max(Ring2Q1.Ring) AS Ring FROM Ring2Q1 GROUP BY Ring2Q1.Parent, Ring2Q1.Child;

‘Ring3Q1 SELECT RINGS.Parent, Ring2Q2.Child, 3 AS Ring FROM RINGS INNER JOIN Ring2Q2 ON RINGS.Child = Ring2Q2.Parent;

‘Ring3Q2 SELECT Ring3Q1.Parent, Ring3Q1.Child, Max(Ring3Q1.Ring) AS Ring FROM Ring3Q1 GROUP BY Ring3Q1.Parent, Ring3Q1.Child;

+1  A: 

Go into Access. Create a new query. Select SQL View. You can copy and paste the text of the query in here. Save it as the name you need for the next query. Repeat. You will obviously need a starting table that the first query calls. I would look at why you need a cascading set of 50 queries, on any sizeable amount of data this is going to take a long time to run.

David
Thanks. The process you outlined is exactly the process I was using. Just trying to find a way to create them all at once. Once all of the queries are run, we plan to make a table showing all of the rings at all of the levels, i.e. concatenating the results from Ring2Q2 to Ring3Q2 etc. The queries would be run only one time. The final table would then serve as a lookup of children at any particular level; e.g. give me all of the children within 29 rings of cell 219.
Marcus
Not sure exactly what you are trying to do. But it sounds like a crosstab query might be something to look at
David