-
Notifications
You must be signed in to change notification settings - Fork 18
/
23_StoredProcedures_Homework.sql
90 lines (40 loc) · 1.79 KB
/
23_StoredProcedures_Homework.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/******************************************************************************
Course videos: https://www.red-gate.com/hub/university/courses/t-sql/tsql-for-beginners
Course scripts: https://litknd.github.io/TSQLBeginners
Stored Procedures
Homework
*****************************************************************************/
/* ✋🏻 Doorstop ✋🏻 */
RAISERROR ( N'Did you mean to run the whole thing?', 20, 1 ) WITH LOG ;
GO
USE WideWorldImporters;
GO
/* Q1
Create a procedure named dbo.MostRecentInvoiceIDForCustomerID with two parameters:
@CustomerID INT,
@InvoiceID INT OUTPUT
The query should return the most recent InvoiceID for that CustomerID based on the
InvoiceDate column
Write code to execute the procedure and return the most recent InvoiceID for @CustomerID = 1
The result should be InvoiceID 70232
*/
/* Q2
This question builds on the prior question
Create a procedure named dbo.MostRecentInvoiceLinesForCustomerID with one parameter:
@CustomerID INT
This procedure should call the dbo.MostRecentInvoiceIDForCustomerID procedure to get
the most recent InvoiceID
It should then query the Sales.InvoiceLines table and return a dataset containing the
following columns:
InvoiceID,
InvoiceLineID,
Description,
Quantity,
UnitPrice
Write code to execute dbo.MostRecentInvoiceIDForCustomerID and return the most recent dataset for CustomerID = 1
The result set should look like this:
InvoiceID InvoiceLineID Description Quantity UnitPrice
--------- ------------- ---------------------------------- -------- ---------
70232 227357 Tape dispenser (Black) 50 32.00
70232 227358 10 mm Double sided bubble wrap 20m 20 30.00
*/