在对金蝶K3二次开发,写一个存储过程时,出现的问题。
具体代码如下:
Create Table #Happen(
FID int IDENTITY,
FDate datetime null,
FGCBillNo nvarchar(255),
FCustName nvarchar(255) null,
FItemID int Null,
FStockID int Null,
FStockPlaceID int Null,
FInQty decimal(28,10),
FUnitWeight decimal(28,10),
FTotalWeight decimal(28,10),
FGCBillQty varchar(255) null,
FTYpe int null)--中间有许多insert into #Happen的语句。执行完后#Happen临时表有5000多条数据。declare @iStart int
declare @iEnd int
declare @iItemID int
declare @iStockID int
declare @iStockPlace int
declare @sGCBillNo nvarchar(255)
set @iStart=(select isnull(min(FID),0) from #Happen where FType=1)
set @iEnd=(select isnull(max(FID),0) from #Happen where FType=1)while not @iStart>@iEnd
begin
select @iItemID=FItemID,@iStockID=FStockID,@iStockPlace=FStockPlaceID,@sGCBillNo=FGCBillNo
from #Happen where FID=@iStart

update t8
set t8.Fdate=t9.FDate, t8.FUnitWeight=t9.FUnitWeight, t8.FGCBillQty=t9.FGCBillQty,                 --第1070行数据,执行到这里的时候出现将 varchar 转换为数据类型 numeric 时发生算术溢出错误 t8.FTotalWeight=(isnull(t9.FUnitWeight,0)*isnull(t8.FInQty,0))/1000 from #Happen t8
left join (select top 1 * from (

select t1.FDate,

(case t1.FTranType when 2 then t2.FEntrySelfA0246 when 5 then t2.FEntrySelfA0552 when 41 then 
t2.FEntrySelfD0152 when 40 then t2.FEntrySelfC0137 when 10 then t2.FEntrySelfA9744 else 0 end) as FUnitWeight, (case t1.FTranType when 2 then t2.FEntrySelfA0245 when 5 then t2.FEntrySelfA0549 else 0 end) as FGCBillQty 
from ICStockBillEntry t2
Inner Join ICStockBill t1 on t1.FInterID=t2.FInterID
where t1.FStatus>0 And t1.FCancelLation=0
and ((t1.FTranType=2 and t2.FEntrySelfA0237=@sGCBillNo) or (t1.FTranType=41 and t2.FEntrySelfD0146=@sGCBillNo)
 or t1.FTranType not in (2,41))
and t2.FItemID=@iItemID and t2.FDCStockID=@iStockID
and t2.FDCSPID=@iStockPlace and isnull(t1.FDate,'1900-01-01')>=@StockStartDate and isnull(t1.FDate,'1900-01-01')<=@StockInDate
union all(select t1.FStockInDate,t1.FPerWeight,t1.FWkQty from WincoInvInitial t1
where isnull(t1.FStockInDate,'1900-01-01')>=@StockStartDate and isnull(t1.FStockInDate,'1900-01-01')<=@StockInDate and t1.FItemID=@iItemID and t1.FStockID=@iStockID and t1.FStockPlaceID=@iStockPlace and FWkNo=@sGCBillNo
)
) t88 order by FDate
) t9 on 1=1
where FID=@iStart

set @iStart=@iStart+1
end
注:FEntrySelf******这些是自定义字段。出错误那一行的时候t1.FTranType=2,FEntrySelfA0245 =301
请知道的大虾,帮帮忙!
还需要知道什么,可能跟贴问。

解决方案 »

  1.   

    超过了 numeric  的范围什么数据啊,这么大??
      

  2.   

    cast(case t1.FTranType when 2 then t2.FEntrySelfA0245 when 5 then t2.FEntrySelfA0549 else 0 end as varchar) as FGCBillQty  
      

  3.   

    在t9子查询结果集里面,加上以下条件:and isnumeric(t2.FEntrySelfC0137=1
    and isnumeric(t2.FEntrySelfA974)=1
    and isnumeric(t2.FEntrySelfA0245)=1
    and isnumeric(t2.FEntrySelfA0549)=1
      

  4.   

    在ACCESS中,有没有办法与K3实现链接?