[英]customize an error message in SQL server 2008 R2 on win 7
我需要在Win 7上的SQL Server 2008 R2中自定義錯誤消息(不支持throw)。
BEGIN TRY
DECLARE @result INT
SET @result = LOG(-1)
END TRY
BEGIN CATCH
EXEC sys.sp_addmessage 60000, 16, 'log() argument is not positive'
RAISERROR (60000, 16, 1)
END CATCH
但是,結果總是相同的:
An invalid floating point operation occurred.
謝謝
您可以通過對Log參數使用變量來解決此問題:
DECLARE @result INT
DECLARE @insidelog INT = -1
IF @insidelog < 0
BEGIN
EXEC sys.sp_addmessage 60000, 16, 'log() argument is not positive'
RAISERROR (60000, 16, 1)
END
ELSE
BEGIN
SET @result = LOG(@insidelog)
END
我認為您無論如何都要將該數字作為變量傳遞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.