Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Combining 2 SELECT statements for converting IP numbers to IP address

$
0
0

What I am trying to do here is get a list of clients with their IP address but SQL IP is in decimal encoded format. Running the below query is returning errors. How can I modify the query to run as one and to make it return IP address instead of decimal format?

select distinct(clientusername), clientip, 
from weblog 
where logtime > '2013-03-01' 

UNION

SELECT 

CAST(ClientIP / 256 / 256 / 256 % 256 AS VARCHAR) + '.' + 

CAST(ClientIP / 256 / 256 % 256 AS VARCHAR) + '.' + 

CAST(ClientIP / 256 % 256 AS VARCHAR) + '.' + 

CAST(ClientIP % 256 AS VARCHAR) 

AS [Nice Source Ip], WebLog.*

From WebLog


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>