rschultz
11-26-2001, 11:15 AM
I work with a couple people who do some programming in Access. They both have queries that reference other queries. To me it seems like spaghetti code. What's the scoop on that? Is it acceptable or bad form?
|
View Full Version : Querys referencing other Querys? rschultz 11-26-2001, 11:15 AM I work with a couple people who do some programming in Access. They both have queries that reference other queries. To me it seems like spaghetti code. What's the scoop on that? Is it acceptable or bad form? pcs 11-26-2001, 12:49 PM Is it acceptable?. most certainly! you can do some very powerful data manipulation with nested queries. al rschultz 11-26-2001, 01:04 PM hmmm, okay thanks. Any suggestions where I can get any ideas about them? pcs 11-26-2001, 02:28 PM visit the MS download site, and get a copy of Qrysmp97. (sample queries) lots of good ideas and tips... hth, al Pat Hartman 11-26-2001, 06:22 PM Rather than spaghetti code they are really a way of "modularizing" code and creating re-usable objects. Sometimes, they are the only way to get the data you need. Say you have three tables - Customer, Order, OrderItems and you want to create a query that shows Customer, TotalShippingCharges, and TotalOrderDollars. ShippingCharges are recorded in the Order table and ExtendedItemPrice is recorded in the OrderItems table. If you created a single query joining the three tables, you would grossly inflate the ShippingCharges figure because it would occur in the recordset too many times. You would first have to create a query that summed the ExtendedItemPrice by Order and then use that query in the join instead of OrderItems. rschultz 11-27-2001, 12:27 PM Pat: Thanks for the great explaination. pcs:I went to the Microsoft download page and searched for keywords "Qrysmp97" but I got no hits. Pat Hartman 11-27-2001, 06:56 PM All the sample db's are prefixed by the words "Access 97 sample". The direct link to the query sample is: http://support.microsoft.com/support/kb/articles/Q182/5/68.asp?FinishURL=%2Fdownloads%2Frelease%2Easp%3FRe leaseID%3D13426%26area%3Dsearch%26ordinal%3D37%26r edirect%3Dno rschultz 11-28-2001, 05:52 AM got it. Thanks The_Doc_Man 11-28-2001, 06:48 AM In regard to queries referencing other queries: Although there is probably an efficiency limit for this, it is a very modular way to save common filtration rules that you then can join with other queries to get detailed data about specific things. We sometimes have to select info from our table based on as many as 7 criteria. So we wrote a query to do the select and produce names. (Basically, we unchecked the "include" boxes in the query design view.) Now, when we have to do something using this list of complex criteria, we just write a JOIN of the main table to that query based on the selected item's name (names are unique keys in this case). We don't have to rewrite the complex query with so many criteria. And our action queries on these items are also very similar. I would vote for using queries based on other queries as being a good idea. |