I need to group some records based on a date but it is a date and time field and I need to ignore the time part of is and just group by the date part – here is my SQL as it stands:
SELECT AutoShipItems.CustomerID,AutoShipItems.NextOrderDate, Customer.FirstName,Customer.LastName, Customer.EmailAddress FROM AutoShipItems INNER JOIN Customer ON AutoShipItems.CustomerID =Customer.CustomerID WHERE (AutoShipItems.NextOrderDate <= GETDATE()) GROUP BY AutoShipItems.CustomerID, AutoShipItems.NextOrderDate, Customer.FirstName, Customer.LastName, Customer.EmailAddress ORDER BY AutoShipItems.NextOrderDate
You can group by this:
I put this into a scalar user-defined function to make it easier:
Which you would then call like this:
Note that you might have to change the values in the SELECT clause, since you are grouping by something different now.