Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Conversion help

Conversion help

Scheduled Pinned Locked Moved Database
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solutionsville
    wrote on last edited by
    #1

    I want to take an IP address e.g. 111.222.333.444 and convert it to either a float or an unsigned datatype. Thanks,

    P 1 Reply Last reply
    0
    • S solutionsville

      I want to take an IP address e.g. 111.222.333.444 and convert it to either a float or an unsigned datatype. Thanks,

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Why? An IP address is really a string of numbers - not a number. Removing the dots won't help because you really don't know where to put them back. I suppose you could always store it as four numbers, but it still doesn't gain you much.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      S 1 Reply Last reply
      0
      • P Pete OHanlon

        Why? An IP address is really a string of numbers - not a number. Removing the dots won't help because you really don't know where to put them back. I suppose you could always store it as four numbers, but it still doesn't gain you much.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        S Offline
        S Offline
        solutionsville
        wrote on last edited by
        #3

        The reason is for faster search indexing. I found this after I posted; Create FUNCTION [dbo].[Dot2LongIP]( @IP VarChar(15) ) RETURNS BigInt AS BEGIN DECLARE @ipA BigInt, @ipB Int, @ipC Int, @ipD Int, @ipI BigInt SELECT @ipA = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipA) - 1 ) SELECT @ipB = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipB) - 1 ) SELECT @ipC = LEFT(@ip, PATINDEX('%.%', @ip) - 1 ) SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipC) - 1 ) SELECT @ipD = @ip RETURN ( @ipA * 256*256*256 ) + ( @ipB * 256*256 ) + ( @ipC * 256 ) + @ipD END RETURN @ipI END This does speed it up and seems to meet my needs. Thanks,

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups