In SQL Server I can use the with
statement to simplify queries like this:
with x as
(
select 1 as a
)
select *
from x
But what if the query I want to work with is actually a stored procedure?
with x as
(
exec p_queryComplexSP 12345, 0, null,'D+0','D+1095','Hour','GMT', 1
)
select *
from x
Fails: SQL Error [156] [S0001]: Incorrect syntax near the keyword 'exec'.
Is there a correct way to express this query?