查看文章 |
/**//*--字符型 IP 地址转换成数字 IP --邹建 2004.08(引用请保留此信息)--*/ /**//*--调用示例 select dbo.f_IP2Int('192.168.0.11') select dbo.f_IP2Int('12.168.0.1') --*/ CREATE FUNCTION [dbo].[f_IP2Int]( @ip char(15) )RETURNS bigint AS BEGIN DECLARE @re bigint SET @re=0 SELECT @re=@re+LEFT(@ip,CHARINDEX('.',@ip+'.')-1)*ID ,@ip=STUFF(@ip,1,CHARINDEX('.',@ip+'.'),'') FROM( SELECT ID=CAST(16777216 as bigint) UNION ALL SELECT 65536 UNION ALL SELECT 256 UNION ALL SELECT 1)A RETURN(@re) END
/**//*--数字 IP 转换成格式化 IP 地址
-------------------------------- 相关sql语句--注意先删除最后一条 !! select count(*) from ip where id is not null select dbo.f_IP2Int(IP_Begin),id from ip order by id update ip set intb=dbo.f_IP2Int(IP_Begin)
|

