We help IT Professionals succeed at work.
Get Started

SQL 2008

Last Modified: 2012-05-10
The following script uses a derived table to return the date and invoice total of the
earliest invoice issued by each vendor. Write a script that generates the same result
set but uses a temporary table in place of the derived table. Make sure your script
tests for the existence of any objects it creates.

SELECT VendorName, FirstInvoiceDate, InvoiceTotal
FROM Invoices JOIN
(SELECT VendorID, MIN(InvoiceDate) AS FirstInvoiceDate
FROM Invoices
GROUP BY VendorID) AS FirstInvoice
ON (Invoices.VendorID = FirstInvoice.VendorID AND
Invoices.InvoiceDate = FirstInvoice.FirstInvoiceDate)
JOIN Vendors
ON Invoices.VendorID = Vendors.VendorID
ORDER BY VendorName, FirstInvoiceDate

This where I have gotten:


     DROP Table #VendorTotal
SELECT MIN(InvoiceDate) AS FirstInvoiceDate, InvoiceTotal
INTO #VendorTotal
FROM Invoices
GROUP BY InvoiceTotal

SELECT Vendorname
FROM Vendors JOIN #VendorTotal
   ON Vendors.VendorID = #VendorTotal.VendorID
GROUP BY VendorName

    This is the last question of six questions, and I have been stuck on it for several hours. I seldom ask for help, but this one has me stumped.
Watch Question
Expert of the Quarter 2010
Expert of the Year 2010
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE