专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 高性能数据库开发

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

发布时间:2010-05-24 21:16:25 文章来源:www.iduyao.cn 采编人员:星星草
存储过程有点慢,帮忙看下怎么优化

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

------解决思路----------------------
新人来学习了~~
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: