If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Urgent help with SQL query!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-04, 17:27
SERGE_2004 SERGE_2004 is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Lightbulb Urgent help with SQL query!

Hi everyone!

I have the table which has IP address column
(192.xxx.xxx.xxx) And I have a new blank column in the
same table titled "Gateway". I will need help to create
the query which will take IP address and replace the last
octet of IP address to .1 , so the results look like :
IP address Gateway
192.134.45.67 192.134.45.1
192.56.25.204 192.56.25.1
And copy that data later into corresponding row
of "gateway" column.
The problem is that last octet could have one, two or
three characters and you can't use here RIGHT, REPLACE is
also very tricky.
Does anyone have any ideas how to do it?
Any help will be greatly appreciated!
Million thanks!

Serge
Reply With Quote
  #2 (permalink)  
Old 02-02-04, 20:50
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Visual Basic 6,

Dim str As String
str = "192.168.0.255"
str = Left(str, InStrRev(str, ".")) + "1"
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 02-04-04, 03:13
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Oracle's SQL:

Code:
UPDATE ip_table SET
  gateway = SUBSTR(ip, 1, INSTR(ip, '.', 1, 3)) || '1';
The INSTR(char1, char2 [,n[,m]]) function searches "char" beginning with its "n"th character for the "m"th occurrence of "char2" and returns the position of the character in "char" that is the first character of this occurrence.

"||" represents concatenation operator.

For example, this query would do something like that:
Code:
IP                    GATEWAY
------------------ ---------------
192.134.45.67   192.134.45.1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On