I have a query that searches for customers that have visted multiple times per day. If I run this query for 1 specific day it works. What I’d like to do is be able to query a range of dates. For example I want to search 12/1/12 – 1/31/13 and have it check each day for multiple visits, and display the date that customer visited multiple times. Below is my query that is not working:
SELECT Customers.sBarcode, COUNT(Customers.sBarcode) AS [Number of Scans], Tickets.dtCreated
FROM Tickets INNER JOIN
Customers ON Tickets.lCustomerID = Customers.lCustomerID
WHERE (Tickets.dtCreated BETWEEN CONVERT(DATETIME, '2012-12-11 00:00:00', 102) AND CONVERT(DATETIME, '2012-12-12 00:00:00', 102)) AND (Tickets.dblTotal <= 0)
GROUP BY Customers.sBarcode, Tickets.dtCreated
HAVING (COUNT(*) > 1)
Try something like this:
Assuming you have time information your dtCreated field, the cast/floor/cast would drop it, then you can group on your date and expand your date range.