sql set xact_abort on 用例
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 用例的更多相关文章
- 嗅探、中间人sql注入、反编译--例说桌面软件安全性问题
嗅探.中间人sql注入.反编译--例说桌面软件安全性问题 今天这篇文章不准备讲太多理论,讲我最近遇到的一个案例.从技术上讲,这个例子没什么高深的,还有一点狗屎运的成分,但是它又足够典型,典型到我可以讲 ...
- [读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例
这是我的文章备份,原始出处:[读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例 http://www.dotblogs.com.tw/mis2000lab/archive/ ...
- 电子商务网站SQL注入项目实战一例
故事A段:发现整站SQL对外输出: 有个朋友的网站,由于是外包项目,深圳某公司开发的,某天我帮他检测了一下网站相关情况. 我查看了页面源代码,发现了个惊人的事情,竟然整站打印SQL到Html里,着实吓 ...
- SQL窗体函數一例
需求: MSSQL,列出服務實例中全部數據庫的例如以下信息: 數據庫ID.數據庫名.創建日期.數據文件類型.數據文件大小.數據庫總大小.文件所在路徑. 寫法(後面的百分比為所花時間占比): -- 连接 ...
- 电子商务网站SQL注入项目实战一例(转载)
故事A段:发现整站SQL对外输出: 有个朋友的网站,由于是外包项目,深圳某公司开发的,某天我帮他检测了一下网站相关情况. 我查看了页面源代码,发现了个惊人的事情,竟然整站打印SQL到Html里,着实吓 ...
- SQL事务回滚样例
选课系统,当同意学号选课数量超过则回滚事务,符合条件则正常插入数据 --开始一个事务处理Begin Tran T1 --执行插入操作insert into Courselist values('201 ...
- SQL游标 数据库编程样例
--处理file与folder中的order -- 声明变量 DECLARE @fileid AS INT, @folderid AS INT, @order AS INT, @oldFolderId ...
- SQL语句优化方法30例
1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化. 例如: SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_I ...
- 高级SQL运用
一:什么是数据库设计? 数据库设计就是将数据库中的数据实体以及这些数据实体之间的关系,进行规范和结构化的过程. 二:为什么要实施数据库设计? 1:良好的数据库设计可以有效的解决数据冗余的问题 2:效率 ...
随机推荐
- C#访问url地址并返回数据
public partial class Form1 : Form { static bool isSelect = false; public Form1() { InitializeCompone ...
- Android笔记:string-array数据
把相应的数据放到values文件夹的arrays.xml文件里 String数组 <?xml version="1.0" encoding="utf-8" ...
- Almost Sorted Array---hdu5532(简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5532 题意:问一个含有n个数的序列,删除一个数后是否有序(递增或递减都可以) 我们只要求一下最长上升子 ...
- VMware中CentOS设置静态IP
因为之前搭建的MongoDB分片没有采用副本集,最近现网压力较大,所以准备研究一下,于是在自己电脑的虚拟机中搭建环境,但是发现之前VMware设置的是DHCP,所以每次重新resume后虚拟机中IP都 ...
- WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.
我当初安装sql server的时候选的Window Authentication mode,没选SQL Server Windows Authentication. 后来做WPF时连接数据库时需要一 ...
- TortoiseGit使用与操作
使用 Git命令有时候确实不怎么方便,特别是每次都要输入密码,如果配置 SSH 的方式,又实在是很麻烦.(当然,必须使用 Windows 神器才有方便友好的客户端图形界面啦!!!) 1.克隆项目 打开 ...
- AWK只打印某个域后的所有域
如转载请指明(博客http: yangzhigang cublog cn).前言:有时我们需要将某个域之后的所有域打印出来,而且每个记录(行)的域的个数也不一定,所以用$4,$5,… $n,… $(N ...
- MEF 松耦合
MEF天生就有解耦合的特性,虽然它不是为解耦而生,而主要是为插件类应用的开发而设计.如果主要是为了解除耦合的话可以使用IoC,Unity等. Unity 微软的IOC 代码: using System ...
- VMware (威睿) 虚拟化产品简介
VMware vSphere 是VMware(威睿)的一个虚拟化产品,VMware vSphere 是业界领先且最可靠的虚拟化平台.vSphere将应用程序和操作系统从底层硬件分离出来,从而简化了 I ...
- python使用zlib实现压缩与解压字符串
命令 字符串:使用zlib.compress可以压缩字符串.使用zlib.decompress可以解压字符串. 数据流:压缩:compressobj,解压:decompressobj 案例 >& ...