I recently had a client, who was creating a SQL Server Reporting Services Employee Sales report, that listed the sales agents who had not made any sales, within a given time period.
Solution:
Within SQL there is a EXCEPT clause, which allows one to compare data between 2 datasets.
The EXCEPT clause will return any distinct value from the first dataset that does not exist in the second dataset.
To find the Employees who have made any orders, in a specific date range:
Declare @Startdate as Datetime Declare @Enddate as datetime
Set @Startdate = CONVERT(DATETIME, '2005-01-01 23:59:59', 102) Set @Enddate = CONVERT(DATETIME, '2005-01-02 23:59:59', 102)
SELECT [Employee ID] FROM Employee
EXCEPT
SELECT [Employee ID] FROM Orders WHERE ([Order Date] BETWEEN @Startdate AND @Enddate)
If you have any questions, leave us a comment below, or need any assistance, please do not hesitate to Contact Us |