title: Distinct by order date and products SQL Server 2008
body: <p>This is my first post here so if I've been mistaken for my post and English I say sorry :)</p>
  
  <p>I already do research in google and unfortunately until now I can't solve this.</p>
  
  <p>This my problem, show the total orders by date on each product and I want to distinct by products</p>
  
  <p>Here's my query sample</p>
  
  <pre><code>SELECT Orders.OrderDate
            ,SUM(OrderDetails.OrderDetailQuantity) AS totalOrdered
            ,Products.ProductId 
  FROM Orders 
  INNER JOIN OrderDetails ON Orders.OrderId = OrderDetails.OrderId 
  INNER JOIN Products ON OrderDetails.ProductId = Products.ProductId 
  GROUP BY Orders.OrderId
            ,Orders.OrderDate
            ,Products.ProductId 
  HAVING (CONVERT(VARCHAR,  Orders.OrderDate, 23) BETWEEN @from AND @to)
  </code></pre>
  
  <p>Now, I want to distinct by product according to the between OrderDate, I know the big problem here is the DATE but I don't have any idea on how to distinct the date by this query.</p>
  
  <p>Please help me. Thank you.</p>
  
  <p>P.S.: if do you want to solve this in linq expression it would be highly accepted :)</p>