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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find string anywhere in dbf tables

Status
Not open for further replies.

khsaunderson

Technical User
Feb 16, 2010
41
GB
Hi

I'm migrating data from an old dbf database and need to only migrate certain info. I'm looking for a specific string, so that I migrate the info from the correct table. Rather than searching through every table (over 200 of them), is there any way I can use SQL to find the string in the tables. I have a T-SQL script that I've used on MS SQL Server, but it doesn't seem to want to work on the dbf tables.

Does anyone knwo of a little trick I can use to find the string? Any help would be much appreciated.
 
The AT command is used in dbase to test a field for a specific string. But it is field specific. You could right a routine that would check every field for this value if needed. But you appear to need this to happen outside that environment. If that is the case there may be a better forum to post this question.

Jim C.
 
Perhaps you could use a search program such as AgentRansack (a free version) which can locate the text string in any file, then just scan those tables for matching records.
 
Once you determine which tables contain the text strings, you can find the record numbers (or do more by modifying code):
Code:
DO ScanFlds WITH "MySearchText", "C:\data\filename.dbf"

PROCEDURE ScanFlds
PARAMETER cSrchText, cPathName
SET TALK OFF
SET EXCLUSIVE OFF
USE (cPathName) NOUPDATE
* using DO WHILE since sometimes SCAN fails
* subtle bug - not sure if limited to dBase for DOS version 5
DO WHILE .NOT. EOF()
   lRecFound = .F.
   FOR xFld = 1 TO FLDCOUNT()
      cFld = FIELD(xFld)
    * If you want to ignore case
    * IF TYPE(cFld) = "C" .AND. UPPER(cSrchText) $ UPPER(EVALUATE(cFld))
      IF TYPE(cFld) = "C" .AND. cSrchText $ EVALUATE(cFld)
         lRecFound = .T.
         EXIT
      ENDIF
   ENDFOR
   IF lRecFound
      ? "Found text in record #"+LTRIM(STR(RECNO())) ;
         + " field: "+cFld+"="+EVALUATE(cFld)
      * matching record found - insert code here
   ENDIF
   SKIP
ENDDO
SET TALK ON
RETURN
 
Just tried out Agent Ransack and it worked like a charm - thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top