use [ElephantCredit]
go
begin transaction tran_bank;
print '**脚本开始执行!';
declare @tran_error int ,
@negRuleId uniqueidentifier
set @tran_error = 0;
set @negRuleId = (select Id from [ElephantCredit].[dbo].[CreditRules] where [Provider]=N'CREDIT_PROVIDER_OPS' and [Code]=N'OPS_DOCTOR_RULE_N7_N')
begin
declare cursor_credit cursor scroll for
(select CreditId from [ElephantCredit].[dbo].[CreditHistories] where RuleId = @negRuleId
group by CreditId
) open cursor_credit;
declare @CreditId uniqueidentifier,
@FinalCredit int=0,
@OldCredit int=0,
@PeakCredit int=0
fetch first from cursor_credit into @CreditId;
while (@@fetch_status = 0)
begin --0.calculate the final credits/ignore these negative rule records.
set @FinalCredit = (select case when (sum(cast([value] as int)))<0 then 0 else sum(cast([value] as int)) end
from [ElephantCredit].[dbo].[CreditHistories] where CreditId=@CreditId and RuleId != @negRuleId) if (@FinalCredit is null)
BEGIN
--break;
goto _out
end --1.update credits principal using the latest credit
set @OldCredit = (select AvailableValue from [ElephantCredit].[dbo].[Credits] where Id=@CreditId)
set @PeakCredit = (select PeakValue from [ElephantCredit].[dbo].[Credits] where Id=@CreditId) update [ElephantCredit].[dbo].[Credits] set
AvailableValue = @FinalCredit,
UpdatedTime =GETDATE()
where Id=@CreditId
print '---creditId:'+ cast(@CreditId as nvarchar(50)) + ',重置成新积分值:'+ cast(@FinalCredit as varchar) +',旧值:' + cast(@OldCredit as varchar) + ',峰值:' + cast(@PeakCredit as varchar); --2.update groups principal
update [ElephantCredit].[dbo].[Growths] set
[Value] = @FinalCredit,
UpdatedTime =GETDATE()
where ExternalId=(select RefId from [ElephantCredit].[dbo].[Credits] where Id=@CreditId)
print '---成长值同步更新完毕!' ; _out:
fetch next from cursor_credit into @CreditId; end
close cursor_credit;
deallocate cursor_credit; --3.clear all the dirty data
delete from [ElephantCredit].[dbo].[CreditHistories] where RuleId = @negRuleId
print '清理全部脏数据完毕';
end
if (@tran_error > 0)
begin
rollback tran;
print '**脚本执行失败!已回滚';
end
else
begin
commit tran;
print '**脚本执行成功!';
end
go --Helper:
--select * from CreditHistories
--select * from Credits --where Id='9416FEBA-C19F-4718-80D5-F01643D57DE5'
--select * from CreditRules

最新文章

  1. hellocharts折线图与柱状图的上下结合酷炫效果(学习笔记)
  2. 谢欣伦 - OpenDev原创教程 - 网络设备查找类CxNetworkHostFind &amp; CxNetworkAdapterFind
  3. Deep learning:四十八(Contractive AutoEncoder简单理解)
  4. 利用ZTree链接数据库实现 [权限管理]
  5. LinkedList其实就那么一回事儿之源码分析
  6. TFS服务器(微软源代码管理服务器)上彻底删除项目
  7. SR4K的API使用(libMesaSR.dll)
  8. mybatis重拾---部署官方demo
  9. iOS8 UISearchViewController搜索功能讲解
  10. [TJOI 2016&amp;HEOI 2016]排序
  11. python ddt数据驱动(简化重复代码)
  12. pe文件头详解
  13. Sublime Text 3(3207)安装
  14. 《Oracle DBA工作笔记:运维、数据迁移与性能调优》 PDF 下载
  15. 【python】多进程与mongo
  16. webpack4 系列教程(六): 处理SCSS
  17. [Oracle]快速构造大量数据的方法
  18. java之静态方法与非静态方法
  19. DAX/PowerBI系列 - 参数表(Parameter Table) - 大客户分析(Top N)
  20. python实现Excel删除特定行、拷贝指定行操作

热门文章

  1. Linux 多进程实现方法
  2. KVM虚拟化技术(三)KVM环境预配
  3. python 拷贝 深拷贝 浅拷贝 赋值
  4. mysql游标错误
  5. 吴裕雄 python深度学习与实践(1)
  6. 对于目标识别的一些idea-传递特征的position而不是特征或特征图
  7. centos 升级sqlite3
  8. 04_web基础(七)之jsp
  9. 1.3.8、CDH 搭建Hadoop在安装之前(端口---Apache Flume和Apache Solr使用的端口)
  10. 树的子结构(python)