I want to summarise the sum of sales.quantity by week, and to show the week number even if there are no sales.
I have setup a weeks table with 1-54 in there to use an ou
The where clause WHERE (sales.transDate BETWEEN @fromDate AND @toDate)
will remove any weeks without sales. You'll likely need to do a subquery to pull the transactions and then join that to your weeks table.
SELECT Weeks.WeekNum, SUM(sales.quantity) AS sales
FROM Weeks LEFT OUTER JOIN
(
SELECT *
FROM sales
WHERE (sales.transDate BETWEEN @fromDate AND @toDate)
) sales
ON Weeks.WeekNum = DATEPART(week, sales.transDate)
GROUP BY Weeks.WeekNum