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 编辑过」