Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AS Clause
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00409807
Message ID:
00410022
Vues:
22
>>>>Hi Jim,
>>>>
>>>>>>When i execute the folowing SQL query, i get the error colomn "WTG"not found.
>>>>>>
>>>>>>SELECT detail.avr_ari,;
>>>>>> iif(Detail.avr_wtg=.t.,'J','N') as WTG;
>>>>>>FROM general!detail;
>>>>>>WHERE WTG='J'
>>>>>>
>>>>>>Is this an impossible kind of query, to include an expressionalias in the WHERE Clause ?
>>>>>>
>>>>>>Any idea's how to solve this ?
>>>>>>
>>>>>
>>>>>Bjorn,
>>>>>
>>>>>The WHERE clause of SELECT si applied to the source tables, there is no fild named WTG in the source fields. You can change it to;
>>>>>
>>>>>WHERE Detail.avr_wtg = "J"
>>>>>
>>>>
>>>>This will cause a data-type mismatch. If he's testing against the result of the iif(), he's got to use the HAVING clause.
>>>
>>>Naw, you don't need a HAVING or a comparison operator, simply
SELECT detail.avr_ari, "J" AS WTG;
>>>FROM general!detail;
>>>WHERE Detail.avr_wtg
will do the trick. Using Detail.avr_wtg = .T. slows things down.
>>
>> George,
>>
>> If you have index on avg_wtg (though it would be strange to have index on logical field), I assume, where avr_wtg=.t. should be faster than where avr_wtg
>>
>>Correct me, please, if I'm wrong.
>
>No, it wouldn't be. This is because whenever you have a comparison operator, both sides of the expression must be evaluated.

Ok, I ran few tests, which basically confirmed your statement, though they are not consistent. Im my test table I have ~7200 records, ~200 deleted, IncInRpt - logical field, and the table has index on this field.
Test with logical field=.t.
  3.973000
  4.389000
  3.751000
  3.714000
  3.698000
  3.704000
  3.711000
  3.713000
  3.703000
  3.714000
Total time:    38.070000
Average Time:     3.807000

Test with just logical field
  3.819000
  3.750000
  3.715000
  3.724000
  3.716000
  3.714000
  3.718000
  3.721000
  3.726000
  3.713000
Total time:    37.316000
Average Time:     3.731600
This is the test program:
lnstr="Test with logical field=.t."
lnSecElapsed=0
lnTot=0
for i=1 to 10
     use g:\redp\work\pp\pp10swan00_b.dbf alias BldMstr
     lnSec=seconds()
     select * from BldMstr where incinrpt=.t. into cursor curInc
     lnSecElapsed=seconds()-lnSec
     lnstr=lnstr+chr(13)+str(lnSecElapsed,10,6)
     lnTot=lnTot+lnSecElapsed
     close data all
next
lnstr=lnstr+chr(13)+"Total time: "+str(lnTot,12,6)+ ;
     chr(13)+"Average Time: "+str(lnTot/10,12,6)
lnTot=0
lnstr=lnstr+chr(10)+chr(13)+"Test with just logical field"
for i=1 to 10
     use g:\redp\work\pp\pp10swan00_b.dbf alias BldMstr
     lnSec=seconds()
     select * from BldMstr where incinrpt into cursor curInc
     lnSecElapsed=seconds()-lnSec
     lnstr=lnstr+chr(13)+str(lnSecElapsed,10,6)
     lnTot=lnTot+lnSecElapsed
     close data all
next
lnstr=lnstr+chr(13)+"Total time: "+str(lnTot,12,6)+ ;
     chr(13)+"Average Time: "+str(lnTot/10,12,6)

strtofile(lnstr,"testfile.txt")
modi file testfile.txt
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform