I want to limit the number of records returned by the ROW_NUMBER () call, but I'm curious if it can be called in dynamic sql?
Also, can you use CTEs in dynamic sql?
Do you mean as opposed to calling from a stored procedure or other code object? If the question is, the answer is yes . Note to record that row_number is only supported in SQL 2005 and later.