关闭

一个对自己来说有记念意义的事务

983人阅读 评论(0) 收藏 举报
begin tran aa ---
set nocount on
       declare @userid varchar(50) 
       declare @newcourseid varchar(50) 
       declare @newcourseid2 varchar(50) 
       declare @oldcourseid varchar(50)
       declare @subjectid varchar(6)
       declare @choosebook float 
       declare @postwayid   int
       declare @reValue int
       declare @i int
       set @i = 0
       set @reValue = 0
       set @oldcourseid = 'ZK012' --大学语文(第一版)
       set @newcourseid = 'ZK012B'--大学语文(第二版)
 
       declare cur_upgrade cursor for
              select --top 600
              s.userid,left(s.courseid,6) subjectid,s.hasbook,s.postwayid
              from studentcoursesys s
              inner join #temp3 t on s.userid = t.userid and s.courseid = t.courseid
              where right(t.courseid,6)='ZK012A' --order by s.userid
       open cur_upgrade
       fetch next from cur_upgrade into @userid,@subjectid,@choosebook,@postwayid
        while @@fetch_status = 0
        begin
              set @newcourseid2 = cast(@subjectid as varchar(6)) + cast(@newcourseid as varchar(6))
              execute @reValue = sp_change_course @userid,@newcourseid2,@oldcourseid,@choosebook,@postwayid
              if @reValue <>0
              begin
                     goto err
              end
             
              fetch next from cur_upgrade into @userid,@subjectid,@choosebook,@postwayid
              set @i = @i + 1
              print @i
       end
 
goto succ
 
err:
       rollback tran aa
       print cast(@reValue as char(20))+'失败!'    
       print @userid
       print @newcourseid2
       close cur_upgrade
       deallocate cur_upgrade
       return
 
succ:      
       close cur_upgrade
       deallocate cur_upgrade
       print cast(@i as char(5))
       print cast(@reValue as char(20))+'成功!'    
       --commit tran aa
       return
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:162033次
    • 积分:2384
    • 等级:
    • 排名:第15666名
    • 原创:66篇
    • 转载:12篇
    • 译文:0篇
    • 评论:33条
    最新评论
    BLOG链接