B.A. Cooper (7/7/2008)
The following code works, but either of the commented lines produce a syntax error in my environment. When the code from the article is cut and pasted it produces the same error. Is there a configuration setting that allows this to work?DECLARE @N INT
SET @N = 5
select TOP 5 * from table_name
--select TOP @N * FROM table_name
--select TOP (@N) * FROM table_name
For SQL Server 2000, a programmable TOP is NOT available unless you do the dynamic SQL thing... you can, however, use rowcount...
DECLARE @N INT
SET @N = 5
SET ROWCOUNT @N
SELECT * FROM table_name
SET ROWCOUNT 0
--Jeff Moden
Change is inevitable... Change for the better is not.