SELECT OPR.OPRID , GPT.GDP_TEMPLATE_ID , GPT.GDP_LABEL FROM PS_GDP_TMPL_TBL GPT , PSOPRDEFN OPR WHERE GPT.GDP_ACTIVE_FLG = 'Y' AND EXISTS ( SELECT 'X' FROM PS_GDP_TMPL_PRIV PRL , PSROLEUSER ROL WHERE PRL.GDP_TEMPLATE_ID = GPT.GDP_TEMPLATE_ID AND PRL.GDP_MBR_TYPE = 'ROLE' AND PRL.GDP_MBR_NAME = ROL.ROLENAME AND ROL.ROLEUSER = OPR.OPRID AND PRL.GDP_PRIVSET_ID IN ('PTAI_CONTRIBUTOR', 'PTAI_ADMINISTRATOR')) AND EXISTS ( SELECT GPT1.GDP_TEMPLATE_ID FROM PS_GDP_TMPL_TBL GPT1 , PS_GDP_TMPL_CTX CTX1 WHERE GPT1.GDP_TEMPLATE_ID = GPT.GDP_TEMPLATE_ID AND GPT1.GDP_TEMPLATE_ID = CTX1.GDP_TEMPLATE_ID AND CTX1.FIELDNAME = 'OPRID' AND EXISTS ( SELECT COUNT(*) FROM PS_GDP_TMPL_TBL GPT2 , PS_GDP_TMPL_CTX CTX2 WHERE GPT2.GDP_TEMPLATE_ID = GPT1.GDP_TEMPLATE_ID AND GPT2.GDP_TEMPLATE_ID = CTX2.GDP_TEMPLATE_ID HAVING COUNT(*) = 1) )
|