Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a CREATE VIEW statement that defines a view named InvoiceBasic that ret

ID: 3577870 • Letter: 1

Question

1. Write a CREATE VIEW statement that defines a view named InvoiceBasic that returns three columns: VendorName, InvoiceNumber, and InvoiceTotal. Then, write a SELECT statement that returns all of the columns in the view, sorted by VendorName, where the first letter of the vendor name is N, O, or P.

2.Create a view named Top10PaidInvoices that returns three columns for each vendor: VendorName, LastInvoice (the most recent invoice date), and SumOfInvoices (the sum of the InvoiceTotal column). Return only the 10 vendors with the largest SumOfInvoices and include only paid invoices.

3.Create an updatable view named VendorAddress that returns the VendorID, both address columns, and the city, state, and zip code columns for each vendor. Then, write a SELECT query to examine the result set where VendorID=4. Next, write an UPDATE statement that changes the address so that the suite number (Ste 260) is stored in VendorAddress2 rather than in VendorAddress1.(Make sure to rerun your SELECT query in order to verify the change)

4.Create a view named AccountByVendor that returns the sum of InvoiceLineItemAmounts in the InvoiceLineItems table, grouped by VendorName and AccountDescription.

5.Modify the InvoiceBasic view created in exercise 1 to sort the result set by VendorName.

Explanation / Answer

Answers

1.CREATE VIEW InvoiceBasic

--RETURN VendorName, InvoiceNumber, InvoiceTotal,

SELECT VendorName, InvoiceNumber, InvoiceTotal

FROM Invoices JOIN Vendors ON Invoices.InvoiceID = Vendors.VendorID
WHERE left(VendorName,1) IN ('N' , 'O ' , 'P' )

2.CREATE VIEW Top10PaidInvoices WITH

SCHEMABINDING '

AS

SELECT TOP 10 VendorName AS Name, MAX(InvoiceDate) AS LastInvoice, SUM(InvoiceTotal) AS SumOfInvoices

FROM dbo.Vendors V JOIN dbo.Invoices I

ON V.VendorID = I.VendorID

WHERE PaymentDate IS NOT NULL

GROUP BY VendorName

ORDER BY SumOFInvoices desc;

3.CREATE VIEW VendorAddress

AS

SELECT VendorID, VendorAddress1, VendorAddress2, VendorState, VendorZip, VendorCity

FROM VendorTable

GO

--select query to examine results

SELECT * FROM VendorAddress WHERE VendorID = 4

--write an UPDATE statement that changes the address so that the suite number (Ste 260) is stored in VendorAddress2 rather than in VendorAddress1

UPDATE VendorAddress

SET VendorAddress2 = 'Ste 260',

VendorAddress1 = REPLACE(VendorAddress1,'Ste 260','')

WHERE VendorAddress1 LIKE '% Ste 260 %'

for second part

SELECT * FROM sys.foreign_keys

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote