【问题标题】:Syntax error in SPs [duplicate]SP 中的语法错误 [重复]
【发布时间】:2011-05-16 18:23:45
【问题描述】:

可能重复:
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

【问题讨论】:

    标签: sql stored-procedures parameters


    【解决方案1】:
    ...select top (@recNo) accDesc...
    

    参数化TOP 需要在括号中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 2015-12-17
      • 2015-02-02
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-07-12
      相关资源
      最近更新 更多