Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tricky sql selection
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00476778
Message ID:
00476874
Vues:
22
Here is my try:
select possid, max(posdate) as maxDate ;
  from position ;
  group by possid ;
  into cursor maxDate
select position.possid, position.posdate, position.posname ;
  from position, maxDate ;
  where position.possid = lv_maxDate.possid ;
    and position.posdate = lv_maxDate.maxDate ;
  into cursor currPos 
select active.actsid, active.actfname, active.actlname, ;
       currPos.possid, currPos.posname, currPos.posdate ;
  from active left outer join currPos ;
    on active.actsid = lv_currPos.possid ;
  order by active.actsid ;
  into cursor empPos
You can add the 3 selects as views into a database, let's say hrData:
open database hrData
create sql view lv_maxDate as ;
  select possid, max(posdate) as maxDate ;
    from position ;
    group by possid
create sql view lv_currPos as ;
  select position.possid, position.posdate, position.posname ;
    from position, lv_maxDate ;
    where position.possid = lv_maxDate.possid ;
      and position.posdate = lv_maxDate.maxDate
create sql view lv_empPos as ;
  select active.actsid, active.actfname, active.actlname, ;
         lv_currPos.possid, lv_currPos.posname, lv_currPos.posdate ;
  from active left outer join lv_currPos ;
    on active.actsid = lv_currPos.possid ;
  orde by active.actsid
and then all you need is:
open database hrData
use lv_empPos
The last view will automatically open the views that it needs, however, if the source tables change, you need to requery all three views:
=requery('lv_maxDate')
=requery('lv_currPos')
=requery('lv_empPos')
Doru
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform