What am I, chopped liver?
snip>
declare @int as bigint, @bin varbinary(4), @ip varchar(15)
select @int = 1023508566 -- or however you're grabbing the data. select @bin = cast(@int as varbinary(4))
select @ip = cast(convert(int,substring(@bin,1,1)) as varchar(3)) + '.' + cast(convert(int,substring(@bin,2,1)) as varchar(3)) + '.' + cast(convert(int,substring(@bin,3,1)) as varchar(3)) + '.' + cast(convert(int,substring(@bin,4,1)) as varchar(3))
select @ip
</snip>
T
http://www.ISAserver.org
Hi Joe!
Oh, great SQL deity, how would a lowly scripter transmorgrify the below Jscript function to T-SQL? What it does is translate a long (SQL BigInt) to an IP address string. Save it as 'long2string.js' Run it as 'cscript long2string.js 1023508566'.
<snip> var lIpAddr = parseInt( WScript.Arguments( 0 ) );
WScript.Echo( "IP_long " + lIpAddr + " == IP_String \'" + IpLongToIpString( lIpAddr ) + "\'." );
function IpLongToIpString( lIpAddr ) { var arrIPAddr = new Array( ); var iOctetMask = 0xFF; var iNumBits = 8; for( var iOctetCtr = 3; iOctetCtr >= 0; iOctetCtr-- ) { var iOctet = ( lIpAddr >>> ( iNumBits * iOctetCtr ) ) & iOctetMask; arrIPAddr.push( iOctet ); } return arrIPAddr.join( "." ); } </snip>
I need to do this in a view so that my OLAP cube presents it in a "readable" form. T'anx!
------------------------------------------------------- Jim Harrison MCP(NT4, W2K), A+, Network+, PCG http://isaserver.org/Jim_Harrison/ http://isatools.org Read the help / books / articles! -------------------------------------------------------
All mail to and from this domain is GFI-scanned.
------------------------------------------------------
List Archives: http://www.webelists.com/cgi/lyris.pl?enter=isalist
ISA Server Newsletter: http://www.isaserver.org/pages/newsletter.asp
ISA Server FAQ: http://www.isaserver.org/pages/larticle.asp?type=FAQ
------------------------------------------------------
Other Internet Software Marketing Sites:
World of Windows Networking: http://www.windowsnetworking.com
Leading Network Software Directory: http://www.serverfiles.com
No.1 Exchange Server Resource Site: http://www.msexchange.org
Windows Security Resource Site: http://www.windowsecurity.com/
Network Security Library: http://www.secinf.net/
Windows 2000/NT Fax Solutions: http://www.ntfaxfaq.com
------------------------------------------------------
You are currently subscribed to this ISAserver.org Discussion List as: thor@xxxxxxxxxxxxxxx
To unsubscribe visit http://www.webelists.com/cgi/lyris.pl?enter=isalist
Report abuse to listadmin@xxxxxxxxxxxxx