Select 
IP.Contract
,IP.Part_No Child
,IP.Description Child_Description
,MS2.Part_No
,P.Description Parent_Description

,IP.TYPE_CODE
,IP.PART_STATUS
,MS.Freq


From Inventory_Part_cfv IP inner join INVENTORY_PART_CHAR_ALL C on IP.Part_No=C.Part_No and IP.Contract=C.Contract
inner join 

(Select Contract,COMPONENT_PART, count(COMPONENT_PART) Freq from MANUF_STRUCTURE MS where MANUF_STRUCT_ALTERNATE_API.Get_State(Ms.contract,MS.part_no,MS.eng_chg_level,MS.bom_type,MS.alternative_no)='Buildable' and MS.EFF_PHASE_OUT_DATE is null and alternative_no='*' group by Contract,Component_Part having count(COMPONENT_PART)>=2) MS on MS.COMPONENT_PART=IP.Part_No and MS.Contract=IP.Contract

inner join MANUF_STRUCTURE MS2 on MS2.COMPONENT_PART=IP.Part_No and MS2.Contract=IP.Contract
inner join Part_Catalog P on MS2.Part_No=P.Part_No

where  C.CHARACTERISTIC_CODE='00006' and C.ATTR_VALUE_ALPHA in ('IML','PAPET INSERT','HEAT TRANSFER')
and MANUF_STRUCT_ALTERNATE_API.Get_State(Ms2.contract,MS2.part_no,MS2.eng_chg_level,MS2.bom_type,MS2.alternative_no)='Buildable' and MS2.EFF_PHASE_OUT_DATE is null and MS2.alternative_no='*' and IP.Part_No not in ('1011502','1011501')

Order by IP.Contract
,IP.Part_No
,MS2.Part_No