Created
December 20, 2013 11:28
-
-
Save JamesTryand/8053548 to your computer and use it in GitHub Desktop.
MSSql Scalar Function that converts an IPAddress to its Numerical equivalent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET ANSI_NULLS ON | |
| GO | |
| SET QUOTED_IDENTIFIER ON | |
| GO | |
| -- ============================================= | |
| -- Author: James Tryand | |
| -- Create date: 2013-12-20 | |
| -- Description: Converts An IPAddress to it's numerical equivalent | |
| -- ============================================= | |
| CREATE FUNCTION IPAddress2IPNumber | |
| ( | |
| @IPaddress varchar(20) | |
| ) | |
| RETURNS bigint | |
| AS | |
| BEGIN | |
| RETURN | |
| 16777216 * CAST(ParseName(@IPaddress, 1) as bigint) + | |
| 65536 * CAST(ParseName(@IPaddress, 2) as bigint) + | |
| 256 * CAST(ParseName(@IPaddress, 3) as bigint) + | |
| CAST(ParseName(@IPaddress, 4) as bigint) | |
| END | |
| GO | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment