473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Need for a recursive query

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

I need to work out how many assemblies I have in stock from knowing
how many individual items are in stock and have the following query:

Select StockItemAssemblies.AssemblyID, Min(StockItems.QuantityInStock/
StockItemAssemblies.Quantity) As QuantityInStock
From StockItems Inner Join StockItemAssemblies On
StockItems.StockItemID = StockItemAssemblies.StockItemID
Group By StockItemAssemblies.AssemblyID

This works fine. Elsewhere in the program the QuantityInStock from
this query is used in place of the QuantityInStock in the StockItems
table when the item is an assembly. For an assembly the
QuantityInStock in the StockItems table is thus ignored.

However a component of an assembly could be another assembly.

How do I modify the query to properly include all sub-assemblies?
Jun 27 '08 #1
2 5493
On Mon, 14 Apr 2008 08:12:31 -0700 (PDT), Jim Devenish
<in***************@foobox.comwrote:

There is no support for recursive queries in Access SQL. You can put
the same table on a query more than once (once for parent, once for
child, once for grandchild etc), but that way you can only query
exactly N levels deep.

A few options I can think of:
* Write it using recursive VBA/DAO code.
* Port your database to sqlserver 2005; it has native (and elegant)
support for recursive queries.
* Use nested sets
(http://www.intelligententerprise.com/001020/celko.jhtml) which are
supported by any dbms.

-Tom.
>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

I need to work out how many assemblies I have in stock from knowing
how many individual items are in stock and have the following query:

Select StockItemAssemblies.AssemblyID, Min(StockItems.QuantityInStock/
StockItemAssemblies.Quantity) As QuantityInStock
From StockItems Inner Join StockItemAssemblies On
StockItems.StockItemID = StockItemAssemblies.StockItemID
Group By StockItemAssemblies.AssemblyID

This works fine. Elsewhere in the program the QuantityInStock from
this query is used in place of the QuantityInStock in the StockItems
table when the item is an assembly. For an assembly the
QuantityInStock in the StockItems table is thus ignored.

However a component of an assembly could be another assembly.

How do I modify the query to properly include all sub-assemblies?
Jun 27 '08 #2
On Apr 15, 3:20*am, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
On Mon, 14 Apr 2008 08:12:31 -0700 (PDT), Jim Devenish

<internet.shopp...@foobox.comwrote:

There is no support for recursive queries in Access SQL. You can put
the same table on a query more than once (once for parent, once for
child, once for grandchild etc), but that way you can only query
exactly N levels deep.

A few options I can think of:
* Write it using recursive VBA/DAO code.
* Port your database to sqlserver 2005; it has native (and elegant)
support for recursive queries.
* Use nested sets
(http://www.intelligententerprise.com/001020/celko.jhtml) which are
supported by any dbms.

-Tom.
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
I need to work out how many assemblies I have in stock from knowing
how many individual items are in stock and have the following query:
Select StockItemAssemblies.AssemblyID, Min(StockItems.QuantityInStock/
StockItemAssemblies.Quantity) As QuantityInStock
From StockItems Inner Join StockItemAssemblies On
StockItems.StockItemID = StockItemAssemblies.StockItemID
Group By StockItemAssemblies.AssemblyID
This works fine. *Elsewhere in the program the QuantityInStock from
this query is used in place of the QuantityInStock in the StockItems
table when the item is an assembly. For an assembly the
QuantityInStock in the StockItems table is thus ignored.
However a component of an assembly could be another assembly.
How do I modify the query to properly include all sub-assemblies?
Thanks Tom. It is helpful to learn that it cannot be done in Access
SQL. It will stop me beating myself up. I will do it in VBA then.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
2
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
3
by: Dennis Haney | last post by:
Hi As far as I can tell, the pull_up_IN_clauses does not optimize recursively. Am I totally misguided here? Index: plan/subselect.c...
1
by: ozcanseker | last post by:
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...
8
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: ...
13
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...
6
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...
3
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 ...
3
by: srinit | last post by:
hi i have a table like col1 col2 col3 col4 35 R 0 0 36 W 1 35 37 R 0 0 38 W 2 35,36 I am giving...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.