-- 帶參輸出的存儲過程 --測試方法:--declare @return int--exec 測試用勿刪 1, @return out--print @return-- Create PROCEDURE [dbo].[測試用勿刪]@userid int, @return int outASbegi ...
-- =============================================
--帶參輸出的存儲過程
--測試方法:
--declare @return int
--exec 測試用勿刪 1, @return out
--print @return
-- =============================================
Create PROCEDURE [dbo].[測試用勿刪]
@userid int,
@return int out
AS
begin try
BEGIN TRAN
print 1/1
COMMIT TRAN
print '成功了'
END try
BEGIN catch
ROLLBACK
print '回滾了'
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
end catch
set @return=@userid+20