Question

The following question uses Microsoft SQL Server. Create a simple stored procedure that does not expect...

The following question uses Microsoft SQL Server.

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.
  6. The result should yield 8845 records.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  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.

T-SQL   FYI

Select p.Name as ProductName,po.PurchaseOrderID, po.PurchaseOrderDetailID, ph.OrderDate,ph.TotalDue, po.RejectedQty
FROM Production.Product p INNER JOIN Purchasing.PurchaseOrderDetail po
       ON p.ProductID = po.ProductID
       INNER JOIN Purchasing.PurchaseOrderHeader ph on ph.PurchaseOrderID = po.PurchaseOrderID

---------------------------------------------------STORED PROCEDURE-----------------------------------------------------

USE [AdventureWorks2012]
GO

/****** Object: StoredProcedure [dbo].[PurchaseOrderInfo] Script Date: 27/02/2020 12:37:29 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:       Anonymous
-- Create date: 27 Feb 2020
-- Description:   This stored procedure return a result set consisting of ProductName, PurchaseOrderID, PurchaseOrderDetailID, OrderDate, TotalDue and ReceivedQty.
-- =============================================
CREATE PROCEDURE [dbo].[PurchaseOrderInfo]
   -- Add the parameters for the stored procedure here, if any
AS
BEGIN
   -- SET NOCOUNT ON added to prevent extra result sets from
   -- interfering with SELECT statements.
   SET NOCOUNT ON;

-- Insert statements for procedure here
   Select p.Name as ProductName,po.PurchaseOrderID, po.PurchaseOrderDetailID, ph.OrderDate,ph.TotalDue, po.RejectedQty
FROM Production.Product p INNER JOIN Purchasing.PurchaseOrderDetail po
       ON p.ProductID = po.ProductID
       INNER JOIN Purchasing.PurchaseOrderHeader ph on ph.PurchaseOrderID = po.PurchaseOrderID
END

GO

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.

1. SIMPLE EXECUTE ---> EXECUTE PurchaseOrderInfo

2. Using EXECUTE command by adding a WITH RESULT SETS statement.

EXEC PurchaseOrderInfo
WITH RESULT SETS
(   
([ProductName] nvarchar(100) NOT NULL,
[PurchaseOrderID] int NOT NULL,
[PurchaseOrderDetailID] int NOT NULL,
[OrderDate] date not null,
[TotalDue] numeric not null,
[RejectedQty] int not null )
);
  

  1. Show the CREATE PROC, both the EXECUTE statements and the two sets of result sets.
  2. The result should yield 8845 records.

Add a comment
Know the answer?
Add Answer to:
The following question uses Microsoft SQL Server. Create a simple stored procedure that does not expect...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the database and tables for the database. Show all SQL statements. Include primary and foreign...

    Create the database and tables for the database. Show all SQL statements. Include primary and foreign keys. Insert data into each table. Show select statements and display the output of each table. Note:Student’s name must be inserted into table as part of the data! Perform the SQL below: Query one table and use WHERE to filter the results. The SELECT clause should have a column list, not an asterisk (*). State the purpose of the query; show the query and...

  • using sql answer the following i need to double check my answers Question 1 Controls the...

    using sql answer the following i need to double check my answers Question 1 Controls the flow of execution based on a condition begin...end try...catch goto if...else 10 points Question 2 Changes the database context to the specified database. set alter exec use 10 points Question 3 Exits the innermost WHILE loop. goto quit return break 10 points Question 4 Controls the flow of execution when an error occurs declare on error goto try...catch continue...error 10 points Question 5 Declares...

  • PL/SQL Auction Program 1. Create a user xyz, who is the owner of the auction. Create...

    PL/SQL Auction Program 1. Create a user xyz, who is the owner of the auction. Create the schema, and package. 2. Create users x1 and x2 who are the participants in the auction. They will need acces to the package. 3. Bid on the same item and record your observations. Verify all scenarios. Upload the files with the missing code and a detailed sample run. AUCTION OWNER.TXT SQL> conn / as sysdba Connected. SQL> drop user xyz cascade; User dropped....

  • QUESTION 9 You plan to query data using the TRANS_HIST_V view that was created by another...

    QUESTION 9 You plan to query data using the TRANS_HIST_V view that was created by another user in their schema. Which statement is true? A. The Oracle Server will retrieve the view definition from the ALL_VIEWS data dictionary view. B. The Oracle Server will retrieve data, determined by the query criteria, from the TRANS_HIST_V view. C. The Oracle Server will verify whether you have been granted access privileges to the TRANS_HIST_V view. D. The Oracle Server will automatically reset the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT