SQL Server查询中的语法无效

时间:2013-11-28 10:15:21

标签: sql sql-server

这不能在SQL Server 2012中编译:

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

它表示'关键字附近的语法不正确'为'。

这应该编译,如果不能解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

;尝试此

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

和CTE后面应该跟一个SELECT语句。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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