我的存储函数如下:
CREATE PROC sp_车票信息添加
@checi varchar(20),
@yingzuo int,
@yingzuo_chexiang int,
@wopu_shang int,
@wopu_shang_chexiang int,
@wopu_zhong int,
@wopu_zhong_chexiang int,
@wopu_xia int,
@wopu_xia_chexiang int,
@ruanwo_shang int,
@ruanwo_shang_chexiang int,
@ruanwo_xia int,
@ruanwo_xia_chexiang int,
@guanliyuan int
AS
Begin 
    Declare @operate_time datetime,
            @yingzuo_rest int,
            @wopu_shang_rest int,
            @wopu_zhong_rest int,
            @wopu_xia_rest int,
            @ruanwo_shang_rest int,
            @ruanwo_xia_rest int
            
    set @operate_time=Getdate()
    set @yingzuo_rest=@yingzuo*@yingzuo_chexiang
    set @wopu_shang_rest=@wopu_shang*@wopu_shang_chexiang
    set @wopu_zhong_rest=@wopu_zhong*@wopu_zhong_chexiang
    set @wopu_xia_rest=@wopu_xia*@wopu_xia_chexiang
    set @ruanwo_shang_rest=@ruanwo_shang*@ruanwo_shang_chexiang
    set @ruanwo_xia_rest=@ruanwo_xia*@ruanwo_xia_chexiang
           
       Insert Into 车票信息 
                        (硬座剩余,
                         硬座车厢数,
                         每节车厢硬座数,
                         卧铺上剩余,
                         卧铺上车厢数,
                         每节车厢卧铺上数,
                         卧铺中剩余,
                         卧铺中车厢数,
                         每节车厢卧铺中数,
                         卧铺下剩余,
                         卧铺下车厢数,
                         每节车厢卧铺下数,                         
                         软卧上剩余,
                         软卧上车厢数,
                         每节车厢软卧上数,
                         软卧下剩余,
                         软卧下车厢数,
                         每节车厢软卧下数,
                         是否管理员操作,
                         操作时间)     
                 Values (@yingzuo_rest,
                         @yingzuo,
                         @yingzuo_chexiang,
                         @wopu_shang_rest,
                         @wopu_shang,
                         @wopu_shang_chexiang,
                         @wopu_zhong_rest,
                         @wopu_zhong,
                         @wopu_zhong_chexiang,
                         @wopu_xia_rest,
                         @wopu_xia,
                         @wopu_xia_chexiang,
                         @ruanwo_shang_rest,
                         @ruanwo_shang,
                         @ruanwo_shang_chexiang,
                         @ruanwo_xia_rest,
                         @ruanwo_xia,
                         @ruanwo_xia_chexiang,
                         @guanliyuan,
                         @operate_time)
END
GO

解决方案 »

  1.   

    在DELPHI中的语句如下:
    StoredProc1.Prepare;
    StoredProc1.ParamByName('@checi').AsString:=Edit12.text;
    StoredProc1.ParamByName('@yingzuo').AsInteger:=Integer(Edit1.Text);
    StoredProc1.ParamByName('@yingzuo_chexiang').AsInteger:=Integer(Edit2.Text);
    StoredProc1.ParamByName('@wopu_shang').AsInteger:=Integer(Edit4.Text);
    StoredProc1.ParamByName('@wopu_shang_chexiang').AsInteger:=Integer(Edit3.Text);
    StoredProc1.ParamByName('@wopu_zhong').AsInteger:=Integer(Edit5.Text);
    StoredProc1.ParamByName('@wopu_zhong_chexiang').AsInteger:=Integer(Edit3.Text);
    StoredProc1.ParamByName('@wopu_xia').AsInteger:=Integer(Edit6.Text);
    StoredProc1.ParamByName('@wopu_xia_chexiang').AsInteger:=Integer(Edit3.Text);
    StoredProc1.ParamByName('@ruanwo_shang').AsInteger:=Integer(Edit10.Text);
    StoredProc1.ParamByName('@ruanwo_shang_chexiang').AsInteger:=Integer(Edit9.Text);
    StoredProc1.ParamByName('@ruanwo_xia').AsInteger:=Integer(Edit11.Text);
    StoredProc1.ParamByName('@ruanwo_xia_chexiang').AsInteger:=Integer(Edit9.Text);
    StoredProc1.ParamByName('@guanliyuan').AsInteger:=1;
    StoredProc1.ExecProc;
    可是说在SQL SERVER中,类型转换到INT的时候出现算术溢出.您看是那里的错误:-)
      

  2.   

    应该是下面几句的值出问题了
        set @yingzuo_rest=@yingzuo*@yingzuo_chexiang
        set @wopu_shang_rest=@wopu_shang*@wopu_shang_chexiang
        set @wopu_zhong_rest=@wopu_zhong*@wopu_zhong_chexiang
        set @wopu_xia_rest=@wopu_xia*@wopu_xia_chexiang
        set @ruanwo_shang_rest=@ruanwo_shang*@ruanwo_shang_chexiang
        set @ruanwo_xia_rest=@ruanwo_xia*@ruanwo_xia_chexiang
      

  3.   

    存储过程里这么多计算不知道和不合适,我觉得计算不是它的长项,他的int型有时候会不够用要是我就会放在程序里计算
      

  4.   

    我把INT改成BIGINT了,计算溢出是没有了,可是为什么我的数据这么大呢?
    StoredProc1.ParamByName('@yingzuo').AsInteger:=Integer(Edit1.Text);
    StoredProc1.ParamByName('@yingzuo_chexiang').AsInteger:=Integer(Edit2.Text);
    在存储函数中其实就是这两个Integer(Edit.text)的积,我分别输入8,120结果却是一个十几位的数!!
      

  5.   

    StoredProc1.ParamByName('@yingzuo').AsInteger:=strtoint(trim(edit1.text))
    StoredProc1.ParamByName('@yingzuo_chexiang').AsInteger:=strtoint(trim(edit1.text));
    这样试试!