set xact_abort on

设置事务回滚的
当为ON时,如果你存储中的某个地方出了问题,整个事务中的语句都会回滚
OFF时,只回滚错误的地方 例子 : ALTER proc [dbo].[BuChongZhaiQuan_SQl] as
begin
set xact_abort on
begin transaction
--if exists(select 1 from InvestorApply where RedeemDate=(select ShouldPayDate=max(ShouldPayDate) from ActualRedemptionIncome) and CheckState=9)
if exists(select 1 from InvestorApply where CheckState=9 and DeleteState=0)
--if(1<>1)
print '暂不补充比例'
else
begin
print '执行补充比例,第一步' insert into NewBuChong
select ApplicationID,ststus=0, REPLACE(CONVERT (VARCHAR(100),getdate(),23),'-',''),getdate()
--,ttt.真实匹配比例 ,TTT.LoanDate
from tb_sanbiao_20160215_InvestorApplyID end
if(@@error<>0)
begin
select 'Error'
rollback tran
return;
end
else
begin
commit;
select 'OK'
end
end

ALTER  proc  [dbo].[BuChongZhaiQuan_SQl]
as beginset xact_abort on  begin transaction--if exists(select 1 from InvestorApply where RedeemDate=(select ShouldPayDate=max(ShouldPayDate) from ActualRedemptionIncome) and CheckState=9)if exists(select 1 from InvestorApply where  CheckState=9 and DeleteState=0)--if(1<>1)print '暂不补充比例'else beginprint '执行补充比例,第一步'
insert  into NewBuChong select ApplicationID,ststus=0, REPLACE(CONVERT (VARCHAR(100),getdate(),23),'-',''),getdate()--,ttt.真实匹配比例 ,TTT.LoanDatefrom (select tt.ApplicationID,tt.LoaneeName '借款人姓名', SUM(tt.LoanMatchRatio) as '真实匹配比例',TT.LoanDate  from (select b.LoanMatchRatio,a.ApplicationID,a.LoaneeName,A.LoanDatefrom Loanee as aleft join LoanMatchDetails as b on b.LoaneeID=a.ID--left join LoanMatch as c on b.LoanMatchID=c.IDleft join InvestorApplyDetails as d on b.InvestorApplyDetailsID=d.IDleft join InvestorApply as e on d.InvestorApplyID=e.IDleft join LoaneeExpand as f on a.ID=f.LoaneeIDleft join Investor as i on e.InvestorID=i.IDwherea.LoanDate>'1900-01-01'and f.transferIsorNo='Y'----and  a.AddTime<'2015-11-01'----and --and --a.ApplicationID in (

--)anda.LoaneeType=0 and a.DeleteState=0 and d.DeleteState=0 and e.DeleteState=0 and i.DeleteState=0 and e.CheckState in (3)and e.InvestorApplyType<>2and Status=0
)tt   group by ApplicationID,LoaneeName ,LoanDate--,真实匹配比例  --having '真实匹配比例'<>1 ;  
)  ttt  where  ttt.真实匹配比例<1 -- abs(1-ttt.真实匹配比例)>0.00000001print '第2步'select ApplicationID,realRatio into #t  from (select tt.ApplicationID,tt.LoaneeName '借款人姓名', SUM(tt.LoanMatchRatio) as realRatio  from (select b.LoanMatchRatio,a.ApplicationID,a.LoaneeNamefrom Loanee as aleft join LoanMatchDetails as b on b.LoaneeID=a.IDleft join InvestorApplyDetails as d on b.InvestorApplyDetailsID=d.IDleft join InvestorApply as e on d.InvestorApplyID=e.IDleft join LoaneeExpand as f on a.ID=f.LoaneeIDleft join Investor as i on e.InvestorID=i.IDwherea.LoanDate>'1900-01-01'and f.transferIsorNo='Y'--and  a.AddTime<'2015-11-01'
and a.ApplicationID in (select  ApplicationID  from NewBuChong   where  ststus=0 and  PiCi= REPLACE(CONVERT (VARCHAR(100),getdate(),23),'-',''))anda.LoaneeType=0 and a.DeleteState=0 and d.DeleteState=0 and e.DeleteState=0 and i.DeleteState=0 and e.CheckState in (3)and e.InvestorApplyType<>2and Status=0
)tt   group by ApplicationID,LoaneeName --,真实匹配比例  --having '真实匹配比例'<>1 ;  
)  ttt   where  abs(1-ttt.realRatio)>0.00000001
 print '第3步' update Loanee set MatchRatio = t2.realRatio ,SurplusMatchRatio=1-t2.realRatio,UpdateTime=GETDATE()from Loanee t1,#t t2 where t1.ApplicationID = t2.ApplicationID  and  t1.DeleteState=0  and  t1.LoaneeType=0
