--NAMING STRORED PROCEDURE OBJECT-----------------------------------------------------------------------------------
--So some of these may be:
/* uspInsertPerson - insert a new person record
uspGetAccountBalance - get the balance of an account
uspGetOrderHistory - return list of orders*/
--------------------------------------------------------------------------------------------------------------------
--STORED PROCEDURE USING TRY & CATCH BLOCK--------------------------------------------------------------------------
CREATE PROCEDURE ProcDemo_TryCatch
AS BEGIN TRY
SELECT * from contact
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() AS ErrorState, ERROR_PROCEDURE() AS ErrorProcedure, ERROR_LINE() AS ErrorLine, ERROR_MESSAGE() AS ErrorMessage;
END CATCH
exec ProcDemo_TryCatch
--------------------------------------------------------------------------------------------------------------------
--FOR CALCULATING AVERAGE
create proc ProcedureAverage as select AVG(id) as Average from contact
exec ProcedureAverage
--------------------------------------------------------------------------------------------------------------------
--So some of these may be:
/* uspInsertPerson - insert a new person record
uspGetAccountBalance - get the balance of an account
uspGetOrderHistory - return list of orders*/
--------------------------------------------------------------------------------------------------------------------
--STORED PROCEDURE USING TRY & CATCH BLOCK--------------------------------------------------------------------------
CREATE PROCEDURE ProcDemo_TryCatch
AS BEGIN TRY
SELECT * from contact
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() AS ErrorState, ERROR_PROCEDURE() AS ErrorProcedure, ERROR_LINE() AS ErrorLine, ERROR_MESSAGE() AS ErrorMessage;
END CATCH
exec ProcDemo_TryCatch
--------------------------------------------------------------------------------------------------------------------
--FOR CALCULATING AVERAGE
create proc ProcedureAverage as select AVG(id) as Average from contact
exec ProcedureAverage
--------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment
Thanks for comments.