Question: 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)

  1. Create a simple stored procedure that does not expect any parameters and contains a single T-SQL statement.
    1. Create the stored procedure as PurchaseOrderInfo
    2. This stored Procedure should return a result set consisting of ProductName, PurchaseOrderID, PurchaseOrderDetailID, OrderDate, TotalDue and ReceivedQty.
    3. Refer to the schema AdventureWorks2012.Production and AdventureWorks2012.Purchasing to access the necessary tables needed to generate the following output.
    4. EXECUTE the stored procedure in 2 ways.
      1. Using the simple EXECUTE keyword, and
      2. Using EXECUTE command by adding a WITH RESULT SETS statement.
    5. Show the CREATE PROC, both the EXECUTE statements and the two sets of result sets in the screenshot.
    6. The result should yield 8845 records as shown below in both screenshots.
  2. ALTER the above stored procedure using input and default parameters.
    1. Write the ALTER procedure for PurchaseOrderInfo
    2. Add two parameters: ALTER PROCEDURE [dbo].[PurchaseOrderInfo]

@EmployeeID int, -- input parameter

@OrderYear int = 2005 -- default parameter

  1. 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

  1. This altered stored procedure should execute successfully.
  2. Now, EXECUTE the stored procedure by passing 258 for the input parameter and 2006 for default parameter.
  3. Show the ALTER PROC, EXEC statement with the two passing parameters and the result screenshot.
  4. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!