Charles, I tend to doubt this will help - so consider this a "Hail Mary" attempt....but it's the only thing I can think of.
In SQL Server, this doesn't work...
declare @RowsToGet int
set @RowsToGet = 10
select top @RowsToGet * from SomeTable
However, this does (requires parenthesis around the parameter variable for SQL to evaluate it)
declare @RowsToGet int
set @RowsToGet = 10
select top (@RowsToGet) * from SomeTable