WITH cte as (
SELECT date, orders
FROM dbo.Orders
),
cte2 as (
select top (SELECT MAX(date) FROM cte) ROW_NUMBER() over(order by a.name)
as date
from sys.all_objects a
)
SELECT cte2.date, SUM(ISNULL(orders, 0))
FROM cte2 LEFT JOIN cte ON cte2.date = cte.date
GROUP BY cte2.date
2
Answers
Use a left against generate_series():