• Getdate function returns the current system date (as Jeff will remind us), rather than the date portion of a date/time field.

    If you want just the date (with no time) from a datetime field, there are a couple of options:

    (1) CONVERT (or CAST) the datetime field to a datetime field

    SELECT CONVERT(DATE, s.LastEditedWhen), s.InvoiceID, s.UnitPrice, SUM(s.StockItemID) AS Product_Total, si.InvoiceID
    FROM Sales.InvoiceLines s
    INNER JOIN Sales.Invoices si
    ON s.InvoiceID = si.InvoiceID
    GROUP BY CONVERT(DATE, s.LastEditedWhen), s.StockItemID, s;

    (2) use datetime differences and additions (link to google for various explanations - pick the one you're most comfortable with) to strip off the time part of the field - this looks odd, but it works well:

    SELECT DATEADD(DAY, DATEDIFF(DAY, '20160101', s.LastEditedWhen), '20160101'), s.InvoiceID, s.UnitPrice, SUM(s.StockItemID) AS Product_Total, si.InvoiceID
    FROM Sales.InvoiceLines s
    INNER JOIN Sales.Invoices si
    ON s.InvoiceID = si.InvoiceID
    GROUP BY DATEADD(DAY, DATEDIFF(DAY, '20160101', s.LastEditedWhen), '20160101'), s.StockItemID, s;

    NB: It looks as though there are potentially some other issues with the code you've provided - the GROUP BY doesn't seem to have fields that match the non-aggregated fields in the SELECT...

    Thomas Rushton
    blog: https://thelonedba.wordpress.com