declare @fsupid int,@fitemid int,@funitid int,@fprice decimal(18,10),@fptype int,@fentryid int,@icount int
set @icount = 1
declare my_select cursor for select fsupid,fitemid,funitid,fprice,fptype,fentryid from t_supplyentry where fused=0
open my_select
fetch next from my_select into @fsupid,@fitemid,@funitid,@fprice,@fptype,@fentryid
while @@fetch_status=0
begin
if (select count(1) as counts from t_supplyentry where fsupid=@fsupid and fitemid=@fitemid and funitid=@funitid and fprice=@fprice and fptype=@fptype and fused=0)=1
begin
update t_supplyentry set fused=1 where fentryid=@fentryid
set @icount = @icount + 1
end
else
begin
if @icount=1
begin
if object_id(N'tempdb.dbo.#my_table') is not null begin drop table #my_table end
select * into #my_table from t_supplyentry where fsupid=@fsupid and fitemid=@fitemid and funitid=@funitid and fprice=@fprice and fptype=@fptype and fused=0
end
else
begin
insert into #my_table (fbrno,fsupid,fitemid,fentryid,funitid,fstartqty,fendqty,fprice,fcyid,fdiscount,fleadtime,fquotetime,fused,fdisabledate,fremark,fptype,flastmodifieddate,flastmodifiedby) select * from t_supplyentry where fsupid=@fsupid and fitemid=@fitemid and funitid=@funitid and fprice=@fprice and fptype=@fptype and fused=0
end
end
fetch next from my_select into @fsupid,@fitemid,@funitid,@fprice,@fptype,@fentryid
end
select * from #my_table
drop table #my_table
close my_select
deallocate my_select
print '共审核'+cast(@icount as varchar)+'行数据'