While converting some MySql databases to SQL Server I ran across this function. Confused by the lack of hints to its purpose in the name I did what any red-blooded IT person would do… look it up. It turns out that this function turns the string representation of an IP address into a long integer. What good that does I am still not sure, but here is the jist of the operation.
(octet1 * 256^3) + (octet2 * 256^2) + (octet3 * 256) + octet4
Simple enough, right? Now for the real question. What the heck is this function doing in the database? My only thought is that it is faster to search an integer than a string, but to my way of thought this function has nothing to do with normal database operations and doesn’t belong. A value like this should be converted to an integer by your business logic and passed into the database. Your DBMS should not be concerned with IP infrastructure. Of course that is jus my opinion and I would love to hear what others think.