SELECT A.QRYNAME , A.DESCR FROM PSQRYDEFN A INNER JOIN ( SELECT B.QRYNAME FROM PSQRYFIELD B INNER JOIN PSQRYSELECT K ON B.QRYNAME = K.QRYNAME AND B.SELNUM = K.SELNUM WHERE B.COLUMNNUM > 0 AND K.PARENTSELNUM = 0 GROUP BY B.QRYNAME HAVING COUNT(1) = 1) B ON A.QRYNAME = B.QRYNAME WHERE A.QRYTYPE = 1 AND A.BNDCOUNT = 1 AND EXISTS ( SELECT 'X' FROM PSQRYBIND H WHERE H.QRYNAME = A.QRYNAME AND H.FIELDNAME = 'SCD_EVALUATION_ID') AND (EXISTS ( SELECT 'X' FROM PSQRYFIELD F INNER JOIN PSDBFIELD G ON F.FIELDNAME = G.FIELDNAME INNER JOIN PSQRYSELECT K ON F.QRYNAME = K.QRYNAME AND F.SELNUM = K.SELNUM WHERE F.QRYNAME = A.QRYNAME AND F.COLUMNNUM > 0 AND K.PARENTSELNUM = 0 AND G.FIELDTYPE IN (2, 3)) OR EXISTS ( SELECT 'X' FROM PSQRYEXPR P INNER JOIN PSQRYFIELD Q ON P.QRYNAME = Q.QRYNAME AND Q.FLDEXPNUM = P.EXPNUM WHERE P.QRYNAME = A.QRYNAME AND P.FIELDTYPE IN (2, 3)))
|