【发布时间】:2017-03-12 13:11:03
【问题描述】:
这是我之前问题的延伸: Auto generating dates based on a table
我得到了完美的解决方案
with n as (
select row_number() over (order by (select null)) - 1 as n
from master..spt_values
)
select t.*, dateadd(day, n.n, t.startDate) as thedate
from t join
n
on dateadd(day, n.n, t.startDate) <= t.endDate;
但是,我想通过将结果保存到表格中来使其持久化。是否可以持久化数据?我尝试了 select into 语句,但没有成功
整个语句是:
select into ABC
(
with n as (
select row_number() over (order by (select null)) - 1 as n
from master..spt_values
)
select t.*, dateadd(day, n.n, t.startDate) as thedate
from t join
n
on dateadd(day, n.n, t.startDate) <= t.endDate
)
收到的错误是:
Msg 156, Level 15, State 1, Line 146
Incorrect syntax near the keyword 'into'.
Msg 319, Level 15, State 1, Line 148
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Line 168
Incorrect syntax near ')'.
如何将结果保存到表格中?
【问题讨论】:
-
请发布您的完整查询插入查询不在此问题中
标签: sql sql-server