IP Int 转 Char

USE [UILogDB]
GO
/****** Object:  UserDefinedFunction [dbo].[ipBigIntToString]    Script Date: 11/09/2011 09:46:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[ipBigIntToString] ( @ip bigint ) 
	RETURNS CHAR(15) 
	AS 
	BEGIN 
	DECLARE @o1 INT, @o2 INT, @o3 INT, @o4 INT IF @ip > 4294967295 
	RETURN '255.255.255.255' 
	IF @ip <= 0 RETURN '0.0.0.0' 
	SET @o1 = @ip / 16777216 
	SET @ip = @ip % 16777216 
	SET @o2 = @ip / 65536 
	SET @ip = @ip % 65536 
	SET @o3 = @ip / 256 
	SET @ip = @ip % 256 
	SET @o4 = @ip 
	RETURN CONVERT(VARCHAR(4), @o1) + '.' + CONVERT(VARCHAR(4), @o2) + '.' + CONVERT(VARCHAR(4), @o3) + '.' + CONVERT(VARCHAR(4), @o4) 
END


你可能感兴趣的:(char)