Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Hierarchies

Author  Topic 

acko
Yak Posting Veteran

52 Posts

Posted - 2003-07-25 : 09:00:07
Hello everybody
Here is my problem
I have two tables.
First is Products and second is ProductsPart.
Products:
CREATE TABLE [Products]
(
[ID] [char] (16),
[NAME] [char] (40)
)
ProductsPart:
CREATE TABLE [ProductsPart]
(
[ID] [char] (16),
[IDPOD] [char] (16),
[QUANTITY] [smallint]
)
All products are in the products table.
Some of products are made of the other products which are also in the products table. From which products the product is made you know with ProductsPart table because IDPOD field shows product from which is made product which ID is ID.

Let's say that Product1 is made from Product2 and Product3
If I want to see from which product Product1 is made I will write this query:

SELECT P.ID, P.NAME
FROM Products P JOIN ProductsPart PP
ON P.ID = PP.IDPOD
WHERE PP.ID = 'Product1'

I will get this results:
ID2 Product2
ID3 Product3


But what if the Product3 is made of the others products(Product4, Product5) and so on...(Product4 = Product6 + Product7)...
How can I make query get this results?
ID2 Product2
ID3 Product3
ID4 Product4
ID6 Product6
ID7 Product7
ID5 Product5

Thanks very much
Alex




X002548
Not Just a Number

15586 Posts

Posted - 2003-07-25 : 09:46:21
Got to the home page and look up More trees and hierarchies...

What happens if a Product is not made up of any other products?

Also how many levels deep do you go?

Are the Products entered through OLTP or are they append in BATCH?



Brett

8-)
Go to Top of Page

acko
Yak Posting Veteran

52 Posts

Posted - 2003-07-25 : 10:21:03
Thanks very much

quote:

Got to the home page and look up More trees and hierarchies...

What happens if a Product is not made up of any other products?

Also how many levels deep do you go?

Are the Products entered through OLTP or are they append in BATCH?



Brett

8-)



Go to Top of Page
   

- Advertisement -