我想为漏斗查询创建一个表,该查询具有days变量的声明。如果我使用不带create语句的查询,则查询运行正常。当我尝试添加select * into ..from
时,我收到两个错误:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'declare'.
Msg 102, Level 15, State 1, Line 19
Incorrect syntax near ')'.
如何将带有days声明的查询保存到新表中
select * into tbl60D_AlertsFunnel from (
declare @d date = getdate() - 60
select sum(IP) AS IP ,sum(sentCount) sentCount, sum(readCount) readCount, sum(NumberOfOpensPerEmail) OpenNumber
from (
select COUNT(distinct CAST(sm.IP AS nvarchar(20))) as IP
, count(distinct v.iditem) sentCount
, MAX(cast(sm.OpenDate as date)) as OpenDateShort -- v.iditem is for sent, sm.OpenDate IS FOR OPEN
,count(cast(sm.OpenDate as date)) as NumberOfOpensPerEmail
, count(distinct sm.iditem) readCount
from fff.dbo.v_rep_MessageQueue v (nolock)
left join [FF].[dbo].[tblMessageOpenedSMTP] sm
on v.IdItem = sm.iditem
-- and cast(sm.OpenDate as date) > @d
where v.IdMessageType = 20
and V.DateScheduled > @d
group by sm.IP
) d
) j