2015-07-28 115 views
-1

我与SQL Server 2008 R2的工作,我有一个存储过程,在那里我试图抛出errror掷错误2008 R2

throw 50001, 'Couldnot process,Please verify Transaction ID and EmbossLine', 1 

但查询没有得到执行,并抛出错误50001.它在SQL Server 2012上工作正常。我认为版本存在一些问题。有没有其他方法可以在SQL Server 2008 R2中引发错误?

这是我的存储过程:

Alter procedure [dbo].[spGetRedemption] 
    @pan varchar(19), 
    @transId bigint 
AS 
Begin 
    if EXISTS(select * from POS_Transactions where [email protected]) 
    Begin 
     select 
      PT.ID, PT.TransactionDate, M.MerchantName1, 
      PT.TerminalID, PT.BatchNumber, PT.SequenceNumber, PT.PAN, 
      C.EmbossName, PT.TotalAmount, PT.CurrencyCode, 
      TT.TransactionType, PT.InvoiceNumber 
     from 
      POS_Transactions PT 
     inner join 
      Terminal T on T.TerminalID = PT.TerminalID 
     inner join 
      Merchant M on M.MerchantID = T.MerchantID 
     inner join 
      Card C on C.EmbossLine = PT.PAN 
     inner join 
      TransactionType TT on TT.TransactionTypeID = PT.TransactionTypeID 
     where 
      PT.ID = @transId 
      and PT.PAN = @pan 
    END 
    Else 
    Begin 
     throw 50001, 'Couldnot process,Please verify Transaction ID and EmbossLine', 1 
    END 
End 
+0

发布查询信息? – Haris

+0

@哈里邮政编辑! – Nuke

+2

'Throw'出现在SQL 2012中; '2008年的Raiserror'。https://msdn.microsoft.com/zh-cn/library/ee677615(v=sql.110).aspx – JohnLBevan

回答

2

Throw没有在SQL Server 2008R2可用;它最早是在SQL Server 2012中

https://msdn.microsoft.com/en-us/library/ee677615(v=sql.110).aspx

介绍另一种方法是使用Raiserror(注意;只有1和C在中间,它不是RaiseError)。

从上面的链路,有这些方法之间的一些差异:

RAISERROR语句

如果MSG_ID传递给RAISERROR,该ID必须sys.messages来限定。

msg_str参数可以包含printf格式样式。

严重性参数指定异常的严重性。

throw语句

的ERROR_NUMBER参数没有在sys.messages中定义。

消息参数不接受printf样式格式。

没有严重性参数。例外严重性始终设置为16.