You are on page 1of 2

Information Management (Lab)

Stored Procedures and UDF

Assignment 7

1. Refer to HOPEDB.SQL and use the following ERD.


2. DO NOT join tables using the WHERE clause (cross join).
3. Use alias name in indicating the name of the column.
4. This assignment should be done in parallel with Quiz Join Related to Assignment.
5. Provide SCREENSHOT of program codes and the output of the CALL (for Stored Procedure)
statement or execution of UDF .
6. Paste your SCRIPTS and SCREENSHOTS into a PDF file. You need to save/convert your MS Word
file into a pdf type.
7. Upload your solution at the provided at NEUVLE link.

SQL SCRIPT 1: Create a stored procedure SHOWSTATE() that has a parameter of two-character state
code ( eg. NY, CA, NJ) that will list all information about the customer who lives in a particular state.
Refer to the CUSTOMER table. The state code can be in lower or uppercase supplied in the parameter.
Use CA to test your stored procedure.

Hint: Use LIKE and UPPER in your stored procedure.


SQL SCRIPT 2: Formulate a stored procedure DISPLAYTRANS() that will display the corresponding sales
transaction based on the transaction number passed. Display transaction number, sales date, product
code, description, unit, quantity. Use TR000039 to test the output of your script.

SQL SCRIPT 3: Create a user-defined function GET_TOTAL_PAYMENT() that will get the total payment
made for each transaction. A transaction number parameter will be included when the function is
called. Use TR000092 to test your function.

SQL SCRIPT 4: Create a stored procedure PAYMENT_SHORT that will display the transaction number,
customer name, total sales, total payment, and the difference between total sales and total payment.
This stored procedure has no parameters.

In this procedure you will use a different set of views that you have created to extract total sales
depending on the correct unit price to be used based on effectivity date and sales date.

Create these views first before using it inside your stored procedure.NO NEED TO DISPLAY THE CONTENT
OF THESE VIEWS.

To display output of the requirement, include GET_TOTAL_PAYMENT user-defined function that you
have created in item 3. TRANSNO should serve as the parameter AND NOT TR000092.

You might also like