DoriTheFish
DoriTheFish

Reputation: 23

cte always produces issues

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

Answers (1)

NonProgrammer
NonProgrammer

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

Related Questions