SP中的语法错误

时间:2011-05-16 18:23:46

标签: sql stored-procedures parameters

  

可能重复:
  Dynamic SELECT TOP @var In SQL Server

为什么我在这里select top @recNo收到语法错误?

create procedure getTopAccounts
(
@recNo int
)
as
begin
    select top 1 accDesc, accNum 
    from
      (select top @recNo accDesc,accNum
      from 
      ACCOUNTS_TABLE
      order by
      accNum desc)
    as a order by accNum
end

1 个答案:

答案 0 :(得分:4)

...select top (@recNo) accDesc...

参数化TOP需要在括号中