在SQL中,是否可以在WITH中放置WITH?是否有可能在SQL中使用WITH WITH WITH
采取下面的查询例如,
WITH Temp ([Description], [Amount], [OverdueBy])
AS
(select Description, SUM(Amount) as Amount, (DATEDIFF(day,DueDate,GETDATE())) as OverdueBy from brvAPAllInvoices
Where PaidDate is null and APCo = 1 and Amount > 0
Group By Description, DueDate, APRef
)
select * from Temp
我想创建基于关闭上述查询一个“虚拟”的临时表。是否有可能使用另一个WITH来包含它?
沿东西这行:
WITH Temp2 ([Description], [Amount], [OverdueBy])
AS
(
WITH Temp ([Description], [Amount], [OverdueBy])
AS
(select Description, SUM(Amount) as Amount, (DATEDIFF(day,DueDate,GETDATE())) as OverdueBy from brvAPAllInvoices
Where PaidDate is null and APCo = 1 and Amount > 0
Group By Description, DueDate, APRef
)
select * from Temp)
select * from Temp2
当你尝试了什么事? –
Msg 156,Level 15,State 1,Line 4 关键字'WITH'附近的语法不正确。 Msg 319,Level 15,State 1,Line 4 关键字'with'附近的语法不正确。如果此语句是公用表表达式,xmlnamespaces子句或变更跟踪上下文子句,则前面的语句必须以分号结尾。 Msg 102,Level 15,State 1,Line 12 ')'附近语法不正确。 – pgunston
确保使用* actual * RDBMS标记。 – user2864740