











































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












































Functions, Stored Procedures, Triggers and Transactions
Solution: Salary Level Function (2) DECLARE @salaryLevel VARCHAR(10) IF (@salary < 30000) SET @salaryLevel = 'Low' ELSE IF(@salary >= 30000 AND @salary <= 50000) SET @salaryLevel = 'Average' ELSE SET @salaryLevel = 'High' RETURN @salaryLevel Variable IF Statement Return Result
Executing Stored Procedures
Dropping Stored Procedures
Using Parameters
Parameterized Stored Procedures – Example CREATE PROC usp_SelectEmployeesBySeniority(@minYearsAtWork int = 5) AS SELECT FirstName, LastName, HireDate, DATEDIFF(Year, HireDate, GETDATE()) as Years FROM Employees WHERE DATEDIFF(Year, HireDate, GETDATE()) > @minYearsAtWork ORDER BY HireDate GO EXEC usp_SelectEmployeesBySeniority 10 EXEC usp_SelectEmployeesBySeniority Procedure Name Procedure Logic Usage