Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Top clause in SP

Author  Topic 

kling
Starting Member

12 Posts

Posted - 2003-08-14 : 19:26:10
Hi,

I got an "Incorrect syntax" error when I try to use the Top clause with a variable in my Stored Procedure. How should it be done?
Below is my procedure!
--------------------------------------
create procedure testSP (@rows int)
as
select top @rows * from myTable
go
--------------------------------------

Thanks!

-Kevin

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-08-14 : 19:31:38
You cannot use a variable with TOP. You can do this however:

create procedure testSP (@rows int) as
set rowcount @rows
select * from myTable
set rowcount 0
Go to Top of Page
   

- Advertisement -