SQL版整数转IP

/*--调用示例 

   

  select dbo.f_Int2IP(4294967295)  

  select dbo.f_Int2IP(212336641)  

--*/  

CREATE FUNCTION f_Int2IP

(

    @IP BIGINT

)

RETURNS VARCHAR(15)

AS

BEGIN

    DECLARE @re VARCHAR(16)  

    SET @re = ''  

    SELECT @re = @re+'.'+CAST(@IP/ID AS VARCHAR), @IP = @IP%ID

    FROM (

             SELECT ID = CAST(16777216 AS BIGINT)

             UNION ALL   SELECT 65536

             UNION ALL   SELECT 256

             UNION ALL   SELECT 1

         )a

    RETURN(STUFF(@re, 1, 1, ''))

END  

GO

你可能感兴趣的:(sql)