Pages

Showing posts with label SQL query. Show all posts
Showing posts with label SQL query. Show all posts

Wednesday, June 30, 2010

Convert Number to IP address

Convert Number to IP address.

Use the following query to convert the number into an IP Address..


DECLARE @IP_NUM AS INTEGER
SET @IP_NUM=1135863234 

SELECT CAST(@IP_NUM/16777216 AS VARCHAR(3)) +'.'+  
CAST((@IP_NUM%16777216)/65536 AS VARCHAR(3)) +'.'+ 
CAST( ((@IP_NUM%16777216)%65536)/256 AS VARCHAR(3))   +'.'+ 
CAST(((@IP_NUM%16777216)%65536)%256 AS VARCHAR(3))

Result:
67.179.229.194

Please give some suggestion to make it better.