Prøvedata og ønskede resultater ville hjælpe. Når du siger "adskilt med" går jeg ud fra, at du mener gruppe med. Bemærk, i WHERE-sætningen behøver du ikke at afgive Order.OrderDate, hvis du sikrer, at tidskomponenten for dine @from &@to-parametre er indstillet korrekt (for at inkludere hver hel dag). Det er aldrig en god idé at anvende en kasteoperation til venstre side af en sammenligning.
SELECT --cast(Orders.OrderDate as date),
Products.ProductId
SUM(OrderDetails.OrderDetailQuantity) AS totalOrdered,
FROM Orders
INNER JOIN OrderDetails ON Orders.OrderId = OrderDetails.OrderId
INNER JOIN Products ON OrderDetails.ProductId = Products.ProductId
where Orders.OrderDate between cast(@from as date) AND cast(@to as date)
GROUP
BY --cast(Orders.OrderDate as date),
Products.ProductId
-- to illustrate:
declare @From datetime = '1/1/2000 10:30:22',
@To datetime = '1/3/2000 9:11:31'
declare @orders table (i int, dt datetime)
insert into @orders
values(1, '1/1/2000 8:00'),(2, '1/2/2000 10:00'), (3, '1/4/2000 3:00')
-- only returns i=2
select *
from @orders
where dt between @From and @To
-- returns i=1 & i=2
select *
from @orders
where dt between cast(@From as date) and cast(@To as date)