判断一个ip地址是否在一个ip范围内
create function f_checkIP(@IP varchar(20),@IP_ST varchar(20),@IP_ED varchar(20))
returns bit as begin
select @IP = right('00'+ParseName(@IP,4),3)+'.'+
right('00'+ParseName(@IP,3),3)+'.'+
right('00'+ParseName(@IP,2),3)+'.'+
right('00'+ParseName(@IP,1),3),
@IP_ST = right('00'+ParseName(@IP_ST,4),3)+'.'+
right('00'+ParseName(@IP_ST,3),3)+'.'+
right('00'+ParseName(@IP_ST,2),3)+'.'+
right('00'+ParseName(@IP_ST,1),3),
@IP_ED = right('00'+ParseName(@IP_ED,4),3)+'.'+
right('00'+ParseName(@IP_ED,3),3)+'.'+
right('00'+ParseName(@IP_ED,2),3)+'.'+
right('00'+ParseName(@IP_ED,1),3)
if (@IP between @IP_ST and @IP_ED)
return 1
return 0
end
go
select dbo.f_checkIP('4.208.48.215','4.43.69.96','4.208.48.255')
select dbo.f_checkIP('4.43.69.95' ,'4.43.69.96','4.208.48.255')
drop function f_checkIPgo