views:

435

answers:

1

I want to limit the number of records returned by calling ROW_NUMBER(), but I am curious as to if you can call it in dynamic sql?

Also, Can you use CTE's in dynamic sql?

+2  A: 

Do you mean, as opposed to being called from inside a stored procedure or other code object? If that's the question, the answer is yes. Note for the record that row_number is only supported on SQL 2005 and later.

Barry Fandango
Inside a stored procedure.
Xaisoft