刚刚用sql server express弄湿了脚。我有一个相当复杂的子查询,我用cte简化它/它们。我收到错误“DatesNotNeeded附近的语法错误。”任何接受者?提前感谢...
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
答案 0 :(得分:1)
您对DatesNeeded
的查询存在缺陷。
SELECT TradingDate
FROM WideDateRange
WHERE NOT EXISTS (DatesNotNeeded)
它应该更像是:
SELECT TradingDate
FROM WideDateRange wdr
WHERE NOT EXISTS (SELECT 1 FROM DatesNotNeeded WHERE Date = wdr.TradingDate)