Convert signed int to string ip address in SQL Server
I'm retrieving a signed int from a SQL Server database and need to convert it to a "normal" looking dotted string for display to users. Googling, I found this code: SELECT dbo.IPADDRESS.IPADDRESS, CAST(ROUND( (cast(dbo.IPADDRESS.IPADDRESS as bigint) / 16777216 ), 0, 1) AS varchar(4)) + '.' + CAST((ROUND( (cast(dbo.IPADDRESS.IPADDRESS as bigint) / 65536 ), 0, 1) % 256) AS varchar(4)) + '.' + CAST((ROUND( (cast(dbo.IPADDRESS.IPADDRESS as bigint) / 256 ), 0, 1) % 256) AS varchar(4)) + '.' + CAST((cast(dbo.IPADDRESS.IPADDRESS as bigint) % 256 ) AS varchar(4)) as IPDottedNotation FROM dbo.IPADDRESS