Reputation: 23
I try to create cte but I feel like I've always having trouble while executing it. I double checked my code and everything looks right to me. While I was running the script inside the cte alone, it works fine. But when I put it in a cte, it says "incorrect syntax near ')'"
Does anyone know why this keeps happening? All my () should work fine. Please help!
Script:
WITH cte AS
(
select a.custid,count(a.orderid),rank() over (order by count(a.orderid) desc) as 'num'
from sales.orders a
group by a.custid
)
select * from cte
Upvotes: 0
Views: 64
Reputation: 1387
Have you tried adding ";" semicolon in front of WITH?
;WITH cte AS
(
select a.custid,count(a.orderid) AS OrderCount,rank() over (order by count(a.orderid) desc) as 'num'
from sales.orders a
group by a.custid
)
select * from cte
Upvotes: 4