Hello,
I have 1 table which contains asset information.
An asset can be linked to 1 other asset making one the assets a master asset and the other the component asset.
A master asset can be linked to another master asset.
I now want to create a SQL statement which shows me the hierarchy of assets.
I have the following statement:
This gives me this result:
MasterNumber | MasterDesc | ComonentNumber | ComponentDesc
SIT-0003 | site | CAM-0001 | cam1
SIT-0003 | site | RIG-0002 | rig
RIG-0002 | rig | CAM-0002 | cam2
The result I'd like to see shows the hierarchy of assets.
MasterNumber | MasterDesc | ComonentNumber | ComponentDesc
SIT-0003 | site | CAM-0001 | cam1
SIT-0003 | site | RIG-0002 | rig
----- | ------- | CAM-0002 | cam2
All assets have SIT-0003 as the master asset. They are linked to it either directly (CAM-0001 and RIG-0002) or they are linked to it through another asset (CAM-0002 is linked to SIT-0003 through RIG-0002)
Would anyone be able to tell me whether I can achieve this with SQL and how I have to alter my querry?
Any help much appreciated.
I have 1 table which contains asset information.
An asset can be linked to 1 other asset making one the assets a master asset and the other the component asset.
A master asset can be linked to another master asset.
I now want to create a SQL statement which shows me the hierarchy of assets.
I have the following statement:
Code:
SELECT "AMASST"."MSTNO" as MasterNumber, "AMASST_1"."DESC" as MasterDesc, "AMASST"."ASTNO" as ComponentNumber, "AMASST"."DESC" AS ComponentDesc
FROM "cap100"."dbo"."AMASST" "AMASST" INNER JOIN "cap100"."dbo"."AMASST" "AMASST_1" ON "AMASST"."MSTNO"="AMASST_1"."ASTNO"
This gives me this result:
MasterNumber | MasterDesc | ComonentNumber | ComponentDesc
SIT-0003 | site | CAM-0001 | cam1
SIT-0003 | site | RIG-0002 | rig
RIG-0002 | rig | CAM-0002 | cam2
The result I'd like to see shows the hierarchy of assets.
MasterNumber | MasterDesc | ComonentNumber | ComponentDesc
SIT-0003 | site | CAM-0001 | cam1
SIT-0003 | site | RIG-0002 | rig
----- | ------- | CAM-0002 | cam2
All assets have SIT-0003 as the master asset. They are linked to it either directly (CAM-0001 and RIG-0002) or they are linked to it through another asset (CAM-0002 is linked to SIT-0003 through RIG-0002)
Would anyone be able to tell me whether I can achieve this with SQL and how I have to alter my querry?
Any help much appreciated.