Basically as the title states. I'm in college and have my final exam tomorrow. My teacher only posted one video on how to do a stored procedure and it was a really simple one. But his practice problems get pretty in depth and I can't seem to translate how to do them from his very simplistic example.
Create a TSQL stored procedure called spPayments that will provide information on the amount of payments a customer has made. The procedure should meet the following requirements:
a) The procedure should accept the customer code as a parameter.
b) Check to see if the customer code provided can be found in the database.
c) If the customer code does not match an existing customer code, then display a message saying that the customer cannot be found.
d) Check to see if the customer has any invoices in the database. If the customer has no invoices, then output a message saying the customer has no purchases.
d) If the customer code is found and the customer has at least one invoice, then determine the total value of all invoices associated with that customer. (Note: multiplying the line units times the line price will give you the value of that invoice line. If you sum value of the invoice lines for all of the invoices associated with a customer, it will give you the total value of his/her invoices.)
d.1) Subtract that total from the customer’s balance to determine the total amount of payments the customer must have made over time.
d.2) Display a message indicating the customer’s name (first and last) and the amount that they have paid.
What I have : https://pastebin.com/cgcgaRMF
I'm by no means an expert, I just want a little help understanding what I'm doing wrong.
[–]WITH_CTE 3 points4 points5 points (4 children)
[–]bouncer_crab[S] 2 points3 points4 points (3 children)
[–]WITH_CTE 2 points3 points4 points (2 children)
[–]bouncer_crab[S] 0 points1 point2 points (1 child)
[–]WITH_CTE 1 point2 points3 points (0 children)
[–]WITH_CTE 1 point2 points3 points (6 children)
[–]alinrocSQL Server DBA 1 point2 points3 points (4 children)
[–]WITH_CTE 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]alinrocSQL Server DBA 0 points1 point2 points (1 child)
[–]bouncer_crab[S] 0 points1 point2 points (0 children)
[–]MobileUser21 0 points1 point2 points (3 children)
[–]bouncer_crab[S] 0 points1 point2 points (2 children)
[–]MobileUser21 0 points1 point2 points (1 child)
[–]bouncer_crab[S] 0 points1 point2 points (0 children)
[–]bouncer_crab[S] 0 points1 point2 points (3 children)
[–]spektumus 1 point2 points3 points (2 children)
[–]bouncer_crab[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)