print '第4步';with cte as (select a.* from Loanee a right join #t b on  a.ApplicationID=b.ApplicationID and LoaneeType=0 and DeleteState=0)insert into LoanMatchDetails select 2818693,cte.id,0,1, GETDATE(),cte.SurplusMatchRatio,-1,0 ,GETDATE(),29452866,1,newid() from cte
print '第5步';with cte as (select a.* from Loanee a right join #t b on  a.ApplicationID=b.ApplicationID and LoaneeType=0 and DeleteState=0)update Loanee set SurplusMatchRatio=0 ,MatchRatio= 1 where ID in( select ID from cte )
print '第6步'UPDATE  NewBuChong  SET  ststus=2   where     ststus=0  and  ApplicationID in (select ApplicationID from  #t)end 
if(@@error<>0)beginselect 'Error'rollback tranreturn;endelsebegincommit;select 'OK'endend

sql set xact_abort on 用例的更多相关文章

  1. 嗅探、中间人sql注入、反编译--例说桌面软件安全性问题

    嗅探.中间人sql注入.反编译--例说桌面软件安全性问题 今天这篇文章不准备讲太多理论,讲我最近遇到的一个案例.从技术上讲,这个例子没什么高深的,还有一点狗屎运的成分,但是它又足够典型,典型到我可以讲 ...

  2. [读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例

    这是我的文章备份,原始出处:[读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例 http://www.dotblogs.com.tw/mis2000lab/archive/ ...

  3. 电子商务网站SQL注入项目实战一例

    故事A段:发现整站SQL对外输出: 有个朋友的网站,由于是外包项目,深圳某公司开发的,某天我帮他检测了一下网站相关情况. 我查看了页面源代码,发现了个惊人的事情,竟然整站打印SQL到Html里,着实吓 ...

  4. SQL窗体函數一例

    需求: MSSQL,列出服務實例中全部數據庫的例如以下信息: 數據庫ID.數據庫名.創建日期.數據文件類型.數據文件大小.數據庫總大小.文件所在路徑. 寫法(後面的百分比為所花時間占比): -- 连接 ...

  5. 电子商务网站SQL注入项目实战一例(转载)

    故事A段:发现整站SQL对外输出: 有个朋友的网站,由于是外包项目,深圳某公司开发的,某天我帮他检测了一下网站相关情况. 我查看了页面源代码,发现了个惊人的事情,竟然整站打印SQL到Html里,着实吓 ...

  6. SQL事务回滚样例

    选课系统,当同意学号选课数量超过则回滚事务,符合条件则正常插入数据 --开始一个事务处理Begin Tran T1 --执行插入操作insert into Courselist values('201 ...

  7. SQL游标 数据库编程样例

    --处理file与folder中的order -- 声明变量 DECLARE @fileid AS INT, @folderid AS INT, @order AS INT, @oldFolderId ...

  8. SQL语句优化方法30例

    1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化. 例如: SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_I ...

  9. 高级SQL运用

    一:什么是数据库设计? 数据库设计就是将数据库中的数据实体以及这些数据实体之间的关系,进行规范和结构化的过程. 二:为什么要实施数据库设计? 1:良好的数据库设计可以有效的解决数据冗余的问题 2:效率 ...

随机推荐

  1. python 十进制 十六进制

    把十六进制的字串转为十进制数字:>>> print int('ff', 16)   255 把十进制数字转换为以十六进制表示之字串,可调用内置的hex()函数:>>> ...

  2. Dlib is a modern C++ toolkit(非常全面的类库)

    http://dlib.net/ http://download.csdn.net/detail/lajuedan2508/9726225 http://download.csdn.net/detai ...

  3. 自己写的一个DirectUI库,基础控件基本都已实现

    http://download.csdn.net/detail/pcradio/9254881 http://blog.csdn.net/pcradio

  4. 安装Postman

    原文地址:http://blog.csdn.net/ouyang111222/article/details/45743831 ** (一)安装篇 ** Postman是一款功能强大的网页调试与发送网 ...

  5. 使用for打印小九九

    使用shell的for语法打印小九九 #!/bin/bash `;do `;do if [ $a -ge $b ];then echo -en "$a x $b = $(expr $a \* ...

  6. C语言课本实例

    1. 将一维数组的内容倒顺 #include <stdio.h>void func(int *s,int n){ int i,temp; for(i=0;i<n/2;i++) { t ...

  7. UIScorlView 循环滚动

    - (void) createAdScrollView { _view = [[UIView alloc] initWithFrame:CGRectMake(, , WIDTH, )]; [self. ...

  8. C# 读取app.config配置文件节点键值,提示"配置系统未能初始化" 错误的解决方案

    MSDN里写到, 如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素. 将自己添加的appSettin ...

  9. HashMap put,get操作

    HashMap中的put方法 public V put(K key, V value) { //当key为null,调用putForNullKey方法,保存null与table第一个位置中,这是Has ...

  10. 第十一篇 Integration Services:日志记录

    本篇文章是Integration Services系列的第十一篇,详细内容请参考原文. 简介在前一篇,我们讨论了事件行为.我们分享了操纵事件冒泡默认行为的方法,介绍了父子模式.在这一篇,我们会配置SS ...