I need to write an SQL query to only include specific dates, I can't seem to figure out where to put the query to restrict the dates. And I'm not certain that I'm using the right query. I was trying "AND TimeIndex>'199606' or TimeIndex<'199805'"
This is my current query missing the date restriction
SELECT DD.Year, DD.MonthOfYear, CONVERT(Integer, dd.Year) * 100 + CONVERT(Integer,
dd.MonthOfYear) AS TimeIndex, cnames.CategoryName, COALESCE(SUM(Orders.Quantity),0) AS Quantity FROM
(
SELECT DISTINCT Year, MonthOfYear
FROM DimDate
) AS dd
CROSS JOIN
(
SELECT DISTINCT CategoryName
FROM DimProduct
) AS cnames
LEFT JOIN (
SELECT dd.Year, dd.MonthOfYear, dd.DateKey,
dp.ProductKey, dp.CategoryName, fs.Quantity
FROM FactSales fs
JOIN DimProduct dp
ON fs.ProductKey = dp.ProductKey
JOIN DimDate dd
ON fs.OrderDateKey = dd.DateKey
) as orders
ON dd.MonthOfYear = orders.MonthOfYear and cnames.CategoryName = Orders.CategoryName
GROUP BY dd.year, dd.MonthOfYear, cnames.CategoryName