The original SQL also has try-catch

Source: Internet
Author: User
Tags sql 2008
Today, I checked the project sample code. I also wrote the try-catch code block in the stored procedure. I thought it was fresh. I don't know if it was the new syntax of SQL 2005 (I used to use 2000). The Code is as follows:

Create proc [dbo]. [p_TNoticeAdmin_RowByLastModifyDate]
@ IntNoticeAdminID INT
AS

Set nocount on;

-- ���� Declare
DECLARE @ btResult BIT; -- fig (0: FIG, 1: FIG)

-- Main code: Begin

BEGIN TRY

SELECT ModifyDate FROM TNoticeAdmin
WHERE NoticeAdminID = @ intNoticeAdminID

SET @ btResult = 0;

END TRY
BEGIN CATCH

DECLARE @ strErrContent VARCHAR (50 ),
@ IntErrorNumber INT,
@ IntErrorSeverity INT,
@ IntErrorState INT,
@ StrErrorProcedure NVARCHAR (126 ),
@ IntErrorLine INT,
@ StrErrorMessage NVARCHAR (4000 );

SET @ strErrContent = '������������������������������ ���� ';
SET @ intErrorNumber = ERROR_NUMBER ();
SET @ intErrorSeverity = ERROR_SEVERITY ();
SET @ intErrorState = ERROR_STATE ();
SET @ strErrorProcedure = ERROR_PROCEDURE ();
SET @ intErrorLine = ERROR_LINE ();
SET @ strErrorMessage = ERROR_MESSAGE ();

EXEC p_TDBErrLog_Create @ strErrContent, @ intErrorNumber, @ intErrorSeverity, @ intErrorState,
@ StrErrorProcedure, @ intErrorLine, @ strErrorMessage;

RAISERROR (@ strErrorMessage, @ intErrorSeverity, @ intErrorState, @ strErrorProcedure, @ intErrorLine );

SET @ btResult = 1;
END CATCH

Haha, although SQL 2008 is coming out, it is also a big gain.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.