Need to compare two strings on two Access columns

I have two sets of data that I need to compare but I can't figure out how to do it. First column contains IP addresses 'nnn.nnn.abc.def'. The second column (called name) contains 'name-abc-def'. I need to verify that the last two octets of the IP address match the second part of the name. The problem is that the name will contain zeros while the IP address will not. So I can't use the Replace(Right()) functions to compare the two values since they will have different lengths. For example:
IP: 123.123.200.6
Name: NAME-200-006

Somehow I would like to show in the query that these two values match. I hope someone can help me with this.
LVL 3
thomasd04Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JezWaltersCommented:
You're probably best to write a little VBA function to do the comparison and then invoke the function from SQL.

Hang on a mo and I'll give you the code.
0
Rey Obrero (Capricorn1)Commented:
you will need a function like this

Function getValues(s As String, d As String)
If s & "" = "" Then Exit Function
Dim vArr
vArr = Split(s, d)
Select Case d
    Case "."
        getValues = vArr(2)
   
    Case "-"
        getValues = vArr(1)
    Case Else
        getValues = ""
End Select
End Function

to use in a query

select * from table
where getvalues([IP],".")=getValues([Name],"-")



0
thomasd04Author Commented:
Thanks.
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Rey Obrero (Capricorn1)Commented:
thomasd04,

place the codes i posted in a regular module, and accept the default name for the module.
0
JezWaltersCommented:
OK, this should do the trick:
Option Explicit      ' Force explicit variable declarations
Option Compare Text  ' Perform non-case sensitive comparisons
Option Base 0        ' Start arrays at index 0

'
' Check addresses match
'
Public Function AddressesMatch(pvarAddress As Variant, _
                               pvarName As Variant) As Boolean

    ' Declare variables
    Dim astrAddress() As String  ' Address components
    Dim astrName() As String     ' Name components

    ' Compare address/name components
    astrAddress = Split(Nz(pvarAddress), ".")
    astrName = Split(Nz(pvarName), "-")
    If UBound(astrAddress) = 3 And _
       UBound(astrName) = 2 Then
        If Format(astrAddress(2), "000") = astrName(1) And _
           Format(astrAddress(3), "000") = astrName(2) Then
            AddressesMatch = True
        End If
    End If

End Function

Open in new window

0
JezWaltersCommented:
After you've created it, you can use the function like this:

    SELECT *
    FROM table1, table2
    WHERE AddressesMatch(table1.IPAddress, table2.Name)
0
MlandaTCommented:
here is a pure access and SQL implementation of the parsing that you need to do. I have created a table adn a view, but it will give you the exact way of doing it.
Database1.mdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.