I need to return a parent child relationship from 3 tables which are for bottom, mid and top level respectively. Easy stuff so far, and done already:
SELECT -1 ParentID, ID + 100000 ID, txtName Value from tblLevel1
UNION
SELECT Level1ID + 100000 ParentID, ID + 50000 ID, txtName Value from tblLevel2
UNION
SELECT Level2ID + 50000 ParentID, ID ID, txtName Value from tblLevel3
My problem is that I need to add another field that describes the path of each entry.
For the first table, it is '-1;{id}).
For the second table is is '{Level1id};{id}'.
The third table's query should return '{Level1id};{Level2id};{id}'. The problem is the third one then.
The table structures are:
Level1; ID int; txtName varchar(50)
Level2; ID int; Level1ID int; txtName varchar(50)
Level3; ID int; Level2ID int; txtName varchar(50)
How do I get the full path in the query on the 3rd table (Level3)?
This is the current result
ParentID ID Value
-1 100001 Test company
-1 100006 Company A
-1 100007 Company B
-1 100008 The Primary Client
-1 100009 Overseas Client 1
100001 50001 Distribution
100006 50016 Attributes
100007 50018 Attributes
100008 50019 Development
100009 50029 Database
50001 1 Balance Sheet
50001 7 Cash Flow Statement
50001 10 Income Statement
50016 20 Vehicles
50016 21 Drivers
50019 33 Health
50029 29 Database