登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

忆风的博客

http://www.cnblogs.com/dhjdhja

 
 
 

日志

 
 
 
 

sql 事务和try  

2009-11-30 11:38:59|  分类: 数据库 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

--select top 1 * from Zz_zkhjhqd
--select * from AccountBase
begin TRANSACTION
begin try
declare @xiayou uniqueidentifier
declare @shangyou uniqueidentifier
declare @xiayoun nvarchar(100)
declare @shangyoun nvarchar(100)
declare @own uniqueidentifier
declare @ownunit uniqueidentifier
select @xiayou=b.zz_accountid,@shangyou=b.Zz_accountid1,@own=a.OwningUser,@ownunit=a.OwningBusinessUnit from Zz_zjxndxyBase a
join Zz_zjxndxyExtensionBase b on a.Zz_zjxndxyId=b.Zz_zjxndxyId
where a.Zz_zjxndxyId='05b18390-5ddd-de11-935f-001018261d7e'

if(not exists(select a.Zz_zkhjhqdId from Zz_zkhjhqdBase a join Zz_zkhjhqdExtensionBase b on a.Zz_zkhjhqdId=b.Zz_zkhjhqdId where Zz_accountid1=@xiayou and zz_accountid2=@shangyou and OwningUser=@own and a.DeletionStateCode=0))
begin
 print '没有'
 declare @id uniqueidentifier
 select @id=NEWID()
 select @xiayoun=Name from AccountBase where AccountId=@xiayou
 select @shangyoun=Name from AccountBase where AccountId=@shangyou

 INSERT INTO [KYGF_MSCRM].[dbo].[Zz_zkhjhqdBase]
      ([Zz_zkhjhqdId]
      ,[CreatedOn]
      ,[CreatedBy]
      ,[ModifiedOn]
      ,[ModifiedBy]
      ,[OwningUser]
      ,[OwningBusinessUnit]
      ,[statecode]
      ,[statuscode]
      ,[DeletionStateCode]
      ,[ImportSequenceNumber]
      ,[OverriddenCreatedOn]
      ,[TimeZoneRuleVersionNumber]
      ,[UTCConversionTimeZoneCode])

 select @id,[CreatedOn]
      ,[CreatedBy]
      ,[ModifiedOn]
      ,[ModifiedBy]
      ,[OwningUser]
      ,[OwningBusinessUnit]
      ,0 as [statecode]
      ,1 as [statuscode]
      ,[DeletionStateCode]
      ,[ImportSequenceNumber]
      ,[OverriddenCreatedOn]
      ,[TimeZoneRuleVersionNumber]
      ,[UTCConversionTimeZoneCode]
 from Zz_zjxndxyBase where Zz_zjxndxyId='05b18390-5ddd-de11-935f-001018261d7e'

 INSERT INTO [KYGF_MSCRM].[dbo].[Zz_zkhjhqdExtensionBase]
      ([Zz_zkhjhqdId]
      ,[Zz_name]
      ,[Zz_accountid1]
      ,[zz_accountid2])
   VALUES(@id,@xiayoun+' FROM'+@shangyoun,@xiayou,@shangyou)
     
 update AccountExtensionBase set zz_sfsyej=1 where AccountId=@xiayou
end
--select @xiayoun,@shangyoun
COMMIT TRANSACTION
end try
begin catch
ROLLBACK TRANSACTION
print 'error'
SELECT
        ERROR_NUMBER() AS ErrorNumber,
        ERROR_MESSAGE() AS ErrorMessage;
end catch


 

 

  评论这张
 
阅读(688)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018