SQL - CTE Within a CTE - Stack Overflow
SQL - CTE Within a CTE - Stack Overflow
with test as (
10 select
SRnum,
gamenumber,
StartOfDistribution,
ApplicationNumber
from #main
where startofdistribution = '2011-06-14 00:00:00.000'
and SRnum = '313'
--order by SRnum, gamenumber, StartOfDistribution, ApplicationNumber
)
select
ApplicationNumber
,count(*) as RetailerAppearance
from test
group by ApplicationNumber
having count(*) = 4
You can't nest CTEs like that in SQL Server but you can
use multiple CTEs the following way:
Home 70
;with test as
PUBLIC (
select
Stack Overflow SRnum,
gamenumber,
Tags StartOfDistribution,
ApplicationNumber
Users from #main
where startofdistribution = '2011-06-14 00:00:00.000'
Jobs and SRnum = '313'
--order by SRnum, gamenumber, StartOfDistribution, App
),
outertest as
Teams (
Q&A for work select
ApplicationNumber
,count(*) as RetailerAppearance
Learn More from test
group by ApplicationNumber
having count(*) = 4
)
select count(*)
from outertest
Seems like you can only run either one of the two cte queries.
JoinAny
Stack
wayOverflow to learn,
of running both? share
– Naufal Janknowledge, and build your career.
30 '18 at 17:53
Join Stack Overflow to learn, share knowledge, and build your career.
https://stackoverflow.com/questions/18728474/cte-within-a-cte 3/3