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)
 A Variation on Recursive Searches

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-03-25 : 07:27:30
Jon writes "I was thrilled to find an easy example (http://4guysfromrolla.com/webtech/sqlguru/q120899-1.shtml) of how to use T-SQL to perform recursive searches as I'd been trying to automate a manual process using SQL. Unfortunately, the data I am trying to recurse through has an odd table structure.

Let's say I am trying to explode out a listing of every component that makes up a piece of equipment, but the table structure is laid out as so:

Equipment Number = the equipment to be exploded

Component Number = the components within the equipment

Where Used Equipment Number = the equipment to be exploded (same as "Equipment Number")

As you can see this is an odd layout; inputting an equipment number would yield the following output

Equipment_Number Component Number Where Used Equip. #
---------------- ---------------- ------------------
Can of Coke
Can of Coke Sugar Solution Can of Coke
Can of Coke Caffeine Can of Coke
Can of Coke Coloring Can of Coke
Can of Coke Aluminum Can Can of Coke


We then want to further explode the components within the Can of Coke as these components are further made up of other components and the output would be:


Equipment Number Component Number Where Used Equip. #
---------------- ---------------- ------------------
Sugar Solution
Sugar Solution Water Sugar Solution
Sugar Solution Sugar Sugar Solution


As you can see, the table structure does not easily lend itself to a recursive search as the list of exploded items ("Component Number") does not include the original Equipment Number upon which you are searching. Is it possible with this table structure to do a recursive search and explode out all components of an item (and all components of components).""

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-03-25 : 08:47:23
If you do this:
Post the DDL (script out the table and post the code)
Post sample data (create insert statements with sample data)

You'll get some answers quick.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -