;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.



 SELECT *,
                         MAX(cashoutMaxAmt) cashoutMaxAmt, 
                         product.prodKey AS prodKey, 
                         UNIX_TIMESTAMP(product.lastModifiedTs) AS lastModifiedTs,
                         product.comment AS prodComment,
                         productGeneral.comment AS condComment FROM product, productCondition, productLockTerm, productGeneral LEFT JOIN productPropertyUse  ON (productGeneral.prodGeneralKey=productPropertyUse.prodGeneralKey) LEFT JOIN productPrepay       ON (productGeneral.prodGeneralKey=productPrepay.prodGeneralKey) LEFT JOIN productLoanPurpose  ON (productGeneral.prodGeneralKey=productLoanPurpose.prodGeneralKey) LEFT JOIN productDocLevel     ON (productGeneral.prodGeneralKey=productDocLevel.prodGeneralKey) LEFT JOIN productPropertyType ON (productGeneral.prodGeneralKey=productPropertyType.prodGeneralKey) LEFT JOIN productState        ON (productGeneral.prodGeneralKey=productState.prodGeneralKey) LEFT JOIN productMortgageLate AS mortgageLate0  ON (productGeneral.mortLateKey  =mortgageLate0.prodMortLateKey) LEFT JOIN productMortgageLate AS mortgageLate12 ON (productGeneral.mortLate12Key=mortgageLate12.prodMortLateKey) LEFT JOIN productMortgageLate AS mortgageLate24 ON (productGeneral.mortLate24Key=mortgageLate24.prodMortLateKey) WHERE product.prodKey = productLockTerm.prodKey  AND product.prodKey = productCondition.prodKey  AND productGeneral.prodGeneralKey = productCondition.prodGeneralKey  AND lockTerm = 'B30'  AND productGeneral.disable = 'E'  AND product.disable = 'E'  AND productLockTerm .disable = 'E'  AND lienPri = '1' AND exception='YES' AND ((loanAmtFrom=0       AND loanAmtTo=0)     ||      (loanAmtFrom IS NULL AND loanAmtTo IS NULL) ||  (loanAmtTo >= '400000' AND loanAmtFrom <= '400000')) AND ((ltvFromPct=0        AND ltvToPct=0)      || (ltvFromPct IS NULL AND ltvToPct IS NULL) || (ltvToPct >= '80.000'      AND ltvFromPct <= '80.000')) AND ((cltvFromPct=0       AND cltvToPct=0) || (cltvFromPct IS NULL AND cltvToPct IS NULL) || (cltvToPct >= '100.000'    AND cltvFromPct <= '100.000')) AND ((crdscrFrom=0        AND crdscrTo=0)      || (crdscrFrom IS NULL AND crdscrTo IS NULL) || (crdscrTo >= '720'   AND crdscrFrom <= '720')) AND ((totalLienMinAmt=0   AND totalLienMaxAmt=0) || (totalLienMinAmt IS NULL AND totalLienMaxAmt IS NULL) || (totalLienMaxAmt  >= '400000' AND totalLienMinAmt  <= '400000')) AND ((secondaryFinance='NO' AND '80.000'='100.000' )  || (secondaryFinance='YES' AND ((maxLtvSecondary >='80.000')     || ((maxLtvSecondary IS NULL || maxLtvSecondary=0 || '80.000'='100.000') ) )))  AND ((frontRatioPct=0) || (frontRatioPct IS NULL) || (frontRatioPct < '0.000')) AND ((backRatioPct=0) || (backRatioPct IS NULL) || (backRatioPct < '10.000')) AND ((impnd             ='NA') || (impnd              ='BOTH') || (impnd = 'YES')) AND ((mortIns           ='NA') || (mortIns            ='BOTH') || (mortIns = 'NO')) AND ((frgnNatl          ='NA') || (frgnNatl           ='BOTH') || (frgnNatl = 'NO')) AND (intOnly = 'NO') AND ((propUseApl ='NO') || (propUseApl ='YES' AND propUse  = 'PRIM')) AND ((propTypeApl='NO') || (propTypeApl='YES' AND (propType = 'DETACH') )) AND ((loanPurpApl='NO') || (loanPurpApl='YES' AND loanPurp = 'P')) AND ((docLevelApl='NO') || (docLevelApl='YES' AND docLevel = 'AF')) AND ((stateApl   ='NO') || (stateApl   ='YES' AND state    = 'UT')) AND mortgageLate0.mortLate30 >= '0' AND mortgageLate0.mortLate60 >= '0' AND mortgageLate0.mortLate90 >= '0' AND mortgageLate12.mortLate30 >= '0' AND mortgageLate12.mortLate60 >= '0' AND mortgageLate12.mortLate90 >= '0' AND ((prepayApl  ='NO') || (prepay='P0')) AND prodCat = '14' GROUP BY product.prodKey, prepay ORDER BY prodCode ASC
