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 ''. 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:
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.
Who is Participating?
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.
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.
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],"-")

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

thomasd04Author Commented:
Rey Obrero (Capricorn1)Commented:

place the codes i posted in a regular module, and accept the default name for the module.
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

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

    SELECT *
    FROM table1, table2
    WHERE AddressesMatch(table1.IPAddress, table2.Name)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.