I would like to ask if there is a way to include the total number of rows, as an additional column, in the returned result sets from a TSQL query using also the Row_Nu
Row_Nu
SELECT n , COUNT(*) OVER ( PARTITION BY 1 ) FROM ( SELECT 1 AS n UNION ALL SELECT 2 AS n ) AS t
Note that @@ROWCOUNT gives you row count from the previous command. Run this:
SELECT 1 AS n; SELECT n , @@ROWCOUNT FROM ( SELECT 1 AS n UNION ALL SELECT 2 AS n ) AS t