Skip to content

Instantly share code, notes, and snippets.

@imrexhuang
Created March 28, 2016 13:09
Show Gist options
  • Save imrexhuang/5734270e9f4ad68fdf61 to your computer and use it in GitHub Desktop.
Save imrexhuang/5734270e9f4ad68fdf61 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 / 0;
--RAISERROR(N'Message', 16, 1);
--儲存Error
SET @ErrorVar = @@ERROR
IF @ErrorVar <> 0
BEGIN
--PRINT N'Error = ' + CAST(@ErrorVar AS NVARCHAR(8));
PRINT @ErrorVar;
END
ELSE
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