Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SEARCH A STRING

Status
Not open for further replies.

txgeekgirl1

Programmer
Sep 10, 2009
85
US
I have a variable Proccode. I need to search the string for letter combinations "GTGY" or "HK". Is there a lookup code for this in FP?
 
Code:
SELECT * FROM YourTable;
       WHERE Field LIKE '%GTGY%' OR;
             Field LIKE '%HK%

or
Code:
LOCATE FOR LIKEC('*GTGY*', Firld) OR;
           LIKEC('*HK*', Firld)

NOT TESTED!!!!!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
SELECT *
FROM ENCCHG1_ ;
WHERE ProcCode LIKE '*GTGY*' ;
AND ProcCode LIKE '*HK*' ;
AND ProcCode LIKE '*UK*' ;
AND ProcCode LIKE '*HR*' ;
INTO CURSOR EncChg_

Invalid table
Unrecognized command.
 
Txgeekgirl1,

Several points:

1. The LIKE operator uses % for its wildcard, not *

2. I'd guess you need to OR the conditions together, not AND them.

3. If you are getting an invalid table message, the most likely explanation is that the table is invalid. Have you considered that possibility?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Two points on your last message.

The first is that you've forgotten the semi-colon from the end of the first line so Fox is trying to execute "SELECT *" and it's failing.

The second is that you should be using "OR" not "AND" to connect the tests. As it stands, your code will only select a record if that record contains every one of your codes. You need to be selecting a record if it includes any one of GTGY or HK or UK or HR.

Geoff Franklin
 
Hi Mike - Table was fine once I removed the WHERE Clause.

I will retry the LIKE. I hand wrote substr(s) but I am not sure if I captured them all.

Thanks,
 
Hmmm, did you see the difference between my two suggestions?
The one where I used SELECT with LIKE and when I used LIKE() function?
Code:
SELECT *; && You missed semicolon here
      FROM ENCCHG1_ ;
WHERE ProcCode LIKE '*GTGY*' ;
   OR ProcCode LIKE '*HK*' ;
   OR ProcCode LIKE '*UK*' ;
   OR ProcCode LIKE '*HR*' ;
INTO CURSOR crsEncChg_
* Always name your cursors that way  so you are sure you didn't close some "real" table


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Here is what worked. Thanks guys! You saved me a lot of time this morning.

SELECT * FROM ENCCHG1_ ;
WHERE ProcCode LIKE '%GTGY%' ;
OR ProcCode LIKE '%HK%' ;
OR ProcCode LIKE '%UK%' ;
OR ProcCode LIKE '%HR%' ;
ORDER BY GridCode, ProcCode, RU, SAC ;
INTO CURSOR encchg_
 
Morning :)
Here it is a beer time :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top