Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pre-filtering and inner joins
Message
De
27/03/2003 12:46:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00770813
Message ID:
00770849
Vues:
17
>I'm trying to get a filtered set of jobs with the customer's company and the job's address. The user can filter on various tables, so I decided to run the filters on each table individually to avoid having such huge temp cursors. This works except one problem. If there is a job that doesn't have any addresses, but the user isn't filtering on the address anyway, I still want to include it. But that doesn't work because the final query doesn't know the difference between a job that has no addresses period and a job that has no addresses that matched the filter.
>
>I simplified the code below as much as I could and still get across what I'm trying to do. Is there a better way to work that last query that will take into account the above situation?
>
>Thanks,
>
>Michelle
>
>
>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
>
Michelle,
Try :
LEFT JOIN tc_city ON jobs.jobno = tc_city.jobno
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform