I am using SQL Server 2008 R2. I need to use a parameter for the last part of T-SQL below.
In this part, the values of parameters to sp_executesql are specified, but I want to supply it dynamically.
EXECUTE sp_executesql @sql,N'@startIndex1 int,@maxRows1 int',
@startIndex1 = @startIndex,@maxRows1 = @maxRows--LAST PART