Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SELECT SQL Help
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00552524
Message ID:
00552607
Vues:
16
>>I have two tables as follows:
>>
>>Table 1 has two fields, oecid and oecname. For example,
>>
>>MCOR1985..... 3M Corporation
>>ABBL1991..... ABB Lummus
>>BLAC2130..... Black & Veatch
>>
>>Table 2 has a multiple number of fields of which I am concerned with the following four: projectid, owner, engineer, and contractor. The owner, engineer, and contractor fields contain an 'oecid'.
>>
>>I want to be able to pull out the projectids whose owner,engineer or contractor 'oecid' matches an 'oecid' form Table 1. In addition, I would like to convert the 'oecid' in each of the owner, engineer, contractor fields to the corresponding 'oecname'.
>>
>>I hope this makes sense! Any suggestions would be greatly appreciated.
>>
>>Thanks in advance for your help,
>>Russell Clendenon
>
>Slightly different SQL, than Sergey's should do the job too (not tested):
>
>select Table2.*, Table1.OecName from Table2 inner join table1 on Table2.Owner=Table1.oecID ;
>union ;
>select Table2.*, Table1.OecName from Table2 inner join table1 on Table2.Engineer=Table1.oecID ;
>union ;
>select Table2.*, Table1.OecName from Table2 inner join table1 on Table2.Contractor=Table1.oecID ;
>into table EverybodyWithDescr
Actually it'll create three records per projectid not one. If that's the goal than
select Table2.projid, Table1.OecName As name, "O" AS recordtype ;
  from Table2 inner join table1 on Table2.Owner=Table1.oecID ;
union ;
select Table2.projid, Table1.OecName As name, "E" AS recordtype ;
  from Table2 inner join table1 on Table2.Engineer=Table1.oecID ;
union ;
select Table2.projid, Table1.OecName As name, "C" AS recordtype ;
  from Table2 inner join table1 on Table2.Contractor=Table1.oecID ;
into table EverybodyWithDescr
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform