Home /
Expert Answers /
Computer Science /
step-1-we-will-query-the-purchasing-purchaseorderheader-purchasing-purchaseorderdetail-and-produc-pa123
(Solved): Step 1 -We will query the Purchasing.PurchaseOrderHeader, Purchasing.PurchaseOrderDetail and Produc ...
Step 1 -We will query the Purchasing.PurchaseOrderHeader, Purchasing.PurchaseOrderDetail and Production.Product tables from the AdventureWorks database, but instead of getting back all records we will limit it to just a particular EmployeelD and OrderYear. ALTER PROCEDURE SP_PurchaseOrderInformation OEmployeeID int, eorderYear int \\( =2011 \\) AS BEGIN SELECT poh.PurchaseOrderID, pod. PurchaseOrderDetailio, poh.OrderDate, poh. TotalDue, pod. ReceivedQty, p. Name ProductName FROM Purchasing. PurchaseOrderHeader poh IMNER JOIN Purchasing.PurchaseOrderDetail pod ON poh. PurchaseOrderID = pod. PurchaseOrderID INWER JOIN Production. Product p ON pod. ProductID \\( = \\) p. ProductIO WHERE poh. EmployeeID = GEmployeeID AND YEAR (poh.OrderDate) = GOrderYear ENO * In the preceding stored procedure, two parameters were specified: input and default. At the end of the T-SQL query, a WHERE clause was included that limits the result based on the values of the two parameters. Step 2 - To execute this stored procedure, only the input parameter has been specified, which is fine because the other parameter has a default value. To call this stored procedure we can execute it as follows: EXEC sp_PurchaseOrderInformation QEmployeeID = 258; Execute the query and review the results.\r\nStep 3 - In the previous code, the default value for the OrderYear parameter has been overwritten with 2012. To call this stored procedure we can execute it as follows: EXEC sp_PurchaseOrderInformation @employeeID \\( = \\) 258, @OrderYear \\( =2012 \\); Execute the query and review the results. PROCEDURE 6 - How to drop stored procedures. Step 1 - To delete a stored procedure, you can use the DROP PROCEDURE statement