This was my procedure USE AdventureWorks2019 GO ALTER PROC Sales.p_InsertNewPay @BusinessEntityID INT, @RateCha

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This was my procedure USE AdventureWorks2019 GO ALTER PROC Sales.p_InsertNewPay @BusinessEntityID INT, @RateCha

Post by answerhappygod »

This was my procedure
USE AdventureWorks2019 GOALTER PROC Sales.p_InsertNewPay @BusinessEntityID INT, @RateChangeDate DATETIME, @Rate MONEY, @PayFrequency TINYINT = 2
ASBEGIN SELECT PayFrequency FROMHumanResources.EmployeePayHistory WHERE PayFrequency = CASEWHEN @PayFrequency IS NULL THEN 2 ELSE @PayFrequencyEND IF @RateChangeDate IS NULL BEGIN SET@RateChangeDate = GETDATE () END
IF NOT EXISTS (SELECT * FROMHumanResources.EmployeePayHistory WHERE @BusinessEntityID<> BusinessEntityID) -- CHECK THE OUTPUT HERE IF <> ANDNOT EXISTS ARE REDUNDANT ELSE CHANGE <> TO = BEGIN PRINT'BusinessEntityID Does not exist, please input a validnumber' RETURN END
IF ((@PayFrequency <> 1) OR(@PayFrequency <> 2)) BEGIN PRINT'Invalid number. Can only choose 1 or 2' RETURN --stop procedure from running END ELSE BEGIN INSERT INTOHumanResources.EmployeePayHistory ( BusinessEntityID,RateChangeDate, Rate, PayFrequency ) VALUES (@BusinessEntityID,@RateChangeDate, @Rate, @PayFrequency ) ENDEND
How do i:
Add TRY...CATCH blocks to the procedures you created in Steps 1and 2. The procedure should log error messages to a new ErrorLog(create your own) table and rollback the transaction if an erroroccurs. The table should have fields for the ErrorNumber,ErrorMessage, LineNumber and Procedure.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply