• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
百里丶落云
Gee,gee,baby,baby
            管理     
sql sever 常见游标写法,及如何强制停止

declare @lot_msg varchar(255)      ,
      @ant int
/*select  @lot_msg =predoccode from propurdadiplanhd        
where  docdate>'2020-07-01'*/
      
 DECLARE cur1 CURSOR FOR select  predoccode from propurdadiplanhd        
where  docdate>@datetime1

OPEN cur1                                                                
  FETCH   NEXT  FROM cur1 INTO  @lot_msg    



   WHILE(@@FETCH_STATUS = 0 )                                                                
  BEGIN                   
     SET @ant = ISNULL(@ant,0) + 1          

declare @lot Nvarchar(1000)  declare @begin_date  datetime      
declare @time_date varchar(244)     
set @lot= ' SELECT  top 1 @begin_Date=begin_Date FROM OPENQUERY(orc_link'+','  +''''+'select * from ps_schedule_head where lot_no=' +''''+'''' +@lot_msg+''''+''''+    
''''+')'       
exec sp_executesql @lot ,N'@begin_date  datetime  output',    
@begin_date output    
print(@begin_date)  select   @time_date=   convert(datetime,replace(replace(replace(@begin_date,'年', '-'),'月','-'),'日',''))      
      
 update propurdadiplanitem  set      
 chengxinjindu =@time_date        
 from  propurdadiplanitem a inner join propurdadiplanhd  b on a.doccode =b.doccode 
 
 where isnull(chengxinjindu,'') !=''  and b.predoccode =@lot_msg 



IF  @ant  >= 1000                  
  BEGIN                  
     BREAK                   
  END    
    FETCH   NEXT  FROM  cur1  INTO @lot_msg                  
  END                  
  CLOSE  cur1                  
  DEALLOCATE  cur1           

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

红色部分为固定

黑色部分为变更内容 

年与时驰,意与日去,遂成枯落, 多不接世,悲守穷庐,将复何及。
posted on 2020-07-22 09:33  百里丶落云  阅读(795)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3