473,574 Members | 11,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need Recursive query structre that can .....

1 New Member
I am trying to write a product-row material cost program. Every product consists of row materials. When I sum up cost of row materials of each product I can find cost of products. But when the row material of the a product is a row material again the my solution does not work.

My table is like that:

Product Row material
p1 r1
p1 r2
p1 r3
p2 r4
p2 p1

I have another table that has costs of row materials.

My query computes the cost of p1 but does not compute the cost of p2 since not knowing the cost of p1. I need a recursive structure that can compute cost of p2.
Jul 25 '06 #1
1 4364
1,418 Recognized Expert Top Contributor
Imagine that information is saved in my_table
Product Row material
p1 r1
p1 r2
p1 r3
p2 r4
p2 p1

For exemple you want to get the row material for p2 in rows, result like this:

p2 r1
p2 r2
p2 r3
p2 r4
p2 p1

In one query, without using code it seem quite difficult...

But if it's an important thing for you You can do the follow:

1. Create a table with those Product, Row_material, My_Flags! Save it As My_Results
2. Create an append query that appends those
p2 r4
p2 p1
in your table

3. Create the folloing function in module in Access Basic:

Function check_for_produ cts()
dim i

If isnull(dcount(" Product","My_Re sults","((Row_m aterial) IN (Select Distinct [Product] FROM my_table))")) then exit function

docmd.Runsql "UPDATE My_Results SET My_Flags = True WHERE ((Row_material) IN (Select Distinct [Product] FROM my_table));"

docmd.Runsql "APPEND INTO My_Results (Product, Row_material, My_Flags) SELECT Product, Row_material, False AS Expr1 FROM my_table
WHERE ((Product) IN (Select Distinct [Row_material] FROM My_Results WHERE My_Flags=True)) ;"

docmd.Runsql "DELETE FROM My_Results WHERE My_Flags=True;"

i=check_for_pro ducts()
End function

It's all!
Sep 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: replace-this-with-my-name | last post by:
Hi. How do I return a string containing an entire menu-tree from a recursive function? Here is my current recursive function: function page_tree( $_i ){ //Call global mysql connection variable
by: Jim Geissman | last post by:
Help, please. I am trying to update a table with this structre: CREATE TABLE Queue (PropID int, EffDate smalldatetime, TxnAmt int) INSERT Queue (PropID) SELECT 1 INSERT Queue (PropID) SELECT 2 INSERT Queue (PropID) SELECT 3
by: Steven Burn | last post by:
..:: The Specs: MS Access 2000 (host charges extra for SQL/MySQL) MS Windows Server 2003 (prod) / MS XP SP1 (dev) ..:: The setup: The database has been setup with two tables; tblDownloads
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work for multiple companies and work for multiple divisions within each company. Within each division he can work in multiple departments and within each...
by: annecarterfredi | last post by:
query the syscat.columns table and prepare SELECT statement (SELECT all_columns FROM table_name). For example, let's say that TAB_1 table has total of three columns, and the statement should be: SELECT COL1, COL2, COL3 FROM TABSCHEMA.TAB_1 for all tables in syscat.columns I am not able to comeup with that query...need help...Thanks.
by: David | last post by:
Hi all, I have a singleton ienumerable that collects data from a database. I have listed the code below. It has the usual methods of current, move and reset. I need to go to a certain position or set filters or many other things and I don't know how to do this. I have just learned singleton AND ienumerable, so miraculously got this to...
by: zaina | last post by:
hi everybody i am nwebie in this forum but i think it is useful for me and the member are helpful my project is about connecting client with the server to start exchanging messages between them. to be more clear we process this purpose we serve this to the student in the university. how?? student will send a message that contains his...
by: NatRoger | last post by:
Hi, We are using DB2 V7 (MVS) in our shop, which dont have the luxury of the 'WITH clause' - CTE support to accomplish recursive queries. Here is my problem - Table1 From-ID To-ID A1 M1 - Member A1's id changes to M1 M1 D1 - M1 changes to D1
by: Jim Devenish | last post by:
I have a table named StockItems with field: StockItemID QuantityInStock I am creating assemblies of stock items and have another table named StockItemAssemblies with fields: StockItemAssemblyID AssemblyID StockItemID Quantity
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.