SELECT ; Plaintf_ID, File_ID, Lastname, Firstname, Partner, Our_FileNo, Plain_Defn, ; ( SELECT File_ID FROM PartFile WHERE PartFile.Plaintf_ID = ???a AND PartFile.Settled = .T. AND ; NOT EMPTY(PartFile.Date_Fund) AND PartFile.Plain_Defn # ???b.Plain_Defn ) AS OtherSideFunded ; FROM PartFile ; WHERE Settled = .T. AND ; EMPTY(Date_Fund) AND ; EMPTY(Date_Closd) ; INTO CURSOR SettledNF READWRITE???a - how do I relate the Plaintf_ID in the outer part of the fields list to the subquery i.e. the subquery must only select records with the same Plaintf_ID
*** Step 1 *** * get the settled files that are not yet funded * Notes: * 1) for simplicity, call this cursor "SettledNF" which means Settled not funded * 2) add column HasOtherFunded to flag on 2nd step which ones have a funded, matching file * 3) add columns for other side File_Type just for checking as the "combined" files need checking SELECT ; Plaintf_ID, File_ID, Lastname, Firstname, Partner, Our_FileNo, Plain_Defn, File_Type, ; .F. AS HasOtherFunded, " " AS OtherFileType ; FROM PartFile ; WHERE Settled = .T. AND ; EMPTY(Date_Fund) AND ; EMPTY(Date_Closd) ; INTO CURSOR SettledNF READWRITE *** Step 2 *** * for a small data set, it is easier to just scan the above results looking for funded files that * match up with the one that is settled but not funded * Notes: * 1) file must be same plaintiff; omit self-join that file_ID not the same * 2) cannot have the same Plain_Defn i.e. plaintiff files only match with defense and visa versa SCAN STORE Plaintf_ID TO lnPlaintf_ID STORE File_ID TO lnFile_ID STORE Plain_Defn TO lcPlain_Defn STORE File_Type TO lcFile_Type SELECT ; File_Type ; FROM PartFile ; WHERE Partfile.Plaintf_ID == lnPlaintf_ID AND ; PartFile.File_ID # lnFile_ID AND ; NOT EMPTY(PartFile.Date_Fund) AND ; NOT PartFile.Plain_Defn == lcPlain_Defn AND ; ( PartFile.File_Type == lcFile_Type OR ; ( PartFile.File_Type == "C" AND lcFile_Type $ "BT" ) OR ; ( PartFile.File_Type $ "BT" AND lcFile_Type == "C" ) ); INTO ARRAY laOtherFiles * if nothing returned, no matching files, do nothing; if something returned, mark the record * that it has an "other side" funded file and insert the File_Type IF _Tally > 0 REPLACE ; HasOtherFunded WITH .T., ; OtherFileType WITH laOtherFiles[1] ENDIF ENDSCAN *** Step 3 *** * only want those that do not have a funded file on the "other side" of this file don't need all of the * columns so explicitly state; probably do not even need Plain_Defn or File_Type but leave in for now SELECT ; File_ID, Lastname, Firstname, Partner, Our_FileNo, Plain_Defn, File_Type ; FROM SettledNF ; WHERE HasOtherFunded = .F. ; ORDER BY Partner, Lastname, Firstname ; INTO CURSOR Results