Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This uses Microsoft SQL Server and Adventure Works2012 Need help with #2 below (#1 is for reference) Create a simple stored procedure that does not
This uses Microsoft SQL Server and Adventure Works2012
Need help with #2 below (#1 is for reference)
- Create a simple stored procedure that does not expect any parameters and contains a single T-SQL statement.
- Create the stored procedure as PurchaseOrderInfo
- This stored Procedure should return a result set consisting of ProductName, PurchaseOrderID, PurchaseOrderDetailID, OrderDate, TotalDue and ReceivedQty.
- Refer to the schema AdventureWorks2012.Production and AdventureWorks2012.Purchasing to access the necessary tables needed to generate the following output.
- EXECUTE the stored procedure in 2 ways.
- Using the simple EXECUTE keyword, and
- Using EXECUTE command by adding a WITH RESULT SETS statement.
- Show the CREATE PROC, both the EXECUTE statements and the two sets of result sets in the screenshot.
- The result should yield 8845 records as shown below in both screenshots.
- ALTER the above stored procedure using input and default parameters.
- Write the ALTER procedure for PurchaseOrderInfo
- Add two parameters: ALTER PROCEDURE [dbo].[PurchaseOrderInfo]
@EmployeeID int, -- input parameter
@OrderYear int = 2005 -- default parameter
- Next add a criteria to your T-SQL statement in your procedure to limit the result based on the values of the two parameters.
poh.EmployeeID = @EmployeeID
AND YEAR(poh.OrderDate) = @OrderYear
- This altered stored procedure should execute successfully.
- Now, EXECUTE the stored procedure by passing 258 for the input parameter and 2006 for default parameter.
- Show the ALTER PROC, EXEC statement with the two passing parameters and the result screenshot.
- The result should yield 45 records as shown below. (Note: You should get records for every order date placed in 2006.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started