December 6, 2008 at 8:35 pm
Hello everybody,
I have IP addresses in one field. I need to display each set of values into different fields.
For example, in an 'IP_Addresses' field I have a record as this:
IP_Addresses
-----------------
208.77.188.166
Now, I need to display it like this:
col_A col_B col_C col_D
------ --------- -------- ---------
208 77 188 166
Can any one give me a clue on how to do this. Thank you.
December 6, 2008 at 11:44 pm
Replace the derived table in the from clause with your real table...
SELECT PARSENAME(d.IpAddr,4) As ColA,
PARSENAME(d.IpAddr,3) As ColB,
PARSENAME(d.IpAddr,2) As ColC,
PARSENAME(d.IpAddr,1) As ColD
FROM
(SELECT '208.77.188.166' AS IpAddr UNION ALL
SELECT '208.77.188.001' UNION ALL
SELECT '208.77.188.1')d
--Jeff Moden
Change is inevitable... Change for the better is not.
December 7, 2008 at 11:04 am
Jeff, I would never have thought to use parsename on an IP address, but it makes perfect sense because it has four elements separated by periods. Tell me that wasn't an original idea that just occurred to you when you saw his question.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
December 7, 2008 at 11:26 am
Thank you Jeff.
December 8, 2008 at 4:54 am
Bob Hovious (12/7/2008)
Jeff, I would never have thought to use parsename on an IP address, but it makes perfect sense because it has four elements separated by periods. Tell me that wasn't an original idea that just occurred to you when you saw his question.
Heh... no... it was an "original" idea when I first saw the need back in the 90's... I say "original" because I later found out that lot's of people had been using it for that and I just didn't know it. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
December 8, 2008 at 4:54 am
Suraj (12/7/2008)
Thank you Jeff.
You bet... thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply