Skip to content

Instantly share code, notes, and snippets.

@imrexhuang
Created March 28, 2016 13:16
Show Gist options
  • Save imrexhuang/e347f242a1286f3d5954 to your computer and use it in GitHub Desktop.
Save imrexhuang/e347f242a1286f3d5954 to your computer and use it in GitHub Desktop.
--參考 https://technet.microsoft.com/zh-tw/library/ms190193(v=sql.105).aspx
--宣告儲存Error的變數
DECLARE @ErrorVar INT
--產生Error
SELECT 6 / 2;
--RAISERROR(N'Message', 16, 1);
--儲存Error
SET @ErrorVar = @@ERROR
IF @ErrorVar = 0
BEGIN
PRINT '執行過程沒有發生錯誤!'+ CHAR(13)+'@ErrorVar:'+CAST(@ErrorVar AS NVARCHAR(8));
END
IF @ErrorVar <> 0
BEGIN
PRINT '執行過程發生錯誤!'+ CHAR(13)+'@ErrorVar:'+CAST(@ErrorVar AS NVARCHAR(8));
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment