Solved

Foxpro - Searching for numbers in separate column

Posted on 2016-10-03
8
32 Views
Last Modified: 2016-11-06
Here is my issue:  I have a dbf table with following fields:
Part Number               Orig Information
123                                Seat, 123, Viton
456                                Seat, 04567, Viton

I am trying to flag a field when the Part Number (123) is identified in the original field so that I can easily find items that need to be corrected.  The 456 is incorrectly entered into the Part Number field, it should be 04567 but I need to identify the ones that we need to look at.
0
Comment
Question by:appelonia21
8 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41826329
Is the Orig Information always in that format?
If so you can do something like
select * from table1 where [part number] <> mid([Orig Information],7,instr(7,[Orig Information],",")-7)

Open in new window

0
 

Author Comment

by:appelonia21
ID: 41826410
No unfortunately it isn't.  It is a raw data field and can be in any format, I just want to be able to search within it for the match
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41826431
@I just want to be able to search within it for the match

Are there any sure delimiters? If not you should create some code to check into any string to strip out the value to match

For example this query will select every record where part number is contained into Orig Information
select * from table1 where [Orig Information] LIKE "*"+[Part Number]+"*"

Open in new window

but if let's say every part number into the Orig Information is in format [space]Part No.[comma] (that is   " 04567,") then you could use a query like
select * from table1 where [Orig Information] not LIKE "* "+[Part Number]+",*"

Open in new window

0
 
LVL 34

Expert Comment

by:PatHartman
ID: 41826552
The ampersand (&) is the standard Access concatenation character.  The plus (+) can be used but it handles nulls differently so unless you need the special treatment of nulls, it is best to stick with standard.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 19

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 100 total points (awarded by participants)
ID: 41826574
not sure if this works in FoxPro, but here is VBA code to pull DIGITS out of a string:
Function GetDigits(psStringWithNumbers As String) As String
'8-6-08 s4p
   Dim sNumber As String _
      , i As Integer _
      , sChar As String * 1
      
   sNumber = ""
   'loop through and only keep numeric characters
   For i = 1 To Len(psStringWithNumbers)
      sChar = Mid(psStringWithNumbers, i, 1)
      If IsNumeric(sChar) Then
         sNumber = sNumber & sChar
      Else
         'comment if you don't want to stop looking
         If Len(sNumber) > 0 Then
            GetDigits = sNumber
            Exit Function
         End If
      End If
   Next i
   GetDigits = sNumber
End Function

Open in new window

0
 
LVL 41

Accepted Solution

by:
pcelba earned 400 total points (awarded by participants)
ID: 41826808
FoxPro allows much easier solution but you should tell what data type is the Part Number column and what is its true name as the "Part Number" looks like a title.

Let say the table is open in the current workarea already and column names are PartNum  and  OrigInfo so you may just SET FILTER to records of your interests:

Following commands shoul dwork independently on the PartNum data type.

*-- Display all rows where the PartNum is inside the OrigInfo:
SET FILTER TO TRANSFORM(PartNum) $ OrigInfo

*-- Display all rows where the PartNum isn't inside the OrigInfo:
SET FILTER TO NOT TRANSFORM(PartNum) $ OrigInfo

*-- Display all rows where the numeric part of OrigInfo is inside the PartNum:
SET FILTER TO CHRTRAN(OrigInfo, CHRTRAN(Originfo, "0123456789", ""), "") $ TRANSFORM(partNum)

*-- Display all rows where the numeric part of OrigInfo isn't inside the PartNum:
SET FILTER TO NOT CHRTRAN(OrigInfo, CHRTRAN(Originfo, "0123456789", ""), "") $ TRANSFORM(partNum)

*-- Clear the filter
SET FILTER TO

You may display the data by BROWSE command after you set the filter.

The TRANSFORM() function converts possible numeric value in the PartNum into a text, the double CHRTRAN() use will remove all nonnumeric characters from the text. The $ operator tests the string for a substring occurence.

But I am saying again: post right column names and data types to allow us to help better.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 41847240
The only solution or help suitable for FoxPro environment is in the post https:#a41826808. It explains how to define filters on the data in question to display data which follow given filter condition.

Other answers did not reflect FoxPro environment so they cannot work.

appelonia21, if you have additional questions to this subject ask then, if not then please close the question and mark the solution.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 41875976
Unfortunately, just one correct solution suitable for FoxPro was provided. Other solutions do not work correctly in FoxPro or they suppose FoxPro knows VBA etc. Assisted points were assigned for the good Access solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now