您的位置: 龙岩金蝶软件论坛 -> 企业管理软件区域 -> 数据库 -> 游标
本帖共有642个阅读者
发表帖子 发表投票 回复主题
游标
尊贵身份标志
cyy275(管理员)
cyy275
头衔:社区公民
帮派:无帮无派
帖数:497
金钱:100000
积分:2248
注册时间:2017-5-8
楼主信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
游标

declare @fbillno  varchar(100)
declare @fnumber  varchar(100)
declare @famount decimal(18,2)
declare @fnote varchar(100)
declare @fid int
declare @fentryid int


DECLARE my_Cursor
CURSOR FOR (select fid,fbillno,fnumber,famount,FNOTE from t_cyyc where fbillno='SOUT000253')
OPEN My_Cursor;  
FETCH NEXT FROM My_Cursor into @fid,@fbillno,@fnumber,@famount,@fnote;
WHILE @@FETCH_STATUS = 0
BEGIN  


select @fentryid=max(fentryid) from icstockbill join icstockbillentry on icstockbill.finterid=icstockbillentry.finterid join t_icitem on t_icitem.fitemid=icstockbillentry.fitemid
where icstockbill.fbillno=@fbillno and t_icitem.fnumber=@fnumber and icstockbillentry.famount=@famount and icstockbillentry.fnote='' group by fnumber


if (select max(fentryid) from icstockbill join icstockbillentry on icstockbill.finterid=icstockbillentry.finterid join t_icitem on t_icitem.fitemid=icstockbillentry.fitemid
where icstockbill.fbillno=@fbillno and t_icitem.fnumber=@fnumber and icstockbillentry.famount=@famount and icstockbillentry.fnote='' group by fnumber)>0
begin
update icstockbillentry
set fnote=@fnote
from icstockbillentry
join icstockbill on icstockbillentry.finterid=icstockbill.finterid
join t_icitem on t_icitem.fitemid=icstockbillentry.fitemid
where icstockbill.fbillno=@fbillno and icstockbillentry.famount=@famount and t_icitem.fnumber=@fnumber and icstockbillentry.fnote='' and fentryid=@fentryid


insert into t_cyyB
select * from t_cyy where fid=@fid

end
else
begin

insert into t_cyya
select * from t_cyy where fid=@fid


end

FETCH NEXT FROM My_Cursor into @fid,@fbillno,@fnumber,@famount,@fnote;  
End
CLOSE My_Cursor;  
DEALLOCATE My_Cursor;  




「该帖子被 cyy275 在 2021/2/4 18:01:44 编辑过」

今天的努力,明天的享受!
今天的无为,明天的无助!
今天的迷茫,明天的受累!
等级:管理员 参考IP地址:*.*.*.*
2019-12-16 21:12:17
Powered by 金蝶论坛 Copyright © 2011 www.xxhcom.cn. All rights reserved.