Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Successive LEFT SQL joins back to original
Message
De
06/12/2012 04:10:28
 
 
À
06/12/2012 03:46:48
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01558899
Message ID:
01558909
Vues:
50
Instead of alias() inside the Select statement, you should add lcSource = alias() before it, and replace alias() with lcSource inside it.

>Borislav,
>Thanks a lot for your example. I was able to mimic with my data . But result was obscure, spa_date was null everywhere for joins, unless artificially make in job2 record rucjob equal job_no. In any case it still draws all qty1 != 0 from jobs, so what was the purpose remains unclear. As you understood, it is someone's else code , so no idea why ALIAS() is used in select statement. Any side effects ?
>
>
>
>>>I need to redo sql statement in legacy Foxpro application and don't understand whether it is meaningful at all. 
>>>
>>>SELECT aa.*,b.spa_date FROM (ALIAS()) aa INNER JOIN jobs ON aa.seq=jobs.seq ;
>>>LEFT JOIN job2 ON jobs.job_no=job2.rucjob;
>>>left join jobs b on b.job_no=job2.job_no;
>>>WHERE jobs.qty1 != 0 INTO CURSOR (ALIAS())
>>>
>>>Since only one field is added from joined tables ( spa_date ) is there any point in 2 left joins or I am missing something. Isn't it equivalent to
>>>
>>>SELECT aa.*,jobs.spa_date FROM (ALIAS()) aa INNER JOIN jobs ON aa.seq=jobs.seq ;
>>>WHERE jobs.qty1 != 0 INTO CURSOR (ALIAS())
>>
>>No, they are not equal.
>>Check the difference:
>><pre>
>>CREATE CURSOR Test (Seq int)
>>CREATE CURSOR Jobs (Seq int, Job_no int, spa_date D, qty1 I)
>>CREATE CURSOR Job2 (Job_no int, Rucjob int)
>>
>>INSERT INTO Test VALUES (1)
>>INSERT INTO Jobs VALUES(1,1, DATE(), 1)
>>INSERT INTO Jobs VALUES(1,2, DATE()+50, 1)
>>INSERT INTO Job2 VALUES (1,2)
>>
>>SELECT Test
>>lcAlias = ALIAS()
>>
>>SELECT aa.*,b.spa_date ;
>>       FROM Test aa;
>>INNER JOIN jobs ON aa.seq=jobs.seq ;
>>LEFT  JOIN job2 ON jobs.job_no=job2.rucjob;
>>LEFT  JOIN jobs b on b.job_no=job2.job_no;
>>WHERE jobs.qty1 != 0 INTO CURSOR Test1
>>BROWSE NORMAL
>>
>>SELECT aa.*,jobs.spa_date;
>>       FROM Test aa;
>>INNER JOIN jobs ON aa.seq=jobs.seq ;
>>WHERE jobs.qty1 != 0 INTO CURSOR Test1
>>BROWSE NORMAL
>>
>>
>>BTW WHY you use ALIAS() in SQL Statement?
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform