Among other answers I have looked at the following:
The multi-part identifier could not be bound
However tying to use that answer I was still not able to make my grouping work.
The following query works:
string query = @"SELECT
ud.FirstName,
ud.LastName,
p.Name AS Product,
p.ItemNumber,
sc.AmountPurchased * sc.Price AS Total,
sc.DatePurchased,
sc.IsInCart AS [NotShipped]
FROM
ShoppingCarts sc INNER JOIN
UserDetails ud ON sc.ClientID = ud.Guid Left
OUTER JOIN
Products p ON sc.ProductID = p.ProductsId
WHERE sc.DatePurchased >= @date1
AND sc.DatePurchased <= @date2
AND sc.IsInCart = @shipped ";
but when I try to group it like this:
string query = @"SELECT ud.LastName, sc.DatePurchased, SUM(Total)
FROM(
SELECT
ud.FirstName,
ud.LastName,
p.Name AS Product,
p.ItemNumber,
sc.AmountPurchased * sc.Price AS Total,
sc.DatePurchased,
sc.IsInCart AS [NotShipped]
FROM
ShoppingCarts sc INNER JOIN
UserDetails ud ON sc.ClientID = ud.Guid Left
OUTER JOIN
Products p ON sc.ProductID = p.ProductsId
WHERE sc.DatePurchased >= @date1
AND sc.DatePurchased <= @date2
AND sc.IsInCart = @shipped
) AS result
GROUP BY ud.LastName, sc.DatePurchased";
I get the "multi-part identifier ud.LastName, etc cannot be bound"