改成Insert Into table2(字段1,字段2…) value row_dept
什么错误,粘上来看看
--没看到游标的定义语句.以下代码假设在open cur之前你已经正确定义了游标(楼主主要是游标的循环用法不当)
declare @Whs numeric(20)
declare @AccMon varchar(20)
declare @MPick decimal(20,12)
declare @EPick decimal(20,12)
open cur
FETCH next from cur INTO @Whs
while @@FETCH_STATUS=0
BEGIN
select @MPick=sum(j.Amount) from bk_MaterialJnl j ,wm_PickJour p where
p.BillID = j.DocID and p.ItemID = j.ItemID
and p.Type = 'PurPick'
and p.CostItem in(select CostID from pub_CostItem where CostNo like '01%' or CostNo like '02%')
and p.Whs=@Whs and j.AccMon='08'
group by p.Whs, j.AccMon
select @EPick=sum(j.Amount) from bk_MaterialJnl j ,wm_PickJour p where
p.BillID = j.DocID and p.ItemID = j.ItemID
and p.Type = 'PurChecksEquPick'
and p.Whs=@Whs and j.AccMon='08'
group by p.Whs, j.AccMon
insert into aaa (whs,MPick,EPick) values(@Whs ,isnull(@MPick,0),isnull(@Pick,0)))
fetch next from cur into @whs
end
close cur
declarecursor c_dept is select * from table1
where serv_id in (select serv_id from zy_th)
and org_trm_id=0
row_dept c_dept%rowtype
begin
open c_dept
loop
fetch c_dept into row_dept
If c_dept%notfound Then
Exit
End If
Insert Into table2 value row_dept
commit--在这加个提交,插入一条提交一次就OK
end loop
close c_dept
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)