2015-07-28 71 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.