just getting my feet wet with sql server express. I have what would be a fairly complicated couple of subqueries, and I simplified it/ them with a cte. I get the error “Incorrect syntax near ‘DatesNotNeeded.’ Any takers? Thanks in advance…
WITH Symb AS
(
SELECT Symbol
FROM tblSymbolsMain
),
DatesNotNeeded AS
(
SELECT Date
FROM tblDailyPricingAndVol
WHERE (tblDailyPricingAndVol.Symbol = Symb.Symbol)
),
WideDateRange AS
(
SELECT TradingDate
FROM tblTradingDays
WHERE (TradingDate >= dbo.NextAvailableDataDownloadDateTime()) AND (TradingDate <= dbo.LatestAvailableDataDownloadDateTime())
),
DatesNeeded AS
(
SELECT TradingDate
FROM WideDateRange
WHERE NOT EXISTS (DatesNotNeeded)
),
SELECT Symb.Symbol, DatesNeeded.TradingDate
FROM Symb CROSS JOIN DatesNeeded
Your query for
DatesNeededis flawed.It should be something more like: