Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select
Message
 
To
10/07/2012 06:03:07
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01547863
Message ID:
01547987
Views:
46
>>>>>>>
>>>>>>>select * from myTable where nNumber IN (Fld1, Fld2, Fld3).
>>>>>>>
>>>>>>>
>>>>>>>They will behave the same as your original code, just a shorter code.
>>>>>>>
>>>>>>>There is no faster approach for this problem.
>>>>>>
>>>>>>Thank you.
>>>>>
>>>>>You're welcome.
>>>>
>>>>Is it optimizable?
>>>
>>>It is exactly the same as original Fld1 = @nNumber or Fld2 = @nNumber or ...
>>>
>>>So, it is optimizable if we have indexes on each of these columns.
>>
>>Not exacyly.
>>Can't test it in SQL Server right now but in VFP:
>>
>>CREATE CURSOR crsTest (Fld1 I, Fld2 I)
>>FOR lnFor = 1 TO 20
>>    INSERT INTO crsTest VALUES(lnFor,20-lnfor)
>>NEXT
>>INDEX ON Fld1 TAG Fld1
>>INDEX ON Fld2 TAG Fld2
>>lnNumber = 12
>>
>>SYS(3054,12,[tst])
>>SELECT * FROM crsTest WHERE m.lnNumber IN(Fld1, Fld2)
>>MESSAGEBOX(tst)
>>
>>SELECT * FROM crsTest WHERE Fld1 = m.lnNumber OR Fld2 = m.lnNumber
>>
>>MESSAGEBOX(tst)
>>SYS(3054,0)
>>
>
>VFP is too simple!
>
>CREATE CURSOR crsTest (Fld1 I, Fld2 I)
>FOR lnFor = 1 TO 20
>    INSERT INTO crsTest VALUES(lnFor,20-lnfor)
>NEXT
>INDEX ON Fld1 TAG Fld1
>INDEX ON Fld2 TAG Fld2
>lnNumber = 12
>
>SYS(3054,12,[tst])
>
>SELECT * FROM crsTest WHERE m.lnNumber IN(Fld1, Fld2)
>MESSAGEBOX(tst)
>
>SELECT * FROM crsTest WHERE Fld1 = m.lnNumber OR Fld2 = m.lnNumber
>
>MESSAGEBOX(tst)
>
>* not optimized !!!!
>SELECT * FROM crsTest WHERE m.lnNumber = Fld1 OR m.lnNumber = Fld2
>
>MESSAGEBOX(tst)
>SYS(3054,0)
>
Yep.
VFP wants the field names to be first in WHERE.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform