LPARAMETERS tcCompany, tcCity *-- Determine the customer filter IF NOT EMPTY(tcCompany) lcCustFilt = "company = " + tcCompany ELSE lcCustFilt = ".T." ENDIF *-- Get a cursor with all clients that fit the filter SELECT custno, company ; FROM customers ; INTO CURSOR tc_custs NOFILTER ; WHERE lcCustFilt *-- Determine the address filter IF NOT EMPTY(tcCity) lcCityFilt = "city = " + tcCity ELSE lcCityFilt = ".T." ENDIF *-- Get a cursor with all addresses that fit the filter SELECT city, state, jobno ; FROM addrs ; INTO CURSOR tc_city NOFILTER ; WHERE lcCityFilt *-- Join them with the main table SELECT jobno, custno, company, city, state ; FROM jobs ; INNER JOIN tc_custs ON jobs.custno = tc_custs.custno ; INNER JOIN tc_city ON jobs.jobno = tc_city.jobno