bigint的长度为8个字节,共64位,能够存储-263~263-1之间的所有数字
这个长度还不够?那就用decimal吧decimal(p, s)。
其中:p:为指定精度或对象能够控制的数字个数。
s:为指定可放到小数点右边的小数位数或数字个数。
p和s必须遵守以下规则:0 <= s <= p <= 38

解决方案 »

  1.   

    bigint
    长度为 8 个字节,存储从 –2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,372,036,854,775,807) 的数字。 
    怎么还会溢出呢?
      

  2.   

    把你如何转化的贴出来看看。
    为何要把IP转化成bigint呢?而不转成字段串格式呢。
      

  3.   

    declare @s dec(38,0)
    set @s=power(cast(256 as dec(38,0)),4)+power(cast(256 as dec(38,0)),3)+power(cast(256 as dec(38,0)),2)+power(cast(256 as dec(38,0)),1)
    select @s---------------------------------------- 
    4311810304(所影响的行数为 1 行)declare @s dec(38,0)
    set @s=power(cast(256 as dec(38,0)),4)+power(cast(256 as dec(38,0)),4)+power(cast(256 as dec(38,0)),4)+power(cast(256 as dec(38,0)),4)
    select @s
    ---------------------------------------- 
    17179869184(所影响的行数为 1 行)
      

  4.   

    --用这两个函数相互转换吧.if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_IP2Int]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[f_IP2Int]
    GO--1. 字符串IP地址转换成IP数值函数。
    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
    GO
    /*===========================================================*/
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Int2IP]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[f_Int2IP]
    GO--1. 字符串IP地址转换成IP数值函数。
    CREATE FUNCTION dbo.f_Int2IP(
    @IP bigint
    )RETURNS varchar(15)
    AS
    BEGIN
    DECLARE @re varchar(15)
    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