RE: SELECT TOP X by using dynamic SQL
I've heard the next release of SQL Server will support dynamic TOP(n) like you've written, but until then, some dynamic SQL should do the job:DECLARE @top varchar(10) DECLARE @sql varchar(100)SET @TOP = 2 SET @sql = 'SELECT TOP ' + @top + ' Field FROM MyTable'PRINT @sql EXEC(@sql)
2005-02-14