SELECT DISTINCT A.OPRID , A.SETID , D.PRODUCT_ID , D.DESCR , 0 , 0 , ' ' FROM PS_TD_SETID_TBL C , PS_TD_TREE_NODE_VW A , PS_PROD_ITEM D WHERE A.SETID = ( SELECT S.SETID FROM PS_SET_CNTRL_REC S WHERE S.SETCNTRLVALUE = C.SETID AND S.RECNAME = 'PROD_ITEM') AND A.TD_TREE_ID = C.TD_TREE_ID_PROD AND A.EFFDT = ( SELECT MAX(A_ED.EFFDT) FROM PS_TD_TREE_NODE_VW A_ED WHERE A.SETID = A_ED.SETID AND A.TD_TREE_ID = A_ED.TD_TREE_ID AND A_ED.EFFDT <= %CurrentDateIn ) AND D.SETID = A.SETID AND A.PRODUCT_ID = D.PRODUCT_ID UNION ALL SELECT DISTINCT A.OPRID , A.SETID , D.PRODUCT_ID , D.DESCR , 0 , 0 , ' ' FROM PS_TD_SETID_TBL C , PS_TD_TREE_NODE_VW A , PS_PROD_ITEM D WHERE A.SETID = ( SELECT S.SETID FROM PS_SET_CNTRL_REC S WHERE S.SETCNTRLVALUE = C.SETID AND S.RECNAME = 'PROD_ITEM') AND A.TD_TREE_ID = C.TD_TREE_ID_PROD AND A.EFFDT = ( SELECT MAX(A_ED.EFFDT) FROM PS_TD_TREE_NODE_VW A_ED WHERE A.SETID = A_ED.SETID AND A.TD_TREE_ID = A_ED.TD_TREE_ID AND A_ED.EFFDT <= %CurrentDateIn) AND D.SETID = A.SETID AND A.PRODUCT_ID = D.PRODUCT_ID
|