I have two tables.
An orders table with customer, and date. A date dimension table from a data warehouse.
The orders table does not contain activity for ev
Assuming that datetable includes every date of the year you can do with one simple CTE
WITH OrdersCustomerDateBorders AS
(
SELECT CustomerID, MIN(fulldate) AS FirstOrderDate, MAX(fulldate) AS LastOrderDate
FROM orders
GROUP BY customer
)
select o.customer, d.fulldate, ISNULL(o.amount, 0) AS Amount
from orders o
INNER JOIN OrdersCustomerDateBorders OCDB ON OCDB.CustomerID = o.CustomerID
INNER JOIN datetable d ON ON d.fulldate between OCDB.FirstOrderDate AND OCDB.LastOrderDate
WHERE d.calendaryear in (2012);