?
Solved

Apply a function to each row in a table

Posted on 2014-09-11
7
Medium Priority
?
164 Views
Last Modified: 2014-09-12
Hello

I have a function that covnerts IPv6 into IPv4 and I need it to loop through each row in the table to perform the conversion.

The pertinent columns in the proxy table are

[ClientIP] -- this contains the IPv6 entries
[IPv4] -- I added this column in order to host the converted values.

What is the best method to accomplish this? Please note that my TSQL programming is only of a fundamental level!

I have attached the function and I can retrieve an output for single values such as:

SELECT [proxy].[dbo].[fnIpAddressToText] (
   'AC130C0A-FFFF-0000-0000-000000000000')

this obviously only accomplishes one conversion and I need it to loop through all the entries in a relatively large table (hundreds of thousands of rows).

We are using SQL Server 2008R2.

All help appreciated!
0
Comment
Question by:Jay Carax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40316818
"I have attached the function"

I don't see that attachment
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40316829
Didn't know you can convert IPv6 to IPv4, since you will have much more addresses in IPv6 than IPv4.
I'm curious about how you going to do this (how to handle those not convertible addresses).
0
 

Author Comment

by:Jay Carax
ID: 40316895
Function is now attached.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:Jay Carax
ID: 40316905
And Vitor, I've just had a word with the networks guys - it converts a hexedecimal value into IPv4 - apologies for the confusion. The attachment should clear things up.
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40316926
Still can't see the attached function but saw the example you posted and by that you can't accomplish what you want, since IPv4 permits at maximum a value of 255 and for example FFFF it's 65535.
0
 
LVL 13

Accepted Solution

by:
Koen Van Wielink earned 2000 total points
ID: 40316942
Since you have the existing value as well as the conversion column in the same table, and a separate function to perform the conversion, this should be fairly straightforward:

update yourTable
set IP4V = [proxy].[dbo].[fnIpAddressToText] (ClientIP)

Open in new window


assuming that [proxy].[dbo].[fnIpAddressToText]  is your conversion function.
0
 

Author Closing Comment

by:Jay Carax
ID: 40319484
Exactly what was needed - thank you.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question