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

Use of InStr to find existence of string

Status
Not open for further replies.

mbowler9

IS-IT--Management
Sep 8, 2003
105
US
Hello all. I am trying to make a query that consists of several tables, but only two tables are important for this issue.

CPU table
-sys_name (samplename)
-dns (sampledns.com)

Performance table
-sys_dns (samplename.sampledns.com)
-tot_occ (integer)

I need to get total_occ in the query, but the primary key on all of my tables is sys_name and dns with the exception of the Performance table which concatenates the two. Can I somewhow use the InStr function to look up the sys_name in sys_dns, or am I going to have to create a new table for this? What about a subquery that takes everthing before the first "."?

Can you think of any other solutions?

Thank you in advance.
 
I solved this about 10 minutes later.

Created a sub query that calls the following function.

Public Function getName(myStr As String) As String
Dim i As Integer
Dim cycle As Boolean
Dim sysname As String

cycle = True

Do While cycle = True

For i = 1 To Len(myStr)
If (Mid(myStr, i, 1)) = "." Then
sysname = Left(myStr, i - 1)
cycle = False
Exit Do
End If
Next i

Loop

getName = sysname
End Function

 
You can use the "LIKE" operator in the query.

for instance:

"SELECT Left(sys_dns, InStr(sys_dns, ".") - 1) As sys_name FROM [Performance table]"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top