0

This does not compile in SQL server 2012:

with q as (
select row_number() over (order by ActionName) as rn, *
from [xxx].[dbo].[Action] a
)

It says 'Incorrect syntax near the keyword 'as'.

Should this compile and if not how to fix this?

3 Answers 3

1

start your statement with ; try this

;with q 
as (
select row_number() over (order by ActionName) as rn, *
from [xxx].[dbo].[Action] a
)
SELECT * FROM q

and CTE should be followed by a SELECT statement.

Sign up to request clarification or add additional context in comments.

Comments

0
;with q as (
select row_number() over (order by a.ActionName) as rn, a.*
from [xxx].[dbo].[Action] a
)

2 Comments

i think ; at beginning is not necessary ? i use sql-server no error if no ;
not necessary, if it is the first statement of the batch. Apparently that was not the case, as OP says Muhammed Ali's answer helped.
0
with q as (
select *, row_number() over (order by ActionName) as rn
from [xxx].[dbo].[Action] a
)

1 Comment

select is obvious after this !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.