create PROCEDURE dbo.bb
@begintime datetime,
@endtime datetime
as
begin
while @begintime<dateadd(dd,1,@endtime)
begin
declare @a1 int,@a2 Varchar (50),@b int
select @b=0
declare aa CURSOR
for select GoodsID,StoreID from Fin_StoreDaily01 where RunDate=dateadd(dd,-1,@begintime)
open aa
fetch aa into @a1,@a2
while @@sqlstatus<>2
begin
select @b=(select count(*) from Fin_StoreDaily01 where GoodsID=@a1 and StoreID=@a2 and RunDate=@begintime)
if @b=0
begin
insert into Fin_StoreDaily01 (RunDate,GoodsID,StoreID,AcctType)
select @begintime ,GoodsID,StoreID,AcctType from Fin_StoreDaily01
where RunDate=dateadd(dd,-1,@begintime) and GoodsID =@a1 and StoreID=@a2
end
fetch aa into @a1,@a2
end
close aa
deallocate cursor aa
select @begintime=dateadd(dd,1,@begintime)
end
end
------解决思路----------------------
新人来学习了~~