我有一个要创建的视图,它有 2 个 CTES。这就是我在下面所做的。第一部分很好,但是在“AND”之后事情就不起作用了。感谢您的意见
CREATE VIEW dbo.VW.SPAg
AS With today as
(SELECT * FROM dbo.Work_Days
WHERE [Date] = CAST(GETDATE() AS DATE)
)
AND WITH rd as
(SELECT [DATE] AS REP_DATE
FROM dbo.Link_Days
WHERE DAY ([DATE]) = 1
)
SELECT wm *,
gr.DATE_ORDINAL AS Goods_Rcvd_Ordinal
gt.DATE_ORDINAL AS Goods_Trnpt_Ordinal
today.DATE
FROM dbo.SPAg sg
INNER JOIN rd
ON YEAR(sg.Client_Query)= YEAR(rd.REP_DATE)
LEFT JOIN dbo.Work_DAYS gr
ON sg.Goods_Rcvd = gr.[DATE]
LEFT JOIN dbo.Work_DAYS gt
ON sg.Goods_Trnpt = gt.[DATE]