Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SEEK and LOCATE and UPPER and ALLTRIM
Message
From
14/01/2009 07:51:23
 
 
To
14/01/2009 07:43:13
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01373413
Message ID:
01373486
Views:
23
>>>There is an index on TableFormProperties.TableName, but the date is in mixed case, so I can't do a SEEK (or can I?). I'm doing this in a LOCATE, but that seems a bit wrong somehow. Is this the right way to do it, or is there a better way.
>>>
>>>lcTableName = "MyTableName"
>>>SELECT TableFormProperties
>>>LOCATE FOR ALLTRIM(UPPER(TableName) = ALLTRIM(UPPER(lcTableName))
>>>
>>
>>It's my opinion that Alltrim() should be avoided as much as possible, unless you really need it. This code will give the same result, and will be much faster if you have an index tag on upper(Tablename). It will also be independent of the Set Exact setting:
>>lcTableName = "MyTableName"
>>SELECT TableFormProperties
>>lcTableName = padr(lcTableName,len(TableName))
>>LOCATE FOR UPPER(TableName) == upper(lcTableName)
>
>I should have stated that the index does not use UPPER, but I see if one was put on in the future it would affect performance.

Anyway, the use of alltrim() can often be very dangerous, but not in this case where you know the value up front. But if lcTablename was an empty string, LOCATE FOR ALLTRIM(UPPER(TableName) = ALLTRIM(UPPER(lcTableName)) would match all the records, my code would only find any blank records.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform