Hi ,
I have 3 tables called product , CMF and global_open_item_id . I need to fetch the products which has mismatch in open_item_id by joining both the poduct and the global_open_item_id table.
The Global_open_Item_id _maptable contains info on the open_item_id for each product. It has two rows one default row with the charge_element_type and charge_element_value=0 and another
row with the charge_element_type=1 and charge_element_value=<elem
ent_id>. The query should pick the default open_item_id if the charge_element_type and charge_element_value does not match a given product , else the matching row open_item_id .
Below is the query i have written to fetch the products with
Select P.element_id , p.Open_item_id , g.open_item_id mismatchid
From Product p,
CMF c ,
Global_open_item_id_map g
Where c.account_no=p.parent_acco
unt_no
and g.charge_element_type in (0,1)
and g.charge_element_value in (0, p.element_id)
and g.state=decode(c.cust_stat
e , 'NH',30,'VT',46,'ME',20);
and g.open_item_id <> p.open_item_id
The Expected output should be as below :
element_id open_item_id mismatchid
10001792 143 145
The structure of the CMF table is
AccountNo Number(12)
Cust_state varchar2(3)
Data:
600003 ME
Also attached is the structure and data of Product and global_open_item_id table