Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 315525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:17:58+00:00 2026-05-12T08:17:58+00:00

As the question says what is the SQL Server equivalent of INET_ATON from mySql.

  • 0

As the question says what is the SQL Server equivalent of INET_ATON from mySql. The reason I need this is because i imported a IP data base from http://ipinfodb.com/ip_database.php into SQL Server 2005 and would like to query the table now. But based on their examples I am not sure how to do that.

INET_ATON(expr)

Given the dotted-quad representation
of a network address as a string,
returns an integer that represents the
numeric value of the address.
Addresses may be 4- or 8-byte
addresses.

mysql> SELECT INET_ATON('209.207.224.40');
        -> 3520061480
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:17:59+00:00Added an answer on May 12, 2026 at 8:17 am

    Take a look at these stored procedure examples for achieving this

    CREATE FUNCTION dbo.ipStringToInt 
    ( 
        @ip CHAR(15) 
    ) 
    RETURNS INT 
    AS 
    BEGIN 
        DECLARE @rv INT, 
            @o1 INT, 
            @o2 INT, 
            @o3 INT, 
            @o4 INT, 
            @base INT 
    
        SELECT 
            @o1 = CONVERT(INT, PARSENAME(@ip, 4)), 
            @o2 = CONVERT(INT, PARSENAME(@ip, 3)), 
            @o3 = CONVERT(INT, PARSENAME(@ip, 2)), 
            @o4 = CONVERT(INT, PARSENAME(@ip, 1)) 
    
        IF (@o1 BETWEEN 0 AND 255) 
            AND (@o2 BETWEEN 0 AND 255) 
            AND (@o3 BETWEEN 0 AND 255) 
            AND (@o4 BETWEEN 0 AND 255) 
        BEGIN      
            SELECT @base = CASE 
                WHEN @o1 < 128 THEN 
                    (@o1 * 16777216) 
                ELSE 
                    -(256 - @o1) * 16777216 
                END 
    
            SET @rv = @base +  
                (@o2 * 65536) +  
                (@o3 * 256) + 
                (@o4) 
        END 
        ELSE 
            SET @rv = -1 
        RETURN @rv 
    END
    

    Example usage

    INSERT mytable VALUES(dbo.ipStringToInt('1.2.3.4'))
    

    If you want to reverse that and turn an integer into a dotted-quad, try this

    CREATE FUNCTION dbo.ipIntToString 
    ( 
        @ip bigINT 
    ) 
    RETURNS CHAR(15) 
    AS 
    BEGIN 
        DECLARE @o1 bigINT, 
            @o2 bigINT, 
            @o3 bigINT, 
            @o4 bigINT 
    
        IF ABS(@ip) > 4294967295 
            RETURN '255.255.255.255' 
    
        SET @o1 = @ip / 16777216 
    
        IF @o1 = 0 
            SELECT @o1 = 255, @ip = @ip + 16777216 
    
        ELSE IF @o1 < 0 
        BEGIN 
            IF @ip % 16777216 = 0 
                SET @o1 = @o1 + 256 
            ELSE 
            BEGIN 
                SET @o1 = @o1 + 255 
                IF @o1 = 128 
                    SET @ip = @ip + 2147483648 
                ELSE 
                    SET @ip = @ip + (16777216 * (256 - @o1)) 
            END 
        END 
        ELSE 
        BEGIN 
            SET @ip = @ip - (16777216 * @o1) 
        END 
    
        SET @ip = @ip % 16777216 
        SET @o2 = @ip / 65536 
        SET @ip = @ip % 65536 
        SET @o3 = @ip / 256 
        SET @ip = @ip % 256 
        SET @o4 = @ip 
    
        RETURN 
            CONVERT(VARCHAR(4), @o1) + '.' + 
            CONVERT(VARCHAR(4), @o2) + '.' + 
            CONVERT(VARCHAR(4), @o3) + '.' + 
            CONVERT(VARCHAR(4), @o4) 
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I'm using SQL Server 2008. Apologies if this question is
As the question says: How to access Microsoft SQL Server 2005 from Cocoa on
Basically, the question says it all. I need a PL\SQL query that returns a
This question is related to my question: SQL Server and TransactionScope (with MSDTC): Sporadically
I'm trying to write a program that will fetch data from a SQL Server
Question says it all. I'm just having trouble figuring this out. What i'm trying
I am using SQL Server 2008 Enterprise. I met with issue which says line
I need to export database from one server and import it into another server.
This question is based on this thread . I run unsuccessfully sudo mysql \.
This is the continual question from this previous question I've asked: Change Database Column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.