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. bodyParser注意“需要请求头的支持”

    bodyParser 支持此类参数解析. 注意: 在提交之前需要指定http 请求头为 content-type=application/json 代码如下: var express = requir ...

  2. C# Dictionary几种遍历方式

    class Program { static void Main(string[] args) { Dictionary<string, string> myDictionary = ne ...

  3. Is Anchor magento

    如何在magento分类页的Layered Navigation中可以用magento后台已有的attributes进行筛选. 首先,进入后台 Catalog > Manage Categori ...

  4. 【转】shell脚本中echo显示内容带颜色

    shell脚本中echo显示内容带颜色显示,echo显示带颜色,需要使用参数-e.格式如下:   echo -e "\033[41;36m something here \033[0m&qu ...

  5. imx6 RGB LCD

    imx6dl需要支持lcd接口的屏,imx6dl的datasheet并没有明确的说明lcd相关的配置,只在Display Content Integrity Checker (DCIC)一章中介绍.本 ...

  6. gulp教程

    1. http://www.tuicool.com/articles/FJVNZf 2.http://www.ydcss.com/archives/18 3.手动创建package.json: 如:c ...

  7. SQL-用JOIN连接多个表

    select * from table1 inner join table2 on table1.id=table2.id     其实 INNER JOIN --ON的语法格式可以概括为:      ...

  8. iOS:iOS开发非常全的三方库、插件等等

    iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...

  9. Inside Kolla - 01 简介

    简介 在 opencloud 2015 的会议上初次了解到 kolla 项目后,开始去了解和学习 kolla 的源代码和相关的知识.经过一段时间的了解,觉得 kolla 确实是一个很好的项目,它使用预 ...

  10. C# --2007Access链接字符串

    public static string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDi ...