当前位置: 代码迷 >> 高性能数据库开发 >> 存储过程有点慢,帮忙看下如何优化
  详细解决方案

存储过程有点慢,帮忙看下如何优化

热度:8025   发布时间:2013-02-26 00:00:00.0
存储过程有点慢,帮忙看下怎么优化
SQL code
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


------解决方案--------------------------------------------------------
新人来学习了~~
  相关解决方案