Hi, I just get a problem executing my sql statement, This is the Northwind db.
declare @PageIndex int
declare @PageSize int
declare @PageLowerBound int
declare @PageUpperBound int
declare @sql nvarchar(4000)
select @PageIndex = 3
select @PageSize = 5
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageLowerBound + @PageSize + 1
with cts
as
(
SELECT *
FROM (SELECT ROW_NUMBER() OVER (ORDER BY OrderID) AS ROW,* FROM Orders)
AS Orders WHERE ROW >=@PageLowerBound AND Row<=@PageUpperBound
)
select @sql = @sql + 'select * from cte'
exec (@sql)
(Modified) Just modify a little bit, I use select * from cte, I accidently pasted the wrong code. Sorry. Actually, i am trying to append a where clause in @sql and execute it, but it throws a error message,saying "Incorrect syntax near the keyword 'exec'." What did I do wrong? Thank you