I'm trying to the last two portions of a devices IP address (which is in a field) and use it as part of a device ID. Right now I'm using the MID function in SQL to get the 9th through the last digit. This works fine for our IP addresses which are like 192.168.0.1 (most of them), but it doesn't work for the IP addresses that are like 12.232.100.100 (a few of them). I would like to be able to have it look for everything after the second period, but I haven't been able to find anything online for that. Is this possible?
Here is the code I'm using now: - SELECT tblDevice.Company,
-
tblDevice.Branch,
-
tblDevice.ComputerName,
-
tblDevice.Department,
-
tblDevice.Type,
-
tblDevice.Manufacturer,
-
tblDevice.Model,
-
tblDevice.SerialNumber,
-
tblDevice.ExtendedServiceCode,
-
tblDevice.PurchaseDate,
-
tblDevice.Warranty,
-
tblDevice.Vender,
-
tblDevice.OperatingSystem,
-
tblDevice.OfficeVersion,
-
tblDevice.Status,
-
tblDevice.UsageHistory,
-
tblDevice.Processor,
-
tblDevice.RAM,
-
tblDevice.HDD,
-
tblDevice.HDDType,
-
tblDevice.HDDRemoved,
-
(SELECT TOP 1 IPAddress FROM tblIPAddress WHERE DeviceID = SerialNumber) AS IPAddress,
-
Year(PurchaseDate) & Month(PurchaseDate) & ('-'+SerialNumber) & ('-'+Mid(IPAddress,9)) AS DeviceID
-
FROM tblDevice;
-
Use the InStr function to find the location of the first dot. Use that plus 1 as the start parameter for another InStr function to find the second dot. Now that you know where the second dot is, you can use the Mid function to grab everything after that point.
2 4486
Use the InStr function to find the location of the first dot. Use that plus 1 as the start parameter for another InStr function to find the second dot. Now that you know where the second dot is, you can use the Mid function to grab everything after that point.
Thank-you Rabbit. That was exactly what I needed. For anyone else viewing this, I replaced line 23 from my OP to be: - Year(PurchaseDate) & Month(PurchaseDate) & ('-'+SerialNumber) & ('-'+Mid(IPAddress,InStr(InStr(IPAddress,".")+1,IPAddress,".")+1)) AS DeviceID
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Richard T. Cunningham |
last post by:
I've been using two instances of substr to pull an IP address out of a
string. I know there's a more efficient way. Anyone? The string is
like this:
HOST 61.2.135.45 blocked.
Richard
|
by: cvillard |
last post by:
I am new to SQL, as old as it is. I am not new to programming I
normally just use Access.
I have two tables for a little project manager I made. After updates I
sent an email to the user. I need...
|
by: kyle.tk |
last post by:
I am trying to write a function to convert an ipv4 address that is held
in the string char *ip to its long value equivalent. Here is what I
have right now, but I can't seem to get it to work.
...
|
by: bobBaker |
last post by:
Does anybody know of a good way to get a list of emails from the corporate
exchange server from a corporate website?
|
by: RThaden |
last post by:
Hi all,
I have a text file with a list of MAC addresses.
Each time, my program is called it reads the last MAC address entry
from the file, increases it by one, writes this new address into a 6...
|
by: amanda27 |
last post by:
I have a database that we use in our department for the status of our projects. In the form when you pick a project from the dropdown list I have a subform that pulls the data entered for the...
|
by: NetworkElf |
last post by:
Hi all,
Does anyone have some code that shows an example of how to loop through a
range of IP addresses? I'm using text boxes to get a start and end value for
the range. I was thinking about...
|
by: Harlin Seritt |
last post by:
Is there a module that can pull str values for say the last 3 months?
Something like:
print lastMonths(3)
Thanks
|
by: barmatt80 |
last post by:
there is a website i was asked to look at ( i have no clue why as i have never done much web development expecially with frontpage extensions).
they want to setup a form on the page that will...
|
by: dewed |
last post by:
hello,
I have a simple form. some text boxes for customername , date and a code for each customer...i want my secretary not to get access to other columns which are about prices..just to enter the 3...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |