Hello All,
I've been tasked with migrating an internally developed ASP.NET tool from Access to SQL Server. This sort of activity isn't my day job, but I'm 99% there thanks to a few books and research here. I have one query left to convert, and I cannot begin to wrap my brain around it.
The output displays a list of employees currently taking leads (who are not "inactive"). For the column headers, the date is shown for the previous seven days (if a lead was submitted on that day), and two totals are displayed under each date. One for the total number of New Orders received, and another for total number of Change Orders. It seems that there should be a better way to present this rather than a /, such as a split column under each date heading, however, I'd be overjoyed just to be able to reproduce what was done in Access.
Access Query that I need to convert to T-SQL:
TRANSFORM Sum([T_Leads]![OrderType]='New Order')-1 & " / " & Sum([T_Leads]![OrderType]='Change Order')-1 AS [New / Change]
SELECT Employees.EmployeeName as Name, Count(T_Leads.OrderType) AS Total
FROM Employees INNER JOIN T_Leads ON Employees.EmployeeID = T_Leads.EmployeeID
WHERE (((T_Leads.Date)>Date()-7))
and [Employees.LeadRotation] <> "Inactive"
GROUP BY Employees.EmployeeName
ORDER BY T_Leads.Date
PIVOT T_Leads.Date;
Produces this output:
+-------------+-------+----------+----------+----------+----------+-----------+
| Name | Total | 4/5/2016 | 4/6/2016 | 4/7/2016 | 4/8/2016 | 4/11/2016 |
+-------------+-------+----------+----------+----------+----------+-----------+
| Doe, Jane | 9 | 0/1 | 0/2 | 0/3 | / | 0/3 |
+-------------+-------+----------+----------+----------+----------+-----------+
| Guy, Some | 4 | 0/1 | 0/1 | / | / | 0/2 |
+-------------+-------+----------+----------+----------+----------+-----------+
| Doe, John | 10 | 0/1 | 1/1 | 2/1 | 0/3 | 0/1 |
+-------------+-------+----------+----------+----------+----------+-----------+
| Boop, Betty | 1 | 0/1 | / | / | / | / |
+-------------+-------+----------+----------+----------+----------+-----------+
| Smith, Jeff | 7 | 1/1 | 0/1 | 0/1 | / | 0/3 |
+-------------+-------+----------+----------+----------+----------+-----------+
Many thanks!