I am modifying my query to include pagination and rownum counts in it, but somehow the rownum is causing an error
Ambigous column name
Code:
WITH List AS ( SELECT ROW_NUMBER() OVER (ORDER BY error_type asc) AS rowNum, MAX(id) AS id, COUNT(errorid) AS ecount, MAX(errorid) AS errorid, FORMAT(MAX(datein), 'MMMM d, yyyy h:mm:ss tt PST', 'en-US') AS max_datein, template, line, error_message, UPPER(error_type) AS error_type FROM mytable mt GROUP BY errorid, template, line, error_message, error_type ), ListRecordCount AS ( SELECT * FROM List, ( SELECT MAX(rowNum) AS TotalrecordCount FROM List ) AS TotalrecordCount ) SELECT * FROM ListRecordCount INNER JOIN List mi ON mt.id = mi.id WHERE rowNum BETWEEN 1 and 5000 ORDER BY mi.max_datein Error I am getting is this:
[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]The multi-part identifier "mt.id" could not be bound. (4104)
[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Ambiguous column name 'rowNum'. (209)
[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Ambiguous column name 'rowNum'. (209)
ListRecordCount as mtand specifymt.rowNum. And ` max(errorid)` is useless as you group byerrorid. But why do you join those CTEs?> [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'mt'. (102)