我有一个要从中创建临时表的MS SQL CTE查询。我不确定该怎么办,因为它会导致Invalid Object name
错误。
下面是整个查询供参考
SELECT * INTO TEMPBLOCKEDDATES FROM
;with Calendar as (
select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime,EventEndTime, EventRecurring, EventStartDate as PlannedDate
,EventType from EventCalender
where EventActive = 1 AND LanguageID =1 AND EventBlockDate = 1
union all
select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime,EventEndTime, EventRecurring, dateadd(dd, 1, PlannedDate)
,EventType from Calendar
where EventRecurring = 1
and dateadd(dd, 1, PlannedDate) <= EventEndDate
)
select EventID, EventStartDate, EventEndDate, PlannedDate as [EventDates], Cast(PlannedDate As datetime) AS DT, Cast(EventStartTime As time) AS ST,Cast(EventEndTime As time) AS ET, EventTitle
,EventType from Calendar
where (PlannedDate >= GETDATE()) AND ',' + EventEnumDays + ',' like '%,' + cast(datepart(dw, PlannedDate) as char(1)) + ',%'
or EventEnumDays is null
order by EventID, PlannedDate
option (maxrecursion 0)
我希望方向正确,或者可以从此CTE查询中创建临时表,
这里是如何做到这一点stackoverflow.com/questions/3306096/...
—
Luxspes
@RGI,这两个答案都适合我的情况,我给他马丁投票,因为我只能选择一个答案。感谢您的回答。我还给了您比他更优先的答案,因为您也提到了临时查询的删除部分。为您还投票。–
—
学习