×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find string anywhere in dbf tables

Find string anywhere in dbf tables

Find string anywhere in dbf tables

(OP)
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.

RE: Find string anywhere in dbf tables

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.
 

RE: Find string anywhere in dbf tables

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.

RE: Find string anywhere in dbf tables

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

RE: Find string anywhere in dbf tables

(OP)
Just tried out Agent Ransack and it worked like a charm - thanks :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close