Given:
You can sort result set by indicating index of column.
SELECT * FROM CUSTOMERS ORDERY BY 1
I’m trying to use in the following context, however, I get error message:
Msg 5308, Level 16, State 1, Line 8
Windowed functions do not support integer indices as ORDER BY clause expressions.
EXEC ("
SELECT *,
ROW_NUMBER() OVER ( ORDER BY 1 ) AS 'Seq'
from dynamic_table");
Can you think of a work-around?
If you know the column name this should work:
If the column name is not known: