I'm working on a report that is in picbasic(yippee) and converting it to .NET. The tables are all pulled from unibasic tables to sql tables. The report is suppose to look like the example below or similar. The table(only showing a portion of data to keep it simple) has the ParentID(ID which can have many to start) and the ChildID(which ties to the next parentId if there is one) and basically joins until there isn't a ChildID available(NULL). I wrote a procedure which I thought would run fine, but sits and doesn't return any type of results. SQL is not my strong point. As you can see the Starting number(part#) is SA33028 and there are 8 parts underneath it and then those parts may have component parts and so on, so forth.
0......... SA330281........42S01311........5S01271........6S01751........ SA330232.......16S01422.......18S01032.......24S01082.......28SM01052....... S30461.AI2....... S304633...... S288073...... S288072....... S306412....... S311342....... S93832....... SA298013......16S01163...... S277983...... S311703...... SA300594.....38S01164.....7S01054..... S19430.1455....7SM01456...7SM0145.0016...7SM0145.0025.... S194304..... S194312....... SA30910
Data:
SA33023 | 16S0142 |
SA33023 | 18S0103 |
SA33023 | 24S0108 |
SA33023 | 28SM0105 |
SA33023 | S30461.AI |
SA33023 | S30463 |
S30463 | S28807 |
S30463 | S28807 |
SA33023 | S30641 |
SA33023 | S31134 |
SA33023 | S9383 |
SA33023 | SA29801 |
SA29801 | 16S0116 |
SA29801 | S27798 |
SA29801 | S31170 |
SA29801 | SA30059 |
SA30059 | 38S0116 |
SA30059 | 7S0105 |
SA30059 | S19430.145 |
S19430.145 | 7SM0145 |
7SM0145 | 7SM0145.001 |
7SM0145 | 7SM0145.002 |
S19430.145 | S19430 |
SA30059 | S19431 |
SA33023 | SA30910 |
SQL:
WITH AllParts AS ( SELECT 1 AS Level, Child.Parent_Part, Child.Component_Part FROM ps as Child WHERE Parent_Part = 'SA33028' UNION ALL SELECT ap.Level + 1, TempPS.Parent_Part, TempPS.Component_Part FROM ps AS TempPS INNER JOIN AllParts AS ap ON TempPS.Parent_Part = ap.Component_Part ) SELECT * FROM Allparts END