Skip to content

Instantly share code, notes, and snippets.

@gbdavid2
Last active February 19, 2017 20:28
Show Gist options
  • Save gbdavid2/26a495d6a63e1a03fbf3 to your computer and use it in GitHub Desktop.
Save gbdavid2/26a495d6a63e1a03fbf3 to your computer and use it in GitHub Desktop.
AdventureWorks: Retrieve data about latest orders by customer name, date and sales person (ordered by date)
SELECT TOP 10 P.FirstName +' '+P.LastName As ClientName, SOH.OrderDate, SOH.SalesPersonID
FROM Sales.SalesOrderHeader SOH
JOIN Sales.Customer C ON SOH.CustomerID = C.CustomerID
JOIN Person.Person P ON P.BusinessEntityID = C.PersonID
WHERE SalesPersonID IS NOT NULL
ORDER BY SOH.OrderDate DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment