0

Possible Duplicate:
Dynamic SELECT TOP @var In SQL Server

why am I getting a syntax error at select top @recNo here?

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
Community
  • 1
  • 1
runat
  • 1

1 Answers1

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

Parametrised TOP needs to be in parenthesis

gbn
  • 422,506
  • 82
  • 585
  • 